11import configparser
22import os
33
4- import smct_pkg .mmt as mmt
5- import smct_pkg .notification as notification
6- import smct_pkg .paths as paths
4+ from smct_pkg import multimonitortool , notification , paths , registry , ui_strings
75
8- MMT_PATH , MONITOR_NAME , AUTOSTART , FIRST_START = (
9- "" ,
10- "" ,
11- False ,
12- True ,
13- )
6+ ENCODING = "utf-8"
7+
8+ # keys
9+ SETTINGS_SECTION = "Settings"
10+ MONITOR_NAME_KEY = "monitor_name"
11+ MULTIMONITORTOOL_EXECUTABLE_KEY = "multimonitortool_executable"
12+ START_WITH_WINDOWS_KEY = "start_with_windows"
13+ FIRT_START_KEY = "first_start"
14+
15+ # values
16+ MMT_PATH_VALUE = ""
17+ MONITOR_NAME_VALUE = ""
18+ AUTOSTART_VALUE = False
19+ FIRST_START_VALUE = True
20+
21+ _configparser = configparser .ConfigParser ()
22+ _configparser .read (paths .CONFIG_PATH , encoding = ENCODING )
1423
1524
1625def check_for_missing_files ():
@@ -19,60 +28,69 @@ def check_for_missing_files():
1928 os .makedirs (paths .ASSETS_DIR_PATH )
2029 # Check for Icons
2130 if not os .path .exists (paths .ASSETS_ICON_ENABLED_PATH ):
22- notification .send_error (paths .ASSETS_ICON_ENABLED_PATH + paths .FILE_NOT_FOUND )
31+ notification .send_error (
32+ paths .ASSETS_ICON_ENABLED_PATH + ui_strings .FILE_NOT_FOUND
33+ )
2334 if not os .path .exists (paths .ASSETS_ICON_DISABLED_PATH ):
24- notification .send_error (paths .ASSETS_ICON_DISABLED_PATH + paths .FILE_NOT_FOUND )
35+ notification .send_error (
36+ paths .ASSETS_ICON_DISABLED_PATH + ui_strings .FILE_NOT_FOUND
37+ )
2538
2639 # Check for MultiMonitorTool
27- if not os .path .exists (MMT_PATH ):
28- notification .send_error (MMT_PATH + paths .FILE_NOT_FOUND )
40+ if not os .path .exists (MMT_PATH_VALUE ):
41+ notification .send_error (MMT_PATH_VALUE + ui_strings .FILE_NOT_FOUND )
2942
3043 # Check for temp folder
3144 if not os .path .exists (paths .TEMP_DIR_PATH ):
3245 os .makedirs (paths .TEMP_DIR_PATH )
3346
3447 # Check for MultiMonitorTool CSV
3548 if not os .path .exists (paths .MMT_CSV_PATH ):
36- mmt .save_mmt_config ()
49+ multimonitortool .save_mmt_config ()
3750
3851
3952def read_config ():
4053 # Check if config.ini file is present
4154 if not os .path .exists (paths .CONFIG_PATH ):
42- notification .send_error (paths .CONFIG_PATH + paths .FILE_NOT_FOUND )
55+ notification .send_error (paths .CONFIG_PATH + ui_strings .FILE_NOT_FOUND )
4356
44- global AUTOSTART , MMT_PATH , MONITOR_NAME , FIRST_START
57+ # * pylint: disable=global-statement
58+ global AUTOSTART_VALUE , MMT_PATH_VALUE , MONITOR_NAME_VALUE , FIRST_START_VALUE
4559
46- config = configparser .ConfigParser ()
60+ MMT_PATH_VALUE = _configparser .get (
61+ SETTINGS_SECTION , MULTIMONITORTOOL_EXECUTABLE_KEY
62+ )
63+ MONITOR_NAME_VALUE = _configparser .get (SETTINGS_SECTION , MONITOR_NAME_KEY )
64+ AUTOSTART_VALUE = _configparser .getboolean (SETTINGS_SECTION , START_WITH_WINDOWS_KEY )
65+ FIRST_START_VALUE = _configparser .getboolean (SETTINGS_SECTION , FIRT_START_KEY )
4766
48- config .read (paths .CONFIG_PATH , encoding = "utf-8" )
67+ if AUTOSTART_VALUE :
68+ registry .add_to_autostart ()
69+ else :
70+ registry .remove_from_autostart ()
4971
50- MMT_PATH = config .get ("SETTINGS" , "multimonitorpath" )
51- MONITOR_NAME = config .get ("SETTINGS" , "monitor_name" )
52- AUTOSTART = config .get ("SETTINGS" , "autostart" )
53- FIRST_START = config .get ("SETTINGS" , "first_start" )
54-
55- check_for_missing_files ()
56-
57- if FIRST_START == "True" :
72+ if FIRST_START_VALUE :
73+ # TODO: Do something else here
5874 notification .send_notification (
59- "If you do not have all Monitors enabled and configured as you like right now, please do so and then right click the tray icon to save the monitor layout. " ,
75+ "placeholder " ,
6076 30 ,
6177 )
62- FIRST_START = "False"
63- set_config_value ("SETTINGS" , "first_start" , FIRST_START )
78+ FIRST_START_VALUE = False
79+ set_config_value (SETTINGS_SECTION , FIRT_START_KEY , FIRST_START_VALUE )
80+
81+ check_for_missing_files ()
6482
6583
66- def set_config_value (category , key , value ):
67- config = configparser .ConfigParser ()
68- config .read (paths .CONFIG_PATH , encoding = "utf-8" )
69- config [category ][key ] = value
70- with open (paths .CONFIG_PATH , "w" ) as configfile :
71- config .write (configfile )
84+ def set_config_value (section , key , value ):
85+ if isinstance (value , bool ):
86+ value_str = "yes" if value else "no"
87+ else :
88+ value_str = str (value )
89+ _configparser [section ][key ] = value_str
90+ with open (paths .CONFIG_PATH , "w" , encoding = ENCODING ) as configfile :
91+ _configparser .write (configfile )
7292 # print("Setting config value: " + key + " to " + value)
7393
7494
75- def get_config_value (category , key ):
76- config = configparser .ConfigParser ()
77- config .read (paths .CONFIG_PATH , encoding = "utf-8" )
78- return config .get (category , key )
95+ def get_config_value (section , key ):
96+ return _configparser .get (section , key )
0 commit comments