-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwtimegui.py
More file actions
executable file
·258 lines (236 loc) · 7.74 KB
/
wtimegui.py
File metadata and controls
executable file
·258 lines (236 loc) · 7.74 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#!/usr/bin/env python3
#
# 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"
flag_ticket_reached = False
flag_time_reached = False
flag_thread_running = False
interval_thread_waitcycles = 5
check_time_thread=None
wtime_out = None
winTITLE="wtime GUI"
lblFONT=("Lucida Grande", 12)
lblFGCOLOR='black'
root = Tk()
root.title(winTITLE)
T1Content = StringVar()
T2Content = StringVar()
T2T1Content = StringVar()
T3Content = StringVar()
T4Content = StringVar()
T4T3Content = StringVar()
PauseTimeContent = StringVar()
TotalTimeContent = StringVar()
TimeToReachContent = StringVar()
TimeRemainingContent = StringVar()
TimeRemainingAtContent = StringVar()
TicketRemainContent = StringVar()
TicketRemainAtContent = StringVar()
TicketTimeContent = StringVar()
TimePercentage = StringVar()
TicketPercentage = StringVar()
T1Text = StringVar()
T2Text = StringVar()
T2T1Text = StringVar()
T3Text = StringVar()
T4Text = StringVar()
T4T3Text = StringVar()
PauseTimeText = StringVar()
TotalTimeText = StringVar()
TimeToReachText = StringVar()
TimeRemainingText = StringVar()
TimeRemainingAtText = StringVar()
TicketRemainText = StringVar()
TicketRemainAtText = StringVar()
TicketTimeText = StringVar()
T1Text = "T1 :"
T2Text = "T2 :"
T2T1Text = "T2 - T1 :"
T3Text = "T3 :"
T4Text = "T4 :"
T4T3Text = "T4 - T3 :"
PauseTimeText = "Pause Time :"
TotalTimeText = "Total Time :"
TimeToReachText = "Time to reach :"
TimeRemainingText = "Time remain :"
TimeRemainingAtText = "at :"
TicketRemainText = "Ticket remain :"
TicketRemainAtText = "at :"
TicketTimeText = "Ticket time :"
#style = ttk.Style()
#style.configure('wt.Horizontal.TProgressbar', fieldbackground='maroon')
#style.map("Horizontal.TProgressbar",fieldbackground=[("active", "black"), ("disabled", "red")])
pbarTime = ttk.Progressbar(root, orient=HORIZONTAL, length=64, mode='determinate')
pbarTicket = ttk.Progressbar(root, orient=HORIZONTAL, length=64, mode='determinate')
def btnExit(*args):
global flag_thread_running
flag_thread_running = False
root.destroy()
sys.exit(0)
def btnRecalc(*args):
global wtime_out
wt = wtime(t1=t1,t2=t2,t3=t3,t4=t4)
wtime_out = wt.calc2()
wt.printout(wtime_out)
gui_update(wtime_out)
def gui_update(out):
T1Content.set(out["t1"])
T2Content.set(out["t2"])
T2T1Content.set(out["t2t1"])
T3Content.set(out["t3"])
T4Content.set(out["t4"])
T4T3Content.set(out["t4t3"])
PauseTimeContent.set(out["pause time"])
TotalTimeContent.set(out.get("total time",""))
TimeToReachContent.set(out.get("time to reach",""))
TimeRemainingContent.set(out.get("time remaining","reached"))
TimeRemainingAtContent.set(out.get("time remaining at",""))
TicketRemainContent.set(out["ticket remaining"])
TicketRemainAtContent.set(out.get("ticket remaining at",""))
TicketTimeContent.set(out["ticket time"])
pbarTime["value"] = out["time remaining perc"]
pbarTicket["value"] = out["ticket remaining perc"]
TimePercentage.set("%2d %%" % out["time remaining perc"])
TicketPercentage.set("%2d %%" % out["ticket remaining perc"])
def check_time():
global root
global wtime_out
global flag_ticket_reached
global flag_time_reached
global flag_thread_running
global interval_thread_waitcycles
time.sleep(1)
flag_thread_running = True
try:
t = currentThread()
except NameError:
t = current_thread()
while flag_thread_running:
if wtime_out.get("overtime",None) is not None and flag_time_reached == False:
root.attributes("-topmost", True)
print("You've DONE!!!")
tkMessageBox.showinfo("wtimegui", "You've DONE!!!",parent=root)
flag_time_reached = True
flag_thread_running = False
root.attributes("-topmost", False)
continue
elif wtime_out["ticket remaining"] == "reached" and flag_ticket_reached == False:
root.attributes("-topmost", True)
print("Ticket reached!!!")
tkMessageBox.showinfo("wtimegui", "Ticket reached!!!",parent=root)
flag_ticket_reached = True
root.attributes("-topmost", False)
btnRecalc()
for i in range(1,interval_thread_waitcycles):
if flag_thread_running:
time.sleep(1)
else:
break
if __name__ == "__main__":
t1,t2,t3,t4 = wtime.getTimes("wtime3")
wt = wtime(t1=t1,t2=t2,t3=t3,t4=t4)
wtime_out = wt.calc2()
wt.printout(wtime_out)
gui_update(wtime_out)
GUI = (
{"label": T1Text,
"label content": T1Content,
"row": 0,
"column": 0},
{"label": T2Text,
"label content": T2Content,
"row": 1,
"column": 0},
{"label": T2T1Text,
"label content": T2T1Content,
"row": 1,
"column": 2},
{"label": T3Text,
"label content": T3Content,
"row": 2,
"column": 0},
{"label": T4Text,
"label content": T4Content,
"row": 3,
"column": 0},
{"label": T4T3Text,
"label content": T4T3Content,
"row": 3,
"column": 2},
{"label": PauseTimeText,
"label content": PauseTimeContent,
"row": 4,
"column": 0},
{"label": TotalTimeText,
"label content": TotalTimeContent,
"row": 5,
"column": 0},
{"label": TimeToReachText,
"label content": TimeToReachContent,
"row": 6,
"column": 0},
{"label": TimeRemainingText,
"label content": TimeRemainingContent,
"row": 7,
"column": 0},
{"label": TimeRemainingAtText,
"label content": TimeRemainingAtContent,
"row": 8,
"column": 0},
{"label": TicketRemainText,
"label content": TicketRemainContent,
"row": 9,
"column": 0},
{"label": TicketRemainAtText,
"label content": TicketRemainAtContent,
"row": 10,
"column": 0},
{"label": TicketTimeContent,
"label content": TicketTimeContent,
"row":11,
"column": 0},
{"label": TimePercentage,
"label content": None,
"row": 7,
"column": 2},
{"label": TicketPercentage,
"label content": None,
"row": 9,
"column": 2},
)
for gui_element in GUI:
Label(root, textvariable=gui_element["label"], text=gui_element["label"], font=lblFONT, fg=lblFGCOLOR).grid(row=gui_element["row"], column=gui_element["column"])
if gui_element["label content"] is not None:
Label(root, textvariable = gui_element["label content"], text=gui_element["label content"], font=lblFONT, fg=lblFGCOLOR).grid(row=gui_element["row"], column=gui_element["column"]+1)
pbarTime.grid(row=7,column=3)
pbarTicket.grid(row=9,column=3)
Button(root, text="Exit", command=btnExit).grid(row=12,column=3)
Button(root, text="Recalc", command=btnRecalc).grid(row=12,column=1)
root.bind('<Return>',btnRecalc)
root.bind('<space>',btnRecalc)
root.bind('<Escape>',btnExit)
check_time_thread = Thread(target=check_time, args=())
check_time_thread.start()
root.lift ()
root.protocol("WM_DELETE_WINDOW", btnExit)
root.call('wm', 'attributes', '.', '-topmost', True)
root.after_idle(root.call, 'wm', 'attributes', '.', '-topmost', False)
root.mainloop()