Skip to content

Commit 4544f55

Browse files
committed
added autostart option
1 parent 2b9e79e commit 4544f55

File tree

4 files changed

+54
-15
lines changed

4 files changed

+54
-15
lines changed

SimpleMonitorControlTray/configHandler.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def check_for_missing_files():
2626

2727
if not os.path.exists(MULTIMONITORTOOL_PATH):
2828
nH.sendError(MULTIMONITORTOOL_PATH + fileNotFound)
29-
tH.quitItemClicked()
29+
tH.exitItemClicked()
3030
if not os.path.exists(os.path.join(currentPath, asset_iconEnabled)):
3131
nH.sendError(asset_iconDisabled + fileNotFound)
32-
tH.quitItemClicked()
32+
tH.exitItemClicked()
3333

3434
if not os.path.exists(CSV_FILE_PATH):
3535
mH.saveMultiMonitorToolConfig()
@@ -47,19 +47,35 @@ def check_for_missing_files():
4747

4848
def read_config():
4949

50-
global MULTIMONITORTOOL_PATH, CSV_FILE_PATH, MM_CONFIG_FILE_PATH, MONITOR_NAME
50+
global AUTOSTART, MULTIMONITORTOOL_PATH, CSV_FILE_PATH, MM_CONFIG_FILE_PATH, MONITOR_NAME
5151

5252
if not os.path.exists(config_file_path):
5353
nH.sendError(config_file_path + fileNotFound)
54-
tH.quitItemClicked()
54+
tH.exitItemClicked()
5555

5656
config = configparser.ConfigParser()
5757

5858
config.read(config_file_path, encoding="utf-8")
5959

6060
MULTIMONITORTOOL_PATH = config.get("SETTINGS", "multimonitorpath")
6161
MONITOR_NAME = config.get("SETTINGS", "monitor_name")
62+
AUTOSTART = config.get("SETTINGS", "autostart")
6263
CSV_FILE_PATH = config.get("DEV", "mm_csv_export_path")
6364
MM_CONFIG_FILE_PATH = config.get("DEV", "mm_config_file_path")
6465

6566
check_for_missing_files()
67+
68+
69+
def set_config_value(category, key, value):
70+
config = configparser.ConfigParser()
71+
config.read(config_file_path, encoding="utf-8")
72+
config[category][key] = value
73+
with open(config_file_path, "w") as configfile:
74+
config.write(configfile)
75+
print("Setting config value: " + key + " to " + value)
76+
77+
78+
def get_config_value(category, key):
79+
config = configparser.ConfigParser()
80+
config.read(config_file_path, encoding="utf-8")
81+
return config.get(category, key)

SimpleMonitorControlTray/registryHandler.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def add_to_autostart():
1414

1515

1616
def remove_from_autostart():
17-
key = reg.OpenKey(reg.HKEY_CURRENT_USER, registry_key, 0, reg.KEY_ALL_ACCESS)
18-
reg.DeleteValue(key, keyName)
19-
reg.CloseKey(key)
17+
try:
18+
key = reg.OpenKey(reg.HKEY_CURRENT_USER, registry_key, 0, reg.KEY_ALL_ACCESS)
19+
reg.DeleteValue(key, keyName)
20+
reg.CloseKey(key)
21+
except:
22+
pass

SimpleMonitorControlTray/trayHandler.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import SimpleMonitorControlTray.configHandler as cH
88
import SimpleMonitorControlTray.monitorHandler as mH
9+
import SimpleMonitorControlTray.registryHandler as rH
910

1011
script_dir = os.getcwd()
1112

@@ -15,6 +16,7 @@
1516
title = "SimpleMonitorControlTray"
1617

1718
icon = None
19+
itemTitle = ""
1820

1921

2022
def saveMultiMonitorToolConfigClicked():
@@ -31,42 +33,58 @@ def iconTrayClicked():
3133
icon.icon = imageIconEnabled
3234

3335

34-
def quitItemClicked():
36+
def exitItemClicked():
3537
icon.stop()
3638

3739

3840
def openConfigClicked():
3941
os.startfile(os.path.join(script_dir, cH.config_file_path))
4042

4143

42-
checked = False
44+
def toggleAutostartInConfig():
45+
global itemTitle
46+
if cH.AUTOSTART == "False":
47+
itemTitle = "Disable Autostart"
48+
rH.add_to_autostart()
49+
cH.set_config_value("SETTINGS", "autostart", "True")
50+
cH.AUTOSTART = "True"
51+
else:
52+
itemTitle = "Enable Autostart"
53+
rH.remove_from_autostart()
54+
cH.set_config_value("SETTINGS", "autostart", "False")
55+
cH.AUTOSTART = "False"
4356

4457

4558
def toggleAutostart(icon):
46-
# Recreate the menu with the updated title for "Autostart"
59+
toggleAutostartInConfig()
4760
new_menu = (
48-
item("New Title", toggleAutostart),
61+
item(itemTitle, toggleAutostart),
4962
item(
5063
"Save current monitor layout (used when enabling)",
5164
saveMultiMonitorToolConfigClicked,
5265
),
5366
item("Open Config.ini", openConfigClicked),
54-
item("Quit", quitItemClicked),
67+
item("Exit", exitItemClicked),
5568
)
5669
icon.menu = new_menu
5770

5871

5972
def initTray():
6073
global icon
74+
if cH.AUTOSTART == "True":
75+
itemTitle = "Disable Autostart"
76+
else:
77+
itemTitle = "Enable Autostart"
78+
6179
menu = (
6280
item(title, iconTrayClicked, default=True, visible=False),
63-
item("Autostart", toggleAutostart),
81+
item(itemTitle, toggleAutostart),
6482
item(
6583
"Save current monitor layout (used when enabling)",
6684
saveMultiMonitorToolConfigClicked,
6785
),
6886
item("Open Config.ini", openConfigClicked),
69-
item("Quit", quitItemClicked),
87+
item("Quit", exitItemClicked),
7088
)
7189

7290
firstImageIcon = None

config.ini

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[SETTINGS]
22
monitor_name = \\.\DISPLAY3
33
multimonitorpath = C:\\App_Install\\multimonitortool-x64\\MultiMonitorTool.exe
4-
autostart = False
4+
autostart = True
5+
56
[DEV]
67
mm_csv_export_path = MultiMonitorTool\multiMonitorToolOutput.csv
78
mm_config_file_path = MultiMonitorTool\MultiMonitorToolConfig
9+

0 commit comments

Comments
 (0)