Debian Codegraph @

fltk/test/fltk_threads.py

raw symbols SCIP
1 #! /usr/bin/env python
2 #
3 # "$Id: fltk_threads.py 536 2020-10-30 15:20:32Z andreasheld $"
4 #
5 # Thread test script for pyFLTK, the Python bindings
6 # for the Fast Light Tool Kit (FLTK).
7 # Port of the game by Michael Sweet
8 # Copyright 2005-2006 by Michael Sweet.
9 #
10 # FLTK copyright 1998-1999 by Bill Spitzak and others.
11 # pyFLTK copyright 2003 by Andreas Held and others.
12 #
13 # This library is free software you can redistribute it and/or
14 # modify it under the terms of the GNU Library General Public
15 # License, version 2.0 as published by the Free Software Foundation.
16 #
17 # This library is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 # Library General Public License for more details.
21 #
22 # You should have received a copy of the GNU Library General Public
23 # License along with this library if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 # USA.
26 #
27 # Please report all bugs and problems to "[email protected]".
28 #
29
30 from fltk import *
31 import threading, sys, time
32
33 class MyThread(threading.Thread):
34 DoRun = True
35 def __init__(self,string):
36 threading.Thread.__init__(self)
37 self.string = string
38 def run(self):
39 while self.DoRun:
40 time.sleep(0.1)
41 sys.stdout.write(self.string)
42
43 class UserInterface:
44 ThreadList = []
45 id = 1
46 def __init__(self):
47 self.window = Fl_Window(128, 176, 158, 150)
48
49 self.start = Fl_Button(25, 25, 85, 25, "Start")
50 self.start.callback(self.newProcessCB)
51
52 self.click = Fl_Button(25,55,85,28,'Click')
53 self.click.callback(self.clickCB)
54
55 self.window.end()
56 def appRun(self):
57 self.window.show()
58 #Fl.run()
59 while self.window.visible():
60 Fl.check()
61 time.sleep(0.1)
62
63 for t in self.ThreadList:
64 print("Joining ", t)
65 t.DoRun = False
66 t.join()
67
68 #callbacks:
69 def newProcessCB(self,widget):
70 t = MyThread(f'Thread {self.id}\n')
71 self.id += 1
72 t.start()
73 self.ThreadList.append(t)
74
75 def clickCB(self,widget):
76 fl_mt_message('Hi')
77 #fl_alert('Hi')
78
79 app = UserInterface()
80 app.appRun()
81