From 138135b9e9e871fd46be06cafd6593100be32345 Mon Sep 17 00:00:00 2001 From: SHooZ Date: Tue, 2 May 2017 02:59:24 +0300 Subject: [PATCH] Add ability to change theme --- MANIFEST.in | 4 ++-- toxygen/main.py | 15 ++++++++++----- toxygen/menu.py | 15 +++++++++++---- toxygen/settings.py | 9 ++++++++- toxygen/styles/{style.qss => dark_style.qss} | 0 toxygen/styles/style.qrc | 2 +- 6 files changed, 32 insertions(+), 13 deletions(-) rename toxygen/styles/{style.qss => dark_style.qss} (100%) diff --git a/MANIFEST.in b/MANIFEST.in index 9bf65b8..a4e17a3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -12,9 +12,9 @@ include toxygen/smileys/starwars/*.png include toxygen/smileys/starwars/config.json include toxygen/smileys/ksk/*.png include toxygen/smileys/ksk/config.json -include toxygen/styles/style.qss +include toxygen/styles/*.qss include toxygen/translations/*.qm include toxygen/libs/libtox.dll include toxygen/libs/libsodium.a include toxygen/libs/libtox64.dll -include toxygen/libs/libsodium64.a \ No newline at end of file +include toxygen/libs/libsodium64.a diff --git a/toxygen/main.py b/toxygen/main.py index c9ab9cf..ea858d4 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -59,11 +59,6 @@ class Toxygen: if platform.system() == 'Linux': QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads) - # application color scheme - with open(curr_directory() + '/styles/style.qss') as fl: - dark_style = fl.read() - app.setStyleSheet(dark_style) - encrypt_save = toxes.ToxES() if self.path is not None: @@ -185,6 +180,16 @@ class Toxygen: else: settings.set_active_profile() + # application color scheme + for theme in settings.built_in_themes().keys(): + if settings['theme'] == theme: + try: + with open(curr_directory() + settings.built_in_themes()[theme]) as fl: + style = fl.read() + app.setStyleSheet(style) + except IsADirectoryError: + app.setStyleSheet('') # for default style + lang = Settings.supported_languages()[settings['language']] translator = QtCore.QTranslator() translator.load(curr_directory() + '/translations/' + lang) diff --git a/toxygen/menu.py b/toxygen/menu.py index 1fe22cb..8488578 100644 --- a/toxygen/menu.py +++ b/toxygen/menu.py @@ -581,11 +581,10 @@ class InterfaceSettings(CenteredWidget): self.label.setFont(font) self.themeSelect = QtGui.QComboBox(self) self.themeSelect.setGeometry(QtCore.QRect(30, 40, 120, 30)) - list_of_themes = ['dark'] - self.themeSelect.addItems(list_of_themes) + self.themeSelect.addItems(list(settings.built_in_themes().keys())) theme = settings['theme'] - if theme in list_of_themes: - index = list_of_themes.index(theme) + if theme in settings.built_in_themes().keys(): + index = list(settings.built_in_themes().keys()).index(theme) else: index = 0 self.themeSelect.setCurrentIndex(index) @@ -726,6 +725,14 @@ class InterfaceSettings(CenteredWidget): def closeEvent(self, event): settings = Settings.get_instance() settings['theme'] = str(self.themeSelect.currentText()) + try: + theme = settings['theme'] + app = QtGui.QApplication.instance() + with open(curr_directory() + settings.built_in_themes()[theme]) as fl: + style = fl.read() + app.setStyleSheet(style) + except IsADirectoryError: + app.setStyleSheet('') # for default style settings['smileys'] = self.smileys.isChecked() restart = False if settings['mirror_mode'] != self.mirror_mode.isChecked(): diff --git a/toxygen/settings.py b/toxygen/settings.py index 5fdca64..ca15d3e 100644 --- a/toxygen/settings.py +++ b/toxygen/settings.py @@ -99,7 +99,7 @@ class Settings(dict, Singleton): Default profile settings """ return { - 'theme': 'default', + 'theme': 'dark', 'ipv6_enabled': True, 'udp_enabled': True, 'proxy_type': 0, @@ -152,6 +152,13 @@ class Settings(dict, Singleton): 'Ukrainian': 'uk_UA' } + @staticmethod + def built_in_themes(): + return { + 'dark': '/styles/dark_style.qss', + 'default': '' + } + def upgrade(self): default = Settings.get_default_settings() for key in default: diff --git a/toxygen/styles/style.qss b/toxygen/styles/dark_style.qss similarity index 100% rename from toxygen/styles/style.qss rename to toxygen/styles/dark_style.qss diff --git a/toxygen/styles/style.qrc b/toxygen/styles/style.qrc index ac14bc5..9759a62 100644 --- a/toxygen/styles/style.qrc +++ b/toxygen/styles/style.qrc @@ -41,6 +41,6 @@ rc/radio_unchecked.png - style.qss + dark_style.qss