Skip to content

Commit 1ac5801

Browse files
committed
finished adding UI + bugfixes
1 parent 72efcf4 commit 1ac5801

File tree

13 files changed

+40
-105
lines changed

13 files changed

+40
-105
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,5 @@ cython_debug/
153153

154154
output/
155155
.vscode/
156+
temp/
157+
config.ini
File renamed without changes.

config.ini

Lines changed: 0 additions & 7 deletions
This file was deleted.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ win10toast
22
pystray
33
pandas
44
customtkinter
5-
python-tkdnd
5+
CTkMessagebox

smct_pkg/config.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import configparser
22
import os
3+
import sys
34

45
from smct_pkg import (
5-
multimonitortool,
66
notification,
77
paths,
88
registry,
9-
setup_gui,
9+
ui,
1010
ui_strings,
1111
)
1212

@@ -31,31 +31,22 @@
3131

3232

3333
def check_for_missing_files():
34-
# Check for assets folder
35-
if not os.path.exists(paths.ASSETS_DIR_PATH):
36-
os.makedirs(paths.ASSETS_DIR_PATH)
3734
# Check for Icons
3835
if not os.path.exists(paths.ASSETS_ICON_ENABLED_PATH):
3936
notification.send_error(
4037
paths.ASSETS_ICON_ENABLED_PATH + ui_strings.FILE_NOT_FOUND
4138
)
39+
sys.exit(1)
4240
if not os.path.exists(paths.ASSETS_ICON_DISABLED_PATH):
4341
notification.send_error(
4442
paths.ASSETS_ICON_DISABLED_PATH + ui_strings.FILE_NOT_FOUND
4543
)
46-
47-
# Check for MultiMonitorTool
48-
if not os.path.exists(MMT_PATH_VALUE):
49-
notification.send_error(MMT_PATH_VALUE + ui_strings.FILE_NOT_FOUND)
44+
sys.exit(1)
5045

5146
# Check for temp folder
5247
if not os.path.exists(paths.TEMP_DIR_PATH):
5348
os.makedirs(paths.TEMP_DIR_PATH)
5449

55-
# Check for MultiMonitorTool CSV
56-
if not os.path.exists(paths.MMT_CSV_PATH):
57-
multimonitortool.save_mmt_config()
58-
5950

6051
def read_config():
6152
# Check if config.ini file is present
@@ -75,18 +66,18 @@ def read_config():
7566
)
7667
FIRST_START_VALUE = _configparser.getboolean(SETTINGS_SECTION, FIRT_START_KEY)
7768

69+
check_for_missing_files()
70+
7871
if START_WITH_WINDOWS_VALUE:
7972
registry.add_to_autostart()
8073
else:
8174
registry.remove_from_autostart()
8275

8376
if FIRST_START_VALUE:
84-
setup_gui.init_mmt_selection_frame()
77+
ui.init_mmt_selection_frame()
8578
FIRST_START_VALUE = False
8679
set_config_value(SETTINGS_SECTION, FIRT_START_KEY, FIRST_START_VALUE)
8780

88-
check_for_missing_files()
89-
9081

