diff --git a/main.py b/main.py index 80b98af..4387538 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ from tkinter import filedialog from tk_tooltip import CreateToolTip import re import os +import platform channel_names = [ "SAY", # 0 @@ -200,13 +201,13 @@ class GUI: self.frm_general_settings.grid(row=6, column=0, columnspan=2, sticky='ew', pady='5') self.frm_general_settings.columnconfigure([0,1,2], weight=1) - self.btn_keep_color = tk.Button(self.frm_general_settings, text="Keep color", command=self.toggle_setting("keep_color"), bg="#ffcccb") - self.btn_keep_channel = tk.Button(self.frm_general_settings, text="Keep channel name", command=self.toggle_setting("keep_channel"), bg="#ffcccb") - self.btn_keep_lang_flag = tk.Button(self.frm_general_settings, text="Keep language flag", command=self.toggle_setting("keep_lang_flag"), bg="#ffcccb") - self.btn_keep_original_part = tk.Button(self.frm_general_settings, text="Keep original text", command=self.toggle_setting("keep_original_part"), bg="#ffcccb") - self.btn_keep_translated_part = tk.Button(self.frm_general_settings, text="Keep translated text", command=self.toggle_setting("keep_translated_part"), bg="#ffcccb") - self.btn_keep_timestamp = tk.Button(self.frm_general_settings, text="Keep timestamp", command=self.toggle_setting("keep_timestamp"), bg="#ffcccb") - self.btn_replace_charname = tk.Button(self.frm_general_settings, text="Replace charname", command=self.toggle_setting("replace_charname"), bg="#ffcccb") + self.btn_keep_color = self.create_toggle_button(self.frm_general_settings, "Keep color", self.toggle_setting("keep_color")) + self.btn_keep_channel = self.create_toggle_button(self.frm_general_settings, "Keep channel name", self.toggle_setting("keep_channel")) + self.btn_keep_lang_flag = self.create_toggle_button(self.frm_general_settings, "Keep language flag", self.toggle_setting("keep_lang_flag")) + self.btn_keep_original_part = self.create_toggle_button(self.frm_general_settings, "Keep original text", self.toggle_setting("keep_original_part")) + self.btn_keep_translated_part = self.create_toggle_button(self.frm_general_settings, "Keep translated text", self.toggle_setting("keep_translated_part")) + self.btn_keep_timestamp = self.create_toggle_button(self.frm_general_settings, "Keep timestamp", self.toggle_setting("keep_timestamp")) + self.btn_replace_charname = self.create_toggle_button(self.frm_general_settings, "Replace charname", self.toggle_setting("replace_charname")) self.btn_keep_color.grid(row=0, column=0, sticky='ew') self.btn_keep_channel.grid(row=0, column=1, sticky='ew') @@ -229,7 +230,7 @@ class GUI: self.frm_btn_channel.columnconfigure([0,1,2,3], weight=1) self.frm_btn_channel.rowconfigure([0,1,2], weight=1) for i,name in enumerate(channel_names): - self.btn_chan_toggle.append(tk.Button(self.frm_btn_channel, text=name, command=self.toggle_channel(i), bg="#ffcccb")) + self.btn_chan_toggle.append(self.create_toggle_button(self.frm_btn_channel, name, self.toggle_channel(i))) self.btn_chan_toggle[i].grid(row=int(i/4), column=i%4, sticky='ew') self.btn_sys_toggle = [] @@ -239,7 +240,7 @@ class GUI: self.frm_btn_sys.columnconfigure([0,1,2,3,4,5,6], weight=1) self.frm_btn_sys.rowconfigure([0,1,2,3,4], weight=1) for i,(name,tooltip) in enumerate(system_info_categories): - self.btn_sys_toggle.append(tk.Button(self.frm_btn_sys, text=name, command=self.toggle_system(i), bg="#ffcccb")) + self.btn_sys_toggle.append(self.create_toggle_button(self.frm_btn_sys, name, self.toggle_system(i))) self.btn_sys_toggle[i].grid(row=int(i/7), column=i%7, sticky='ew') ttp_sys = CreateToolTip(self.btn_sys_toggle[i], tooltip) @@ -256,6 +257,17 @@ class GUI: self.toggle_system(7)() self.toggle_setting("keep_translated_part")() + def create_toggle_button(self, parent, text, command): + btn = None + if platform.system() == "Darwin": + btn = tk.Label(parent, text=text, bg="#ffcccb", relief='raised') + btn.bind("",lambda e:command()) + btn.grid(padx=1, pady=1, ipady=3) + else: + btn = tk.Button(parent, text=text, command=command, bg="#ffcccb") + return btn + + def toggle_setting(self, setting): def tgl_pref(): if getattr(self, setting):