From 6470b9a31ed111e8eba2882d94fd0775472d6435 Mon Sep 17 00:00:00 2001 From: Furtif Date: Tue, 5 Mar 2024 04:57:36 +0100 Subject: [PATCH] use dark mode in user config --- .github/FUNDING.yml | 4 ++-- main.py | 21 ++++++++++++++------- options.py | 4 +++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 234d54a7..c1b575f6 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1,4 @@ # These are supported funding model platforms -custom: "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=cedricpaille%40gmail%2ecom&lc=CY&item_name=codetronic¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted" -github: [Cedric PAILLE] +custom: ["https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=cedricpaille%40gmail%2ecom&lc=CY&item_name=codetronic¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted", "https://github.com/sponsors/Furtif"] +github: [Cedric PAILLE, Furtif] diff --git a/main.py b/main.py index f6b86a1f..fe3c02f9 100644 --- a/main.py +++ b/main.py @@ -1303,7 +1303,7 @@ def __init__(self): darkstylelayout = widgets.QHBoxLayout() self.darklayoutcheck = widgets.QCheckBox() - self.darklayoutcheck.setChecked(False) + self.darklayoutcheck.setChecked(options.dark_mode) self.darklayoutcheck.stateChanged.connect(set_dark_style) darkstylelabel = widgets.QLabel(_("Dark style")) darkstylelayout.addWidget(self.darklayoutcheck) @@ -1351,8 +1351,9 @@ def setIcon(self): def save_config(self): options.configuration["lang"] = options.lang_list[self.langcombo.currentText()] + options.configuration["dark"] = options.dark_mode options.save_config() - exit(0) + app.exit(0) def check_elm(self): currentitem = self.listview.currentItem() @@ -1566,11 +1567,17 @@ def demoMode(self): options.simultation_mode = True app = widgets.QApplication(sys.argv) - stylefile = core.QFile("dtt4all_data/qstyle.qss") - stylefile.open(core.QFile.ReadOnly) - options.dark_mode = False - StyleSheet = bytes(stylefile.readAll()).decode() - app.setStyleSheet(StyleSheet) + try: + f = open("dtt4all_data/config.json", "r", encoding="UTF-8") + configuration = json.loads(f.read()) + f.close() + if configuration["dark"]: + set_dark_style(2) + else: + set_dark_style(0) + except: + set_dark_style(0) + pass fsize = 9 fname = "Segoe UI" diff --git a/options.py b/options.py index c72e2745..677e7b6c 100644 --- a/options.py +++ b/options.py @@ -33,7 +33,8 @@ mode_edit = False safe_commands = ["3E", "14", "21", "22", "17", "19", "10"] configuration = { - "lang": None + "lang": None, + "dark": False } lang_list = { "English": "en_US", @@ -69,6 +70,7 @@ def create_new_config(): # print(i + " code: " + lang_list[i]) # codes += lang_list[i] + " " configuration["lang"] = get_translator_lang() + configuration["dark"] = False # print("\nEdit it only if it not ok for you country language.") # print(f'Edit the `dtt4all_data/config.json`\nConfiguration however you want this to be translated.\nThe self-assigned code is: {lang}') # print(f'Close and edit the configuration for list: \n\t{codes.strip()} \nAnd reopen the application.')