Repository navigation
Expand file tree
/
Copy paththreadtest.py
More file actions
64 lines (54 loc) · 2 KB
/
Copy paththreadtest.py
File metadata and controls
64 lines (54 loc) · 2 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import gi, threading, time
gi.require_version('Gtk','3.0')
from gi.repository import Gtk
from time import strftime, gmtime, sleep
class Worker(threading.Thread):
timerIsRunning = False
quit = False
def run(self):
print "entered worker.run"
time.sleep(1)
while not self.quit:
print self.timerIsRunning
if self.timerIsRunning:
print "timer is running"
max_seconds = 10
count = 0
curr = sec_count = int(strftime("%S", gmtime()))
while self.timerIsRunning:
sec_count = int(strftime("%S", gmtime()))
if sec_count != curr:
count = count + 1
if count > max_seconds:
timerIsRunning = False
break
curr = sec_count
print "."
else:
print "timer should not be running"
print self.timerIsRunning
time.sleep(1)
# def starttimer(self, widget):
# timerIsRunning = True
# def stoptimer(self, widget):
# timerIsRunning = False
class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="thread testing")
self.worker = Worker()
#self.worker.run()
self.worker.start() #explore what this does
def command(arg):
self.worker.timerIsRunning = arg
self.box = Gtk.Box(spacing=6)
self.add(self.box)
self.button1 = Gtk.Button(label="button1")
self.button2 = Gtk.Button(label="button2")
self.box.pack_start(self.button1, True, True, 0)
self.box.pack_start(self.button2, True, True, 0)
self.button1.connect("clicked", lambda _b: command(True))
self.button2.connect("clicked", lambda _b: command(False))
win = Window()
win.connect("delete-event", Gtk.main_quit)
win.show_all() # why tho
Gtk.main()