-
Notifications
You must be signed in to change notification settings - Fork 0
/
report_clock
221 lines (131 loc) · 4.66 KB
/
report_clock
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
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
from time import strftime, gmtime
import winsound
import pathlib
current_dir = str(pathlib.Path.cwd())
file_path = current_dir + '\\alarm.wav'
lines = ['Mute = False\n', '.5 Metar = False']
name = 'ReportClock'
global root, CheckVar1_value, CheckVar2_value, icon, isHidden, state
state = True
isHidden = False
if pathlib.Path(current_dir + '\\clock.txt').is_file():
with open (current_dir + '\\clock.txt', 'r') as f:
lines = f.readlines()
if 'False' in lines[0]:
Mute = False
else:
Mute = True
if 'False' in lines[1]:
Metar = False
else:
Metar = True
else:
with open (current_dir + '\\clock.txt', 'w') as f:
f.writelines(lines)
Mute = False
Metar = False
fn = current_dir + '\\clock.txt'
CheckVar1_value = Mute
CheckVar2_value = Metar
global tuple2
tuple2 = (100, 100)
def About():
messagebox.showinfo('About', 'The author is Seyed Abdolvahab Taghavi.')
def ring():
global tuple2, CheckVar1_value, CheckVar2_value, root, lbl, isHidden, state, CheckVar1, CheckVar2
if state:
L = [50]
if CheckVar2.get() == 1:
L.append(20)
CheckVar1_value = CheckVar1.get()
zolotime = gmtime()
tuple1 = (zolotime.tm_min, zolotime.tm_sec)
if ((tuple1[0] in L and tuple1[1] ==0) or (tuple1 == tuple2)) and CheckVar1_value == 0:
if isHidden:
root.deiconify()
root.attributes("-topmost", True)
root.focus_force()
winsound.PlaySound(file_path, winsound.SND_LOOP + winsound.SND_ASYNC)
message = messagebox.askquestion("snooze","snooze", default='no')
if message == 'yes':
winsound.PlaySound(None, winsound.SND_PURGE)
zolotime2 = gmtime()
tm_min = zolotime2.tm_min + 1
tm_min = (tm_min - 60) * (tm_min >= 60) + tm_min * (tm_min < 60)
tuple2 = (tm_min, zolotime2.tm_sec)
else:
winsound.PlaySound(None, winsound.SND_PURGE)
tuple2 = (100, 100)
root.after(1000, ring)
def show_time():
global root, CheckVar1, CheckVar1_value, lbl
string = strftime('%H:%M:%S %p')
lbl.config(text=string)
root.after(1000, show_time)
def window():
global root, CheckVar1_value, CheckVar1, lbl, CheckVar2_value, CheckVar2
root = Tk()
root.geometry("200x100")
root.title('Clock')
root.iconbitmap('Clock.ico')
lbl = Label(root, font=('calibri', 40, 'bold'),
background='blue',
foreground='white')
CheckVar1 = IntVar()
CheckVar2 = IntVar()
CheckVar1.set(CheckVar1_value)
CheckVar2.set(CheckVar2_value)
def checkbutton():
bool1 = bool(CheckVar1.get())
str1 = str(bool1)
bool2 = bool(CheckVar2.get())
str2 = str(bool2)
lines12 = ['Mute = ' + str1 + '\n', '.5 Metar = ' + str2]
with open (current_dir + '\\clock.txt', 'w') as f:
f.writelines(lines12)
Ch1 = Checkbutton(root, text = "Mute", variable = CheckVar1, \
onvalue = 1, offvalue = 0, command=checkbutton)
Ch2 = Checkbutton(root, text = ".5 h METAR", variable = CheckVar2, \
onvalue = 1, offvalue = 0, command=checkbutton)
lbl.pack(anchor='center')
Ch1.pack(anchor='sw')
Ch2.place(x=75, y=70)
CheckVar1_value = CheckVar1.get()
CheckVar2_value = CheckVar2.get()
menubar = Menu(root )
root.config(menu=menubar)
menubar.add_command(label="About!", command=About)
root.resizable(0, 0)
ring()
show_time()
root.protocol('WM_DELETE_WINDOW', conceal_window )
root.mainloop()
quit_event = EV()
def qcallback(systray):
global root
global state
state = False
root.withdraw()
root.quit()
quit_event.set()
def show_window(systray):
global root, isHidden
root.deiconify()
isHidden = False
def hide_window(systray):
global root, isHidden
root.withdraw()
isHidden = True
def conceal_window():
global root, isHidden
root.withdraw()
isHidden = True
menu_options = ( ("show_window", None, show_window),("hide_window", None, hide_window),)
systray = SysTrayIcon("Clock.ico", "Report Clock icon", menu_options, on_quit=qcallback)
with systray:
window()
quit_event.wait(timeout=None) # returns True if quit_event is set and False if not and timeout reached
print("The code ran properly.")