1
1
import time
2
- import sys
3
2
import multiprocess
4
3
import webbrowser
5
- import PySimpleGUI as sg
4
+ import PySimpleGUI as Sg
6
5
import pyautogui as pag
7
6
import keyboard
8
7
import logging
9
- from app .settings .helpers .functions import (get_latest_version , create_process , countdown , graceful_exit , get_hotkey , correct_key ,
10
- is_capslock_on , terminate )
8
+ from app .settings .helpers .functions import (get_latest_version , create_process , countdown , graceful_exit , get_hotkey ,
9
+ correct_key ,
10
+ is_capslock_on , terminate , os_check )
11
11
from threading import Thread , Event
12
12
from app .settings .helpers .mouse_jiggler import jiggler
13
13
from app .settings .helpers .configurator import Configurator
@@ -17,48 +17,49 @@ logging.basicConfig(filename='app/settings/helpers/log.log', encoding='utf-8', l
17
17
18
18
19
19
def about_window ():
20
- layout = [[sg .T (s = 40 )],
21
- [sg .Push (), sg .T (str (WINDOW_TITLE ), font = (FONT_FAMILY , 12 , "bold" )), sg .Push ()],
22
- [sg .Push (), sg .T ("Prevent your PC from sleeping with - 'Don't sleep' \n or X-Sleep for short." ,
23
- font = (FONT_FAMILY , 9 , "italic" ), justification = 'c' , text_color = 'grey' ), sg .Push ()],
24
- [sg .T ()],
25
- [sg .Push (), sg .T (github_url ['name' ], enable_events = True , font = (FONT_FAMILY , 10 , "underline" ),
20
+ layout = [[Sg .T (s = 40 )],
21
+ [Sg .Push (), Sg .T (str (WINDOW_TITLE ), font = (FONT_FAMILY , 12 , "bold" )), Sg .Push ()],
22
+ [Sg .Push (), Sg .T ("Prevent your PC from sleeping with - 'Don't sleep' \n or X-Sleep for short." ,
23
+ font = (FONT_FAMILY , 9 , "italic" ), justification = 'c' , text_color = 'grey' ), Sg .Push ()],
24
+ [Sg .T ()],
25
+ [Sg .Push (), Sg .T (github_url ['name' ], enable_events = True , font = (FONT_FAMILY , 10 , "underline" ),
26
26
justification = 'l' , text_color = '#0066CC' ,
27
- auto_size_text = True , key = '-LINK-' ), sg .Push ()],
28
- [sg .Push (), sg .T ("License: GPL-3.0" , justification = 'c' ), sg .Push ()],
29
- [sg .T ()],
30
- [sg .Push (), sg .T ("Copyright © 2023 Kaloian Kozlev" , text_color = 'light grey' ), sg .Push ()]]
27
+ auto_size_text = True , key = '-LINK-' ), Sg .Push ()],
28
+ [Sg .Push (), Sg .T ("License: GPL-3.0" , justification = 'c' ), Sg .Push ()],
29
+ [Sg .T ()],
30
+ [Sg .Push (), Sg .T ("Copyright © 2023 Kaloian Kozlev" , text_color = 'light grey' ), Sg .Push ()]]
31
31
32
- window = sg .Window ("About" , layout , icon = ICON )
32
+ window = Sg .Window ("About" , layout , icon = ICON )
33
33
34
34
while True :
35
35
event , values = window .read ()
36
36
37
37
match event :
38
- case sg .WIN_CLOSED :
38
+ case Sg .WIN_CLOSED :
39
39
break
40
40
41
41
case '-LINK-' :
42
42
webbrowser .open (github_url ['url' ])
43
43
window .close ()
44
+ break
44
45
45
46
46
- def new_version_check (c_release , c_release_name , l_release , l_release_name , down_url ):
47
+ def new_version_window (c_release , c_release_name , l_release , l_release_name , down_url ):
47
48
global update_check
48
- layout = [[sg .T (s = 40 )],
49
- [sg .T (font = (FONT_FAMILY , 10 ), justification = 'l' , key = "-INFO-" )],
50
- [sg .T ()],
51
- [sg .T ('Current Version is :' , justification = 'l' , font = (FONT_FAMILY , 10 )),
52
- sg .T (f'{ c_release_name } ' , font = (FONT_FAMILY , 10 ))],
53
- [sg .T ('Available Version is:' , justification = 'l' , font = (FONT_FAMILY , 10 )),
54
- sg .T (f'{ l_release_name } ' , font = (FONT_FAMILY , 10 ))],
55
- [sg .T ()],
56
- [sg .Push (),
57
- sg .B ('Yes' , key = '-DOWNLOAD-' , s = 8 , button_color = '#93b7a6' ),
58
- sg .B (key = '-EXIT-' , s = 8 , button_color = '#db5656' ),
59
- sg .Push ()]]
60
-
61
- window = sg .Window ("Update Available" , layout , icon = ICON , keep_on_top = True , finalize = True )
49
+ layout = [[Sg .T (s = 40 )],
50
+ [Sg .T (font = (FONT_FAMILY , 10 ), justification = 'l' , key = "-INFO-" )],
51
+ [Sg .T ()],
52
+ [Sg .T ('Current Version is :' , justification = 'l' , font = (FONT_FAMILY , 10 )),
53
+ Sg .T (f'{ c_release_name } ' , font = (FONT_FAMILY , 10 ))],
54
+ [Sg .T ('Available Version is:' , justification = 'l' , font = (FONT_FAMILY , 10 )),
55
+ Sg .T (f'{ l_release_name } ' , font = (FONT_FAMILY , 10 ))],
56
+ [Sg .T ()],
57
+ [Sg .Push (),
58
+ Sg .B ('Yes' , key = '-DOWNLOAD-' , s = 8 , button_color = '#93b7a6' ),
59
+ Sg .B (key = '-EXIT-' , s = 8 , button_color = '#db5656' ),
60
+ Sg .Push ()]]
61
+
62
+ window = Sg .Window ("Update Available" , layout , icon = ICON , keep_on_top = True , finalize = True )
62
63
63
64
if l_release is None :
64
65
message = "Cannot fetch version data! \n Please check your network connection."
@@ -85,7 +86,7 @@ def new_version_check(c_release, c_release_name, l_release, l_release_name, down
85
86
event , values = window .read ()
86
87
87
88
match event :
88
- case sg .WIN_CLOSED :
89
+ case Sg .WIN_CLOSED :
89
90
break
90
91
91
92
case '-DOWNLOAD-' :
@@ -103,50 +104,54 @@ def main_window():
103
104
104
105
app_menu = [['Help' , ['About' , 'Check for Updates' ]]]
105
106
106
- layout = [[sg .Menubar (app_menu )],
107
- [sg .Frame ('Hotkey' ,
108
- [[sg .I (disabled = True , default_text = hot_key , justification = 'c' ,
107
+ layout = [[Sg .Menubar (app_menu )],
108
+ [Sg .Frame ('Hotkey' ,
109
+ [[Sg .I (disabled = True , default_text = hot_key , justification = 'c' ,
109
110
disabled_readonly_text_color = 'grey' , disabled_readonly_background_color = '#dae0e6' ,
110
111
key = '-HT_KEY-' , tooltip = "ALT, CTRL, SHIFT, WINDOWS, A-Z, 0-9, F1-F12" )],
111
- [sg .Checkbox ('Change' , key = '-CHANGE-' , enable_events = True ), sg .Push (),
112
- sg .B ('Reset' , size = 8 , key = '-RESET-' ),
113
- sg .B ('Apply' , size = 8 , disabled = True , disabled_button_color = 'light grey' , key = '-APPLY-' )]
112
+ [Sg .Checkbox ('Change' , key = '-CHANGE-' , enable_events = True , disabled = True ), Sg .Push (),
113
+ Sg .B ('Reset' , size = 8 , key = '-RESET-' , disabled_button_color = 'light grey' , disabled = True ),
114
+ Sg .B ('Apply' , size = 8 , disabled = True , disabled_button_color = 'light grey' , key = '-APPLY-' )]
114
115
], expand_x = True )],
115
- [sg .Frame ('Timer' ,
116
- [[sg .T ('Hours:' ), sg .DropDown (HOURS , default_value = ' 00' , key = '-H-' , disabled = True ,
116
+ [Sg .Frame ('Timer' ,
117
+ [[Sg .T ('Hours:' ), Sg .DropDown (HOURS , default_value = ' 00' , key = '-H-' , disabled = True ,
117
118
readonly = True , button_background_color = '#93b7a6' , s = (3 , 1 )),
118
- sg .T ('Minutes:' ), sg .DropDown (MINUTES , default_value = ' 00' , key = '-M-' , disabled = True ,
119
+ Sg .T ('Minutes:' ), Sg .DropDown (MINUTES , default_value = ' 00' , key = '-M-' , disabled = True ,
119
120
readonly = True , button_background_color = '#93b7a6' , s = (3 , 1 )),
120
- sg .T ('Seconds:' ), sg .DropDown (SECONDS , default_value = ' 00' , key = '-S-' , disabled = True ,
121
+ Sg .T ('Seconds:' ), Sg .DropDown (SECONDS , default_value = ' 00' , key = '-S-' , disabled = True ,
121
122
readonly = True , button_background_color = '#93b7a6' , s = (3 , 1 ))
122
123
],
123
- [sg .Radio ('Off' , 'timer' , default = True , enable_events = True , key = '-OFF-' ),
124
- sg .Radio ('On' , 'timer' , enable_events = True , key = '-ON-' ), sg .Push (),
125
- sg .I (background_color = '#dae0e6' , size = 8 , key = '-LOG_TIME-' , justification = 'c' ,
124
+ [Sg .Radio ('Off' , 'timer' , default = True , enable_events = True , key = '-OFF-' ),
125
+ Sg .Radio ('On' , 'timer' , enable_events = True , key = '-ON-' ), Sg .Push (),
126
+ Sg .I (background_color = '#dae0e6' , size = 8 , key = '-LOG_TIME-' , justification = 'c' ,
126
127
default_text = '00:00:00' , disabled = True , disabled_readonly_text_color = 'grey' ,
127
128
disabled_readonly_background_color = '#dae0e6' , readonly = True )]
128
129
], expand_x = True )],
129
- [sg .Frame ('Log' ,
130
- [[sg .Input (background_color = '#dae0e6' , size = 45 , key = '-LOG-' , justification = 'c' ,
130
+ [Sg .Frame ('Log' ,
131
+ [[Sg .Input (background_color = '#dae0e6' , size = 45 , key = '-LOG-' , justification = 'c' ,
131
132
text_color = 'white' )]], expand_x = True )],
132
- [sg .Button ('Start' , size = 8 , button_color = '#93b7a6' , disabled_button_color = 'light grey' ,
133
+ [Sg .Button ('Start' , size = 8 , button_color = '#93b7a6' , disabled_button_color = 'light grey' ,
133
134
key = '-START-' ),
134
- sg .Button ('Stop' , size = 8 , button_color = '#ffcf61' , disabled = True ,
135
+ Sg .Button ('Stop' , size = 8 , button_color = '#ffcf61' , disabled = True ,
135
136
disabled_button_color = 'light grey' , key = '-STOP-' ),
136
- sg .Button ('Exit' , size = 8 , button_color = '#db5656' )]
137
+ Sg .Button ('Exit' , size = 8 , button_color = '#db5656' )]
137
138
]
138
139
139
- window = sg .Window (WINDOW_TITLE , layout , keep_on_top = False )
140
+ window = Sg .Window (WINDOW_TITLE , layout , keep_on_top = False )
141
+
142
+ if update_check :
143
+ new_version_window (RELEASE , RELEASE_NAME , latest_release , latest_release_name , download_url )
140
144
141
145
while True :
142
146
event , values = window .read (timeout = 10 )
143
147
144
- if update_check :
145
- new_version_check (RELEASE , RELEASE_NAME , latest_release , latest_release_name , download_url )
148
+ if hot_key_active :
149
+ window ['-CHANGE-' ].update (disabled = False )
150
+ window ['-RESET-' ].update (disabled = False )
146
151
147
- keyboard .add_hotkey (hot_key , lambda : graceful_exit (thread_event , window , pag ))
152
+ keyboard .add_hotkey (hot_key , lambda : graceful_exit (thread_event , window , pag ))
148
153
149
- if event in ('Exit' , sg .WIN_CLOSED ):
154
+ if event in ('Exit' , Sg .WIN_CLOSED ):
150
155
break
151
156
152
157
if event == '-START-' :
@@ -169,7 +174,7 @@ def main_window():
169
174
window ['-LOG-' ].update ('Application running' , background_color = '#5fad65' )
170
175
171
176
elif event == '-STOP-' :
172
- is_capslock_on (pag )
177
+ is_capslock_on (pag , os_name = os_name )
173
178
174
179
if values ['-ON-' ] and values ['-LOG_TIME-' ] != '00:00:00' :
175
180
thread_event .set ()
@@ -231,16 +236,28 @@ def main_window():
231
236
about_window ()
232
237
233
238
if event == 'Check for Updates' :
234
- new_version_check (RELEASE , RELEASE_NAME , latest_release , latest_release_name , download_url )
239
+ new_version_window (RELEASE , RELEASE_NAME , latest_release , latest_release_name , download_url )
235
240
236
241
graceful_exit (thread_event , window , pag )
237
242
238
243
239
244
if __name__ == '__main__' :
240
- if sys .platform .startswith ('win' ):
245
+ hot_key_active = False
246
+ thread_event = Event ()
247
+ conf = Configurator ()
248
+ conf .create_on_start ()
249
+ hot_key = get_hotkey (conf )
250
+ update_check = False
251
+ bgp = None
252
+ os_name = os_check ()
253
+
254
+ if os_name == "windows" :
241
255
multiprocess .freeze_support ()
256
+ hot_key_active = True
257
+ else :
258
+ hot_key = 'Not Supported on this platform'
242
259
243
- RELEASE_NAME = '2 .0.2 '
260
+ RELEASE_NAME = '3 .0.0 '
244
261
RELEASE = int ('' .join (filter (lambda x : x .isdigit (), RELEASE_NAME )))
245
262
WINDOW_TITLE = "X-Sleep"
246
263
FONT_FAMILY = "Arial"
@@ -252,15 +269,8 @@ if __name__ == '__main__':
252
269
github_url = {'name' : 'Official GitHub Page' ,
253
270
'url' : 'https://github.com/kbkozlev/x-sleepGUI' }
254
271
255
- sg .theme ("Reddit" )
256
- sg .set_options (force_modal_windows = True , dpi_awareness = True , use_ttk_buttons = True , icon = ICON )
257
-
258
- thread_event = Event ()
259
- conf = Configurator ()
260
- conf .create_on_start ()
261
- hot_key = get_hotkey (conf )
262
- update_check = False
263
- bgp = None
272
+ Sg .theme ("Reddit" )
273
+ Sg .set_options (force_modal_windows = True , dpi_awareness = True , use_ttk_buttons = True , icon = ICON )
264
274
265
275
latest_release , latest_release_name , download_url = get_latest_version ()
266
276
if latest_release is not None and latest_release > RELEASE :
0 commit comments