Skip to content

Commit

Permalink
chore: Update .gitignore and theme selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
LyubomirT committed Jul 27, 2024
1 parent 43e0d04 commit c8643ab
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Virtual/
output/
dist/
dist.zip
language.txt
language.txt
theme.txt
10 changes: 10 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ def toggleTheme(self):
else:
self.setStyleSheet(open("darkmode.css").read())

self.save_theme_based_on_last_choice()

def save_theme_based_on_last_choice(self):
if self.lightModeCheckBox.isChecked():
with open("theme.txt", "w", encoding="utf-8") as f:
f.write("light")
else:
with open("theme.txt", "w", encoding="utf-8") as f:
f.write("dark")

if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyleSheet(open("style.css").read())
Expand Down
14 changes: 14 additions & 0 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ def setupUi(self, MainWindow):

self.update_ui_text()

self.load_theme_based_on_last_choice()

# set the current language of the dropdown to the saved language
self.languageComboBox.setCurrentText(self.current_language)

Expand All @@ -117,6 +119,18 @@ def load_translations(self):
with open(os.path.join(translations_dir, filename), "r", encoding="utf-8") as f:
self.translations[language_code] = json.load(f)
self.languageComboBox.addItem(language_code)

def load_theme_based_on_last_choice(self):
if not os.path.exists("theme.txt"):
return
with open("theme.txt", "r", encoding="utf-8") as f:
theme = f.read()
if theme == "dark":
self.lightModeCheckBox.setChecked(False)
self.toggleTheme()
if theme == "light":
self.lightModeCheckBox.setChecked(True)
self.toggleTheme()

def change_language(self):
self.current_language = self.languageComboBox.currentText()
Expand Down

0 comments on commit c8643ab

Please sign in to comment.