From 54093ab513938c1ed5d42549912523d3dbe88e40 Mon Sep 17 00:00:00 2001 From: Tom Schimansky Date: Mon, 25 Oct 2021 11:19:15 +0200 Subject: [PATCH] add settings in menu bar --- assets/user_settings/user_settings.json | 2 +- main.py | 4 +- tuner_appearance_manager/color_manager.py | 11 ----- tuner_ui_parts/settings_frame.py | 58 ++++++----------------- tuner_ui_parts/tkinter_custom_button.py | 8 ++-- 5 files changed, 23 insertions(+), 60 deletions(-) diff --git a/assets/user_settings/user_settings.json b/assets/user_settings/user_settings.json index 2af4534..4a464f2 100644 --- a/assets/user_settings/user_settings.json +++ b/assets/user_settings/user_settings.json @@ -1 +1 @@ -{"check_for_updates": true, "bell_muted": true, "agreed_on_usage_stats": false, "open_times": 0, "id": null} \ No newline at end of file +{"check_for_updates": true, "bell_muted": true, "agreed_on_usage_stats": true, "open_times": 0, "id": null} \ No newline at end of file diff --git a/main.py b/main.py index ae4decb..9fa3cb6 100755 --- a/main.py +++ b/main.py @@ -82,6 +82,7 @@ def __init__(self, *args, **kwargs): self.bind("", self.on_closing) self.bind("", self.on_closing) self.createcommand('tk::mac::Quit', self.on_closing) + self.createcommand('tk::mac::ShowPreferences', self.draw_settings_frame) menu_bar = tkinter.Menu(master=self) app_menu = tkinter.Menu(menu_bar, name='apple') @@ -116,7 +117,6 @@ def draw_main_frame(self, event=0): self.main_frame.place(relx=0, rely=0, relheight=1, relwidth=1) def manage_usage_stats(self, option, open_times, id): - # check usage_monitor module could be loaded if usage_monitor is not None: @@ -140,8 +140,10 @@ def manage_usage_stats(self, option, open_times, id): self.on_closing() def check_for_updates(self): + # check if user agreed on update checking if self.read_user_setting("check_for_updates") is True: try: + # use github API to get latest version string response = requests.get(Settings.GITHUB_API_URL + "/releases/latest") latest_version = response.json()["tag_name"] except Exception as err: diff --git a/tuner_appearance_manager/color_manager.py b/tuner_appearance_manager/color_manager.py index 1a055aa..8bb5ac6 100644 --- a/tuner_appearance_manager/color_manager.py +++ b/tuner_appearance_manager/color_manager.py @@ -4,17 +4,6 @@ class ColorManager(object): def __init__(self): - self.background_layer_1 = None - self.background_layer_0 = None - self.text_main = None - self.text_2 = None - self.text_2_highlight = None - self.theme_main = None - self.theme_dark = None - self.theme_light = None - self.needle = None - self.needle_hit = None - self.set_mode("Light") def set_mode(self, mode): diff --git a/tuner_ui_parts/settings_frame.py b/tuner_ui_parts/settings_frame.py index 13d1696..63f49c0 100644 --- a/tuner_ui_parts/settings_frame.py +++ b/tuner_ui_parts/settings_frame.py @@ -19,11 +19,7 @@ def __init__(self, master, *args, **kwargs): self.bottom_frame = tkinter.Frame(master=self, bg=self.color_manager.background_layer_0) - self.bottom_frame.place(anchor=tkinter.S, - relx=0.5, - rely=1, - relheight=0.2, - relwidth=1) + self.bottom_frame.place(anchor=tkinter.S, relx=0.5, rely=1, relheight=0.2, relwidth=1) self.button_back = TkinterCustomButton(master=self.bottom_frame, bg_color=self.color_manager.background_layer_0, @@ -36,10 +32,7 @@ def __init__(self, master, *args, **kwargs): width=110, height=40, command=self.master.draw_main_frame) - - self.button_back.place(anchor=tkinter.SE, - relx=0.95, - rely=0.75) + self.button_back.place(anchor=tkinter.SE, relx=0.95, rely=0.75) self.button_website = TkinterCustomButton(master=self.bottom_frame, bg_color=self.color_manager.background_layer_0, @@ -52,34 +45,21 @@ def __init__(self, master, *args, **kwargs): width=110, height=40, command=self.website_button) - - self.button_website.place(anchor=tkinter.SW, - relx=0.05, - rely=0.75) + self.button_website.place(anchor=tkinter.SW, relx=0.05, rely=0.75) self.label_info_text = tkinter.Label(master=self, bg=self.color_manager.background_layer_1, fg=self.color_manager.text_2, font=self.font_manager.info_text_font, text=Settings.ABOUT_TEXT) - - self.label_info_text.place(anchor=tkinter.CENTER, - relx=0.5, - rely=0.12, - relheight=0.2, - relwidth=0.8) + self.label_info_text.place(anchor=tkinter.CENTER, relx=0.5, rely=0.12, relheight=0.2, relwidth=0.8) self.label_note_text = tkinter.Label(master=self, bg=self.color_manager.background_layer_1, fg=self.color_manager.text_2, font=self.font_manager.settings_text_font, text="A4 =") - - self.label_note_text.place(relx=0.2, - rely=0.45, - relheight=0.1, - relwidth=0.2, - anchor=tkinter.CENTER) + self.label_note_text.place(relx=0.2, rely=0.45, relheight=0.1, relwidth=0.2, anchor=tkinter.CENTER) self.label_frequency = TkinterCustomButton(master=self, bg_color=self.color_manager.background_layer_1, @@ -92,38 +72,29 @@ def __init__(self, master, *args, **kwargs): width=170, height=65, hover=False) - - self.label_frequency.place(anchor=tkinter.CENTER, - relx=0.5, - rely=0.45) + self.label_frequency.place(anchor=tkinter.CENTER, relx=0.5, rely=0.45) self.button_frequency_up = TkinterCustomButtonImageset(master=self, + height=50, + width=150, bg_color=self.color_manager.background_layer_1, image_dict={"standard": self.image_manager.arrowUp_image, "clicked": self.image_manager.arrowUp_image, "standard_hover": self.image_manager.arrowUp_image_hovered, "clicked_hover": self.image_manager.arrowUp_image_hovered}, command=self.frequency_button_up) - - self.button_frequency_up.place(anchor=tkinter.CENTER, - relx=0.5, - rely=0.3, - height=50, - width=150) + self.button_frequency_up.place(anchor=tkinter.CENTER, relx=0.5, rely=0.3) self.button_frequency_down = TkinterCustomButtonImageset(master=self, + height=50, + width=150, bg_color=self.color_manager.background_layer_1, image_dict={"standard": self.image_manager.arrowDown_image, "clicked": self.image_manager.arrowDown_image, "standard_hover": self.image_manager.arrowDown_image_hovered, "clicked_hover": self.image_manager.arrowDown_image_hovered}, command=self.frequency_button_down) - - self.button_frequency_down.place(anchor=tkinter.CENTER, - relx=0.5, - rely=0.6, - height=50, - width=150) + self.button_frequency_down.place(anchor=tkinter.CENTER, relx=0.5, rely=0.6) def update_color(self): self.configure(bg=self.color_manager.background_layer_1) @@ -155,8 +126,9 @@ def frequency_button_up(self): self.label_frequency.set_text(str(self.master.a4_frequency) + " Hz") def frequency_button_down(self): - self.master.a4_frequency -= 1 - self.label_frequency.set_text(str(self.master.a4_frequency) + " Hz") + if self.master.a4_frequency > 1: + self.master.a4_frequency -= 1 + self.label_frequency.set_text(str(self.master.a4_frequency) + " Hz") def website_button(self): webbrowser.open(Settings.GITHUB_URL_README) diff --git a/tuner_ui_parts/tkinter_custom_button.py b/tuner_ui_parts/tkinter_custom_button.py index 2c2f1dc..577c323 100644 --- a/tuner_ui_parts/tkinter_custom_button.py +++ b/tuner_ui_parts/tkinter_custom_button.py @@ -51,10 +51,10 @@ def __init__(self, self.width = width self.height = height - if corner_radius*2 > self.height: - self.corner_radius = self.height/2 - elif corner_radius*2 > self.width: - self.corner_radius = self.width/2 + if corner_radius * 2 > self.height: + self.corner_radius = self.height / 2 + elif corner_radius * 2 > self.width: + self.corner_radius = self.width / 2 else: self.corner_radius = corner_radius