| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 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 |
|
| 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 |
|
| 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 |
|
| 78 |
|
| 79 |
app = UserInterface() |
| 80 |
app.appRun() |
| 81 |
|