Skip to content

Commit

Permalink
finished adding UI + bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wrecks-code committed Apr 17, 2024
1 parent 72efcf4 commit 1ac5801
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 105 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,5 @@ cython_debug/

output/
.vscode/
temp/
config.ini
File renamed without changes.
7 changes: 0 additions & 7 deletions config.ini

This file was deleted.

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ win10toast
pystray
pandas
customtkinter
python-tkdnd
CTkMessagebox
23 changes: 7 additions & 16 deletions smct_pkg/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import configparser
import os
import sys

from smct_pkg import (
multimonitortool,
notification,
paths,
registry,
setup_gui,
ui,
ui_strings,
)

Expand All @@ -31,31 +31,22 @@


def check_for_missing_files():
# Check for assets folder
if not os.path.exists(paths.ASSETS_DIR_PATH):
os.makedirs(paths.ASSETS_DIR_PATH)
# Check for Icons
if not os.path.exists(paths.ASSETS_ICON_ENABLED_PATH):
notification.send_error(
paths.ASSETS_ICON_ENABLED_PATH + ui_strings.FILE_NOT_FOUND
)
sys.exit(1)
if not os.path.exists(paths.ASSETS_ICON_DISABLED_PATH):
notification.send_error(
paths.ASSETS_ICON_DISABLED_PATH + ui_strings.FILE_NOT_FOUND
)

# Check for MultiMonitorTool
if not os.path.exists(MMT_PATH_VALUE):
notification.send_error(MMT_PATH_VALUE + ui_strings.FILE_NOT_FOUND)
sys.exit(1)

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

# Check for MultiMonitorTool CSV
if not os.path.exists(paths.MMT_CSV_PATH):
multimonitortool.save_mmt_config()


def read_config():
# Check if config.ini file is present
Expand All @@ -75,18 +66,18 @@ def read_config():
)
FIRST_START_VALUE = _configparser.getboolean(SETTINGS_SECTION, FIRT_START_KEY)

check_for_missing_files()

if START_WITH_WINDOWS_VALUE:
registry.add_to_autostart()
else:
registry.remove_from_autostart()

if FIRST_START_VALUE:
setup_gui.init_mmt_selection_frame()
ui.init_mmt_selection_frame()
FIRST_START_VALUE = False
set_config_value(SETTINGS_SECTION, FIRT_START_KEY, FIRST_START_VALUE)

check_for_missing_files()