9182
def _create_default_config_file():
9283
_configparser["Settings"] = {

smct_pkg/notification.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
import threading
1+
from tkinter import messagebox
22

3-
from win10toast import ToastNotifier
43

5-
6-
# TODO: add Logic
74
def send_error(text):
8-
toaster = ToastNotifier()
9-
toaster.show_toast("Error", text, duration=7)
10-
11-
12-
def send_notification(text, duration):
13-
def show_notification():
14-
toaster = ToastNotifier()
15-
toaster.show_toast("It's your first startup!", text, duration=duration)
16-
17-
notification_thread = threading.Thread(target=show_notification)
18-
notification_thread.start()
5+
messagebox.showerror("Error", text)

smct_pkg/paths.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ def strip_package_name_from_path(path):
3232
MMT_CONFIG_PATH = TEMP_DIR_PATH + r"\MultiMonitorToolConfig"
3333
ASSETS_ICON_ENABLED_PATH = ASSETS_DIR_PATH + r"\iconEnabled.png"
3434
ASSETS_ICON_DISABLED_PATH = ASSETS_DIR_PATH + r"\iconDisabled.png"
35+
ASSETS_ICO_PATH = ASSETS_DIR_PATH + r"\icon.ico"

smct_pkg/tray.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
ICON = None
1010

11-
icon_enabled_image = Image.open(paths.ASSETS_ICON_ENABLED_PATH)
12-
icon_disabled_image = Image.open(paths.ASSETS_ICON_DISABLED_PATH)
11+
ICON_ENABLED_IMAGE = None
12+
ICON_DISABLED_IMAGE = None
1313

1414

1515
def save_mmt_config_clicked():
@@ -19,10 +19,10 @@ def save_mmt_config_clicked():
1919
def icon_tray_clicked():
2020
if multimonitortool.is_monitor_enabled():
2121
multimonitortool.disable_monitor()
22-
ICON.icon = icon_disabled_image
22+
ICON.icon = ICON_DISABLED_IMAGE
2323
else:
2424
multimonitortool.enable_monitor()
25-
ICON.icon = icon_enabled_image
25+
ICON.icon = ICON_ENABLED_IMAGE
2626

2727

2828
def exit_clicked():
@@ -64,6 +64,11 @@ def startup_with_windows_clicked(icon):
6464

6565

6666
def init_tray():
67+
# pylint: disable=global-statement
68+
global ICON_ENABLED_IMAGE, ICON_DISABLED_IMAGE
69+
ICON_ENABLED_IMAGE = Image.open(paths.ASSETS_ICON_ENABLED_PATH)
70+
ICON_DISABLED_IMAGE = Image.open(paths.ASSETS_ICON_DISABLED_PATH)
71+
6772
menu = (
6873
item(ui_strings.APP_NAME, icon_tray_clicked, default=True, visible=False),
6974
item(
@@ -84,11 +89,10 @@ def init_tray():
8489
first_image_icon = None
8590

8691
if multimonitortool.is_monitor_enabled():
87-
first_image_icon = icon_enabled_image
88-
if not os.path.exists(paths.MMT_CONFIG_PATH):
89-
multimonitortool.save_mmt_config()
92+
first_image_icon = ICON_ENABLED_IMAGE
93+
multimonitortool.save_mmt_config()
9094
else:
91-
first_image_icon = icon_disabled_image
95+
first_image_icon = ICON_DISABLED_IMAGE
9296

9397
# pylint: disable=global-statement
9498
global ICON

smct_pkg/setup_gui.py renamed to smct_pkg/ui.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import sys
2+
import os
3+
import shutil
24
import tkinter
35
import customtkinter
46
from customtkinter import filedialog
5-
6-
7-
from smct_pkg import ui_strings, config, multimonitortool
8-
9-
# https://github.com/TomSchimansky/CustomTkinter/tree/master/examples
10-
# https://github.com/TomSchimansky/CustomTkinter
7+
from smct_pkg import ui_strings, config, multimonitortool, paths
118

129
customtkinter.set_ctk_parent_class(tkinter.Tk)
1310

@@ -18,14 +15,19 @@
1815

1916
_root_window = customtkinter.CTk()
2017

21-
_root_window.title(ui_strings.APP_NAME)
18+
_root_window.title(ui_strings.SHORT_NAME)
2219
_root_window.resizable(False, False)
2320

21+
_root_window.geometry()
22+
2423
_select_mmt_exe_frame = customtkinter.CTkFrame(master=_root_window)
2524
_select_monitor_frame = customtkinter.CTkFrame(master=_root_window)
2625

2726

2827
def exit_application():
28+
# clean up files if setup was interrupted
29+
shutil.rmtree(paths.TEMP_DIR_PATH)
30+
os.remove(paths.CONFIG_PATH)
2931
_root_window.destroy()
3032
sys.exit(1)
3133

@@ -34,7 +36,8 @@ def exit_application():
3436

3537

3638
def init_mmt_selection_frame():
37-
_root_window.geometry("300x110")
39+
_root_window.iconbitmap(paths.ASSETS_ICO_PATH)
40+
# _root_window.geometry("300x110")
3841
_select_mmt_exe_frame.pack(pady=10, padx=10, fill="both", expand=True)
3942

4043
select_mmt_label = customtkinter.CTkLabel(
@@ -59,9 +62,6 @@ def _browse_button_callback():
5962
title=ui_strings.SELECT_MMT_LABEL,
6063
filetypes=[("MultiMonitorTool", "multimonitortool.exe")],
6164
)
62-
# TODO: if using auto-py-to-exe this returns the wrong path? -> crashes
63-
# C:/App_Install/multimonitortool-x64/MultiMonitorTool.exe should the output be
64-
# but its C:\\App_Install\\ etc. fix this.
6565
if not _exe_path:
6666
print(ui_strings.NO_FILE_SELECTED)
6767
else:
@@ -76,7 +76,7 @@ def _browse_button_callback():
7676

7777

7878
def _init_monitor_selection_frame():
79-
_root_window.geometry("300x160")
79+
# _root_window.geometry("300x160")
8080
_select_monitor_frame.pack(pady=10, padx=10, fill="both", expand=True)
8181

8282
_monitor_selection_label = customtkinter.CTkLabel(

smct_pkg/ui_strings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
APP_NAME = "SimpleMonitorControlTray"
2+
SHORT_NAME = "SMCT"
23

34
# UI STRINGS TRAY
4-
FILE_NOT_FOUND = " file not found. Exiting."
5+
FILE_NOT_FOUND = " not found. Exiting."
56

67
STARTUP_WITH_WINDOWS = "Startup with Windows"
78
SAVE_MONITOR_LAYOUT = "Save current monitor layout"
@@ -10,7 +11,7 @@
1011

1112
# GUI STRINGS
1213
SELECT_MMT_LABEL = "Please select your MultiMonitorTool.exe"
13-
SELECT_MONITOR_LABEL = "Select a monitor."
14+
SELECT_MONITOR_LABEL = "Select the monitor that will be turned off."
1415
NO_FILE_SELECTED = "No file selected. Please select multimonitortool.exe"
1516
BROWSE_BUTTON = "Browse..."
1617
OK_BUTTON = "OK"

0 commit comments

Comments
 (0)