Skip to content

Commit abf55cc

Browse files
committed
refactoring, renaming, first steps for guided setup
1 parent 494fcad commit abf55cc

File tree

13 files changed

+446
-197
lines changed

13 files changed

+446
-197
lines changed

config.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[SETTINGS]
1+
[Settings]
22
monitor_name = DELL U2422H
3-
multimonitorpath = C:\\App_Install\\multimonitortool-x64\\MultiMonitorTool.exe
4-
autostart = False
5-
first_start = False
3+
multimonitortool_executable = C:\\App_Install\\multimonitortool-x64\\MultiMonitorTool.exe
4+
start_with_windows = no
5+
first_start = no
66

SimpleMonitorControlTray.py renamed to main.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import smct_pkg.config as config
2-
import smct_pkg.tray as tray
3-
1+
from smct_pkg import config, tray
42

53
# TODO add selection of monitor at startup
6-
# TODO clean up imports like so:
7-
# import smct_pkg.config
84

95

106
def main():

smct_pkg/config.py

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import configparser
22
import 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

1625
def 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

3952
def 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)

smct_pkg/customtkinter_example.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import customtkinter
2+
import tkinterDnD
3+
4+
customtkinter.set_ctk_parent_class(tkinterDnD.Tk)
5+
6+
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
7+
customtkinter.set_default_color_theme(
8+
"dark-blue"
9+
) # Themes: "blue" (standard), "green", "dark-blue"
10+
11+
app = customtkinter.CTk()
12+
app.geometry("400x780")
13+
app.title("CustomTkinter simple_example.py")
14+
15+
print(type(app), isinstance(app, tkinterDnD.Tk))
16+
17+
18+
def button_callback():
19+
print("Button click", combobox_1.get())
20+
21+
22+
def slider_callback(value):
23+
progressbar_1.set(value)
24+
25+
26+
frame_1 = customtkinter.CTkFrame(master=app)
27+
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
28+
29+
label_1 = customtkinter.CTkLabel(master=frame_1, justify=customtkinter.LEFT)
30+
label_1.pack(pady=10, padx=10)
31+
32+
progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
33+
progressbar_1.pack(pady=10, padx=10)
34+
35+
button_1 = customtkinter.CTkButton(master=frame_1, command=button_callback)
36+
button_1.pack(pady=10, padx=10)
37+
38+
slider_1 = customtkinter.CTkSlider(
39+
master=frame_1, command=slider_callback, from_=0, to=1
40+
)
41+
slider_1.pack(pady=10, padx=10)
42+
slider_1.set(0.5)
43+
44+
entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
45+
entry_1.pack(pady=10, padx=10)
46+
47+
optionmenu_1 = customtkinter.CTkOptionMenu(
48+
frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."]
49+
)
50+
optionmenu_1.pack(pady=10, padx=10)
51+
optionmenu_1.set("CTkOptionMenu")
52+
53+
combobox_1 = customtkinter.CTkComboBox(
54+
frame_1, values=["Option 1", "Option 2", "Option 42 long long long..."]
55+
)
56+
combobox_1.pack(pady=10, padx=10)
57+
combobox_1.set("CTkComboBox")
58+
59+
checkbox_1 = customtkinter.CTkCheckBox(master=frame_1)
60+
checkbox_1.pack(pady=10, padx=10)
61+
62+
radiobutton_var = customtkinter.IntVar(value=1)
63+
64+
radiobutton_1 = customtkinter.CTkRadioButton(
65+
master=frame_1, variable=radiobutton_var, value=1
66+
)
67+
radiobutton_1.pack(pady=10, padx=10)
68+
69+
radiobutton_2 = customtkinter.CTkRadioButton(
70+
master=frame_1, variable=radiobutton_var, value=2
71+
)
72+
radiobutton_2.pack(pady=10, padx=10)
73+
74+
switch_1 = customtkinter.CTkSwitch(master=frame_1)
75+
switch_1.pack(pady=10, padx=10)
76+
77+
text_1 = customtkinter.CTkTextbox(master=frame_1, width=200, height=70)
78+
text_1.pack(pady=10, padx=10)
79+
text_1.insert("0.0", "CTkTextbox\n\n\n\n")
80+
81+
segmented_button_1 = customtkinter.CTkSegmentedButton(
82+
master=frame_1, values=["CTkSegmentedButton", "Value 2"]
83+
)
84+
segmented_button_1.pack(pady=10, padx=10)
85+
86+
tabview_1 = customtkinter.CTkTabview(master=frame_1, width=300)
87+
tabview_1.pack(pady=10, padx=10)
88+
tabview_1.add("CTkTabview")
89+
tabview_1.add("Tab 2")
90+
91+
app.mainloop()

smct_pkg/customtkintertest.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import customtkinter
2+
import tkinterDnD
3+
4+
from smct_pkg import gui
5+
6+
# https://github.com/TomSchimansky/CustomTkinter/tree/master/examples
7+
# https://github.com/TomSchimansky/CustomTkinter
8+
9+
customtkinter.set_ctk_parent_class(tkinterDnD.Tk)
10+
11+
customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
12+
customtkinter.set_default_color_theme(
13+
"dark-blue"
14+
) # Themes: "blue" (standard), "green", "dark-blue"
15+
16+
app = customtkinter.CTk()
17+
app.geometry("300x180")
18+
app.title("CustomTkinter simple_example.py")
19+
20+
21+
def button_callback():
22+
gui.select_multimonitortool()
23+
24+
25+
frame = customtkinter.CTkFrame(master=app)
26+
frame.pack(pady=20, padx=20, fill="both", expand=True)
27+
28+
select_multimonitortool_label = customtkinter.CTkLabel(
29+
text="Please select your MultiMonitorTool.exe",
30+
master=frame,
31+
justify=customtkinter.LEFT,
32+
)
33+
select_multimonitortool_label.pack(pady=10, padx=10)
34+
35+
browse_button = customtkinter.CTkButton(
36+
text="Browse...", master=frame, command=button_callback
37+
)
38+
browse_button.pack(pady=10, padx=10)
39+
40+
41+
app.mainloop()
42+
43+
# pylint: disable=pointless-string-statement
44+
"""
45+
monitor_selection_menu = customtkinter.CTkOptionMenu(
46+
frame, values=["Option 1", "Option 2", "Option 42 long long long..."]
47+
)
48+
monitor_selection_menu.pack(pady=10, padx=10)
49+
monitor_selection_menu.set("Select your monitor")
50+
"""

0 commit comments

Comments
 (0)