def _create_default_config_file():
_configparser["Settings"] = {
Expand Down
17 changes: 2 additions & 15 deletions smct_pkg/notification.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import threading
from tkinter import messagebox

from win10toast import ToastNotifier


# TODO: add Logic
def send_error(text):
toaster = ToastNotifier()
toaster.show_toast("Error", text, duration=7)


def send_notification(text, duration):
def show_notification():
toaster = ToastNotifier()
toaster.show_toast("It's your first startup!", text, duration=duration)

notification_thread = threading.Thread(target=show_notification)
notification_thread.start()
messagebox.showerror("Error", text)
1 change: 1 addition & 0 deletions smct_pkg/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ def strip_package_name_from_path(path):
MMT_CONFIG_PATH = TEMP_DIR_PATH + r"\MultiMonitorToolConfig"
ASSETS_ICON_ENABLED_PATH = ASSETS_DIR_PATH + r"\iconEnabled.png"
ASSETS_ICON_DISABLED_PATH = ASSETS_DIR_PATH + r"\iconDisabled.png"
ASSETS_ICO_PATH = ASSETS_DIR_PATH + r"\icon.ico"
20 changes: 12 additions & 8 deletions smct_pkg/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

ICON = None

icon_enabled_image = Image.open(paths.ASSETS_ICON_ENABLED_PATH)
icon_disabled_image = Image.open(paths.ASSETS_ICON_DISABLED_PATH)
ICON_ENABLED_IMAGE = None
ICON_DISABLED_IMAGE = None


def save_mmt_config_clicked():
Expand All @@ -19,10 +19,10 @@ def save_mmt_config_clicked():
def icon_tray_clicked():
if multimonitortool.is_monitor_enabled():
multimonitortool.disable_monitor()
ICON.icon = icon_disabled_image
ICON.icon = ICON_DISABLED_IMAGE
else:
multimonitortool.enable_monitor()
ICON.icon = icon_enabled_image
ICON.icon = ICON_ENABLED_IMAGE


def exit_clicked():
Expand Down Expand Up @@ -64,6 +64,11 @@ def startup_with_windows_clicked(icon):


def init_tray():
# pylint: disable=global-statement
global ICON_ENABLED_IMAGE, ICON_DISABLED_IMAGE
ICON_ENABLED_IMAGE = Image.open(paths.ASSETS_ICON_ENABLED_PATH)
ICON_DISABLED_IMAGE = Image.open(paths.ASSETS_ICON_DISABLED_PATH)

menu = (
item(ui_strings.APP_NAME, icon_tray_clicked, default=True, visible=False),
item(
Expand All @@ -84,11 +89,10 @@ def init_tray():
first_image_icon = None

if multimonitortool.is_monitor_enabled():
first_image_icon = icon_enabled_image
if not os.path.exists(paths.MMT_CONFIG_PATH):
multimonitortool.save_mmt_config()
first_image_icon = ICON_ENABLED_IMAGE
multimonitortool.save_mmt_config()
else:
first_image_icon = icon_disabled_image
first_image_icon = ICON_DISABLED_IMAGE

# pylint: disable=global-statement
global ICON
Expand Down
24 changes: 12 additions & 12 deletions smct_pkg/setup_gui.py → smct_pkg/ui.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import sys
import os
import shutil
import tkinter
import customtkinter
from customtkinter import filedialog


from smct_pkg import ui_strings, config, multimonitortool

# https://github.com/TomSchimansky/CustomTkinter/tree/master/examples
# https://github.com/TomSchimansky/CustomTkinter
from smct_pkg import ui_strings, config, multimonitortool, paths

customtkinter.set_ctk_parent_class(tkinter.Tk)

Expand All @@ -18,14 +15,19 @@

_root_window = customtkinter.CTk()

_root_window.title(ui_strings.APP_NAME)
_root_window.title(ui_strings.SHORT_NAME)
_root_window.resizable(False, False)

_root_window.geometry()

_select_mmt_exe_frame = customtkinter.CTkFrame(master=_root_window)
_select_monitor_frame = customtkinter.CTkFrame(master=_root_window)


def exit_application():
# clean up files if setup was interrupted
shutil.rmtree(paths.TEMP_DIR_PATH)
os.remove(paths.CONFIG_PATH)
_root_window.destroy()
sys.exit(1)

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


def init_mmt_selection_frame():
_root_window.geometry("300x110")
_root_window.iconbitmap(paths.ASSETS_ICO_PATH)
# _root_window.geometry("300x110")
_select_mmt_exe_frame.pack(pady=10, padx=10, fill="both", expand=True)

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


def _init_monitor_selection_frame():
_root_window.geometry("300x160")
# _root_window.geometry("300x160")
_select_monitor_frame.pack(pady=10, padx=10, fill="both", expand=True)

_monitor_selection_label = customtkinter.CTkLabel(
Expand Down
5 changes: 3 additions & 2 deletions smct_pkg/ui_strings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
APP_NAME = "SimpleMonitorControlTray"
SHORT_NAME = "SMCT"

# UI STRINGS TRAY
FILE_NOT_FOUND = " file not found. Exiting."
FILE_NOT_FOUND = " not found. Exiting."

STARTUP_WITH_WINDOWS = "Startup with Windows"
SAVE_MONITOR_LAYOUT = "Save current monitor layout"
Expand All @@ -10,7 +11,7 @@

# GUI STRINGS
SELECT_MMT_LABEL = "Please select your MultiMonitorTool.exe"
SELECT_MONITOR_LABEL = "Select a monitor."
SELECT_MONITOR_LABEL = "Select the monitor that will be turned off."
NO_FILE_SELECTED = "No file selected. Please select multimonitortool.exe"
BROWSE_BUTTON = "Browse..."
OK_BUTTON = "OK"
36 changes: 0 additions & 36 deletions temp/MultiMonitorToolConfig

This file was deleted.

4 changes: 0 additions & 4 deletions temp/MultiMonitorToolOutput.csv

This file was deleted.

4 changes: 0 additions & 4 deletions temp/sampleoutput.csv

This file was deleted.

0 comments on commit 1ac5801

Please sign in to comment.