-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwtimegui2.py
More file actions
executable file
·210 lines (189 loc) · 9 KB
/
wtimegui2.py
File metadata and controls
executable file
·210 lines (189 loc) · 9 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/env python
#
# wtimegui - Working time class with GUI
#
import sys
import time
try:
from Tkinter import *
import ttk
import tkMessageBox
from threading import *
except ModuleNotFoundError:
from tkinter import *
from tkinter import ttk
from threading import *
from tkinter import messagebox as tkMessageBox
from wtime3 import wtime
__author__ = "Riccardo Bruno"
__copyright__ = "2017"
__license__ = "Apache"
__maintainer__ = "Riccardo Bruno"
__email__ = "riccardo.bruno@gmail.com"
class wtimeGUI:
flag_ticket_reached = False
flag_time_reached = False
flag_thread_running = False
interval_thread_waitcycles = 5
check_time_thread=None
wtime_out = {}
winTITLE="wtime GUI"
lblFONT=("Lucida Grande", 12)
lblFGCOLOR='black'
root = None
GUI_data = (
{"type": "text", "name": "t1", "title": "T1", "row": 0, "col": 0},
{"type": "text", "name": "t2", "title": "T2", "row": 1, "col": 0},
{"type": "text", "name": "t2t1", "title": "T2 - T1", "row": 1, "col": 2},
{"type": "text", "name": "t3", "title": "T3", "row": 2, "col": 0},
{"type": "text", "name": "t4", "title": "T4", "row": 3, "col": 0},
{"type": "text", "name": "t4t3", "title": "T4 - T3", "row": 3, "col": 2},
{"type": "text", "name": "pause time", "title": "Pause Time", "row": 4, "col": 0},
{"type": "text", "name": "total time", "title": "Total Time", "row": 5, "col": 0},
{"type": "text", "name": "overtime", "title": "Over Time", "row": 5, "col": 2},
{"type": "text", "name": "time to reach", "title": "Time to reach", "row": 6, "col": 0},
{"type": "text", "name": "time remaining", "title": "Time remain", "row": 7, "col": 0},
{"type": "text", "name": "time remaining at", "title": "at", "row": 8, "col": 0},
{"type": "text", "name": "ticket remaining", "title": "Ticket remain", "row": 9, "col": 0},
{"type": "text", "name": "ticket remaining at", "title": "at", "row": 10, "col": 0},
{"type": "text", "name": "ticket time", "title": "TicketTime", "row": 11, "col": 0},
{"type": "text", "name": "time remaining perc", "title": "%", "row": 7, "col": 2},
{"type": "text", "name": "ticket remaining perc", "title": "%", "row": 9, "col": 2},
{"type": "progress", "name": "t1", "title": "Time progress", "row": 7, "col": 3},
{"type": "progress", "name": "t1", "title": "Ticket progress", "row": 9, "col": 3},
{"type": "button", "name": "t1", "title": "Update", "row": 12, "col": 1},
{"type": "button", "name": "t1", "title": "Exit", "row": 12, "col": 3},
)
def __init__(self):
# wtime3
self.t1, self.t2, self.t3, self.t4 = wtime.getTimes("wtime3")
self.wt = wtime(t1=self.t1, t2=self.t2, t3=self.t3, t4=self.t4)
# GUI
self.root = Tk()
self.root.title(self.winTITLE)
self.gui_build()
self.check_time()
self.root.bind('<Return>',self.btnUpdate)
self.root.bind('<space>',self.btnUpdate)
self.root.bind('<Escape>',self.btnExit)
self.root.lift()
self.root.protocol("WM_DELETE_WINDOW", self.btnExit)
self.root.call('wm', 'attributes', '.', '-topmost', True)
self.root.after_idle(self.root.call, 'wm', 'attributes', '.', '-topmost', False)
#Thread
self.check_time_thread = Thread(target=self.check_time_thread, args=(self,))
self.check_time_thread.start()
# Main loop
self.root.mainloop()
def check_time(self):
self.wtime_out = self.wt.calc2()
self.gui_update()
def btnExit(self, *args):
self.flag_thread_running = False
#Wait for thread completion
self.check_time_thread.join()
self.root.destroy()
sys.exit(0)
def btnUpdate(self, *args):
self.check_time()
self.wt.printout(self.wtime_out)
#print(self.wtime_out)
def show_message_box(self, message):
self.root.attributes("-topmost", True)
tkMessageBox.showinfo("wtimegui", message,parent=self.root)
self.root.attributes("-topmost", False)
def gui_build(self):
for item in self.GUI_data:
if item["type"] == "text":
item["label_var"] = StringVar()
item["value_var"] = StringVar()
item["label_ctl"] = Label(self.root,
textvariable=item["label_var"],
text="None",
font=self.lblFONT,
fg=self.lblFGCOLOR).grid(row=item["row"],
column=item["col"])
item["value_ctl"] = Label(self.root,
textvariable = item["value_var"],
text="None",
font=self.lblFONT,
fg=self.lblFGCOLOR).grid(row=item["row"],
column=item["col"]+1)
elif item["type"] == "progress":
item["progress_ctl"] = ttk.Progressbar(self.root,
orient=HORIZONTAL,
length=64,
mode='determinate')
item["progress_ctl"].grid(row=item["row"],
column=item["col"])
elif item["type"] == "button":
if item["title"] == "Exit":
callback = self.btnExit
elif item["title"] == "Update":
callback = self.btnUpdate
else:
print("WARNING: Unhespected button named: %s" % item["title"])
item["button"] = Button(self.root,
text=item["title"],
command=callback).grid(row=item["row"],
column=item["col"])
else:
print("WARNING: Skipping unknown type: '%s' for item '%s'"
% (item["type"], item["title"]))
def gui_update(self):
for item in self.GUI_data:
if item["type"] == "text":
if item["name"] == "time remaining perc" or item["name"] == "ticket remaining perc":
perc = max(0, self.wtime_out.get(item["name"],""))
item["label_var"].set("%s%%: " % perc)
elif item["name"] == "total time" and self.wtime_out.get("consume pause", None) is not None:
item["label_var"].set("Consuming pause: ")
item["value_var"].set(self.wtime_out["consume pause"])
else:
value = self.wtime_out.get(item["name"],"")
if value != "":
item["label_var"].set(item["title"] + " :")
item["value_var"].set(value)
else:
pass
elif item["type"] == "progress":
item["progress_ctl"]["value"] = self.wtime_out["time remaining perc"]
item["progress_ctl"]["value"] = self.wtime_out["ticket remaining perc"]
elif item["type"] == "button":
pass
else:
print("WARNING: Skipping unknown type: '%s' for item '%s'"
% (item["type"], item["title"]))
def check_time_thread(self, *args):
gui = args[0]
if gui is None:
print("ERROR: No GUI passed")
time.sleep(1)
try:
t = currentThread()
print("wtime updating thread started")
self.flag_thread_running = True
while self.flag_thread_running:
overtime = self.wtime_out.get("overtime", None)
if overtime is not None and self.flag_time_reached == False:
print("You've DONE!!!")
self.flag_time_reached = True
gui.show_message_box("You've DONE!!!")
elif overtime is not None and self.flag_time_reached == True:
self.TotalTimeText = "Overtime: "
self.gui_build()
elif self.wtime_out["ticket remaining"] == "reached" and self.flag_ticket_reached == False:
print("Ticket reached!!!")
self.flag_ticket_reached = True
gui.show_message_box("Ticket reached!!!")
self.check_time()
for i in range(1,10 * self.interval_thread_waitcycles):
if self.flag_thread_running:
time.sleep(.1)
else:
break
except NameError:
print("wtime updating thread not started")
print("wtime updating thread terminated")
if __name__ == "__main__":
gui = wtimeGUI()