44import pathlib
55
66from PySide6 import QtCore
7- from PySide6 .QtWidgets import QApplication , QMainWindow , QMessageBox , QSystemTrayIcon , QMenu
8- from PySide6 .QtGui import QIcon , QPixmap , QAction
7+ from PySide6 .QtWidgets import (
8+ QApplication ,
9+ QMainWindow ,
10+ QMessageBox ,
11+ QSystemTrayIcon ,
12+ QMenu ,
13+ )
14+ from PySide6 .QtGui import QIcon , QPixmap , QAction
915
1016from mainUi import Ui_main_window
1117
1723import ctypes
1824
1925import configparser
26+
2027SETTINGS = "settings.ini"
2128
29+
2230def validate_settings ():
2331 # ? checks if setting.ini exist, if not make it with default settings
2432 if not os .path .exists (SETTINGS ):
@@ -47,7 +55,13 @@ def validate_settings():
4755 config ["repeat" ] = {"repeat-times" : "0" , "repeat-type" : "2" }
4856 config ["position" ] = {"pos-type" : "1" , "pos-x" : "0" , "pos-y" : "0" }
4957 config ["shortcuts" ] = {"Activate-key" : "F6" , "Stop-key" : "F6" }
58+ config ["checkbox" ] = {
59+ "tray_icon_visible" : "False" ,
60+ "alt_click" : "False" ,
61+ }
5062 config .write (file )
63+
64+
5165validate_settings ()
5266
5367# ? replace this during build time with import pyautogui, its just there to get rid of the annoying error that the user will never see
@@ -63,7 +77,7 @@ def __init__(self):
6377
6478 self .config = configparser .ConfigParser ()
6579 self .config .read ("settings.ini" )
66-
80+
6781 self .ui = Ui_main_window ()
6882 self .ui .setupUi (self )
6983 self .setWindowFlags (self .windowFlags () | QtCore .Qt .CustomizeWindowHint )
@@ -92,26 +106,30 @@ def __init__(self):
92106 logger .info ("thread successfully initiated." )
93107
94108 # & startup tasks
95- self .ui .le_hours .setText (self .config [' interval' ][ ' hour' ])
96- self .ui .le_mins .setText (self .config [' interval' ][ ' minute' ])
97- self .ui .le_s .setText (self .config [' interval' ][ ' second' ])
98- self .ui .le_ms .setText (self .config [' interval' ][ ' milliseconds' ])
109+ self .ui .le_hours .setText (self .config [" interval" ][ " hour" ])
110+ self .ui .le_mins .setText (self .config [" interval" ][ " minute" ])
111+ self .ui .le_s .setText (self .config [" interval" ][ " second" ])
112+ self .ui .le_ms .setText (self .config [" interval" ][ " milliseconds" ])
99113
100- self .ui .le_timer_h .setText (self .config [' timer' ][ ' hour' ])
101- self .ui .le_timer_min .setText (self .config [' timer' ][ ' minute' ])
102- self .ui .le_timer_s .setText (self .config [' timer' ][ ' second' ])
103- self .ui .le_timer_ms .setText (self .config [' timer' ][ ' milliseconds' ])
114+ self .ui .le_timer_h .setText (self .config [" timer" ][ " hour" ])
115+ self .ui .le_timer_min .setText (self .config [" timer" ][ " minute" ])
116+ self .ui .le_timer_s .setText (self .config [" timer" ][ " second" ])
117+ self .ui .le_timer_ms .setText (self .config [" timer" ][ " milliseconds" ])
104118
105- self .ui .le_hold_hours .setText (self .config [' holdTime' ][ ' hour' ])
106- self .ui .le_hold_mins .setText (self .config [' holdTime' ][ ' minute' ])
107- self .ui .le_hold_s .setText (self .config [' holdTime' ][ ' second' ])
108- self .ui .le_hold_ms .setText (self .config [' holdTime' ][ ' milliseconds' ])
119+ self .ui .le_hold_hours .setText (self .config [" holdTime" ][ " hour" ])
120+ self .ui .le_hold_mins .setText (self .config [" holdTime" ][ " minute" ])
121+ self .ui .le_hold_s .setText (self .config [" holdTime" ][ " second" ])
122+ self .ui .le_hold_ms .setText (self .config [" holdTime" ][ " milliseconds" ])
109123
110124 self .ui .repeat_times .setValue (int (self .config ["repeat" ]["repeat-times" ]))
111125
112- self .ui .tray_icon_visible .setChecked (bool (self .config .getboolean ("checkbox" , "tray_icon_visible" )))
113- self .ui .alt_clk_checkbox .setChecked (bool (self .config .getboolean ("checkbox" , "alt_click" )))
114-
126+ self .ui .tray_icon_visible .setChecked (
127+ bool (self .config .getboolean ("checkbox" , "tray_icon_visible" ))
128+ )
129+ self .ui .alt_clk_checkbox .setChecked (
130+ bool (self .config .getboolean ("checkbox" , "alt_click" ))
131+ )
132+
115133 self .update_vars () # ? runs once to update properly
116134
117135 # & Connections
@@ -142,12 +160,12 @@ def __init__(self):
142160 self .ui .btn_stop .clicked .connect (self .stop )
143161 self .ui .btn_shortcut .clicked .connect (self .shortcut_change )
144162 self .ui .btn_help .clicked .connect (self .help_func )
145-
163+
146164 self .ui .alt_clk_checkbox .clicked .connect (self .alt_clk_checkbox_function )
147165 self .ui .tray_icon_visible .clicked .connect (self .tray_icon_visible_function )
148- # & Tray icon and functionality
166+ # & Tray icon and functionality
149167 # Create the system tray icon
150- self .tray_icon = QSystemTrayIcon (QIcon (self .icon_name ), self )
168+ self .tray_icon = QSystemTrayIcon (QIcon (self .icon_name ), self )
151169
152170 # Create a context menu for the tray icon
153171 self .tray_menu = QMenu ()
@@ -163,10 +181,10 @@ def __init__(self):
163181
164182 # Connect the activated signal to a method
165183 self .tray_icon .activated .connect (self .tray_icon_activated )
166-
184+
167185 if self .ui .tray_icon_visible .isChecked ():
168186 self .tray_icon .show ()
169-
187+
170188 # & Final tasks which has to do with shortcut btn
171189 self .shortcut_start_stop = self .config ["shortcuts" ]["activate-key" ]
172190 keyboard .add_hotkey (self .shortcut_start_stop , self .shortcut_func )
@@ -441,13 +459,13 @@ def update_vars(self):
441459 + int (self .ui .le_s .text ())
442460 + int (self .ui .le_ms .text ()) / 1000
443461 )
444- self .config [' interval' ][ ' hour' ] = self .ui .le_hours .text ()
445- self .config [' interval' ][ ' minute' ] = self .ui .le_mins .text ()
446- self .config [' interval' ][ ' second' ] = self .ui .le_s .text ()
447- self .config [' interval' ][ ' milliseconds' ] = self .ui .le_ms .text ()
448- with open (SETTINGS , "w" ) as f :
462+ self .config [" interval" ][ " hour" ] = self .ui .le_hours .text ()
463+ self .config [" interval" ][ " minute" ] = self .ui .le_mins .text ()
464+ self .config [" interval" ][ " second" ] = self .ui .le_s .text ()
465+ self .config [" interval" ][ " milliseconds" ] = self .ui .le_ms .text ()
466+ with open (SETTINGS , "w" ) as f :
449467 self .config .write (f )
450-
468+
451469 except ValueError :
452470 self .click_speed = - 1
453471 logger .warning (
@@ -460,13 +478,13 @@ def update_vars(self):
460478 + int (self .ui .le_timer_s .text ())
461479 + int (self .ui .le_timer_ms .text ()) / 1000
462480 )
463- self .config [' timer' ][ ' hour' ] = self .ui .le_timer_h .text ()
464- self .config [' timer' ][ ' minute' ] = self .ui .le_timer_min .text ()
465- self .config [' timer' ][ ' second' ] = self .ui .le_timer_s .text ()
466- self .config [' timer' ][ ' milliseconds' ] = self .ui .le_timer_ms .text ()
467- with open (SETTINGS , "w" ) as f :
481+ self .config [" timer" ][ " hour" ] = self .ui .le_timer_h .text ()
482+ self .config [" timer" ][ " minute" ] = self .ui .le_timer_min .text ()
483+ self .config [" timer" ][ " second" ] = self .ui .le_timer_s .text ()
484+ self .config [" timer" ][ " milliseconds" ] = self .ui .le_timer_ms .text ()
485+ with open (SETTINGS , "w" ) as f :
468486 self .config .write (f )
469-
487+
470488 except ValueError :
471489 self .click_timer = - 1
472490 logger .warning (
@@ -479,21 +497,21 @@ def update_vars(self):
479497 + int (self .ui .le_hold_s .text ())
480498 + int (self .ui .le_hold_ms .text ()) / 1000
481499 )
482- self .config [' holdTime' ][ ' hour' ] = self .ui .le_hold_hours .text ()
483- self .config [' holdTime' ][ ' minute' ] = self .ui .le_hold_mins .text ()
484- self .config [' holdTime' ][ ' second' ] = self .ui .le_hold_s .text ()
485- self .config [' holdTime' ][ ' milliseconds' ] = self .ui .le_hold_ms .text ()
486- with open (SETTINGS , "w" ) as f :
500+ self .config [" holdTime" ][ " hour" ] = self .ui .le_hold_hours .text ()
501+ self .config [" holdTime" ][ " minute" ] = self .ui .le_hold_mins .text ()
502+ self .config [" holdTime" ][ " second" ] = self .ui .le_hold_s .text ()
503+ self .config [" holdTime" ][ " milliseconds" ] = self .ui .le_hold_ms .text ()
504+ with open (SETTINGS , "w" ) as f :
487505 self .config .write (f )
488-
506+
489507 except ValueError :
490508 self .click_hold = - 1
491509 logger .warning (
492510 "Wrong values for click hold, use different values, this warning is safe."
493511 )
494512 self .click_repeat = abs (int (self .ui .repeat_times .text ()))
495513 self .config ["repeat" ]["repeat-times" ] = str (self .click_repeat )
496- with open (SETTINGS , "w" ) as f :
514+ with open (SETTINGS , "w" ) as f :
497515 self .config .write (f )
498516 self .click_type = {"Single" : 1 , "Double" : 2 , "Triple" : 3 }
499517
@@ -535,24 +553,28 @@ def restore_window(self):
535553 def exit_app (self ):
536554 # self.tray_icon.setVisible(False) # Hide the tray icon
537555 QApplication .quit () # Exit the application
556+
538557 # & -------------------------
539-
558+
540559 # & Checkbox functions
541560 def alt_clk_checkbox_function (self ):
542561 self .config ["checkbox" ]["alt_click" ] = str (self .ui .alt_clk_checkbox .isChecked ())
543- with open (SETTINGS , "w" ) as f :
562+ with open (SETTINGS , "w" ) as f :
544563 self .config .write (f )
545-
564+
546565 def tray_icon_visible_function (self ):
547- self .config ["checkbox" ]["tray_icon_visible" ] = str (self .ui .tray_icon_visible .isChecked ())
548- with open (SETTINGS , "w" ) as f :
566+ self .config ["checkbox" ]["tray_icon_visible" ] = str (
567+ self .ui .tray_icon_visible .isChecked ()
568+ )
569+ with open (SETTINGS , "w" ) as f :
549570 self .config .write (f )
550-
571+
551572 if self .ui .tray_icon_visible .isChecked ():
552573 self .tray_icon .show ()
553574 else :
554575 self .tray_icon .hide ()
555-
576+
577+
556578def main () -> None :
557579
558580 # ^ checking if essential folders exist or not, if not create them
0 commit comments