Add ability to change theme

This commit is contained in:
SHooZ 2017-05-02 02:59:24 +03:00
parent 06e8c79b3f
commit 138135b9e9
6 changed files with 32 additions and 13 deletions

View File

@ -12,7 +12,7 @@ include toxygen/smileys/starwars/*.png
include toxygen/smileys/starwars/config.json include toxygen/smileys/starwars/config.json
include toxygen/smileys/ksk/*.png include toxygen/smileys/ksk/*.png
include toxygen/smileys/ksk/config.json include toxygen/smileys/ksk/config.json
include toxygen/styles/style.qss include toxygen/styles/*.qss
include toxygen/translations/*.qm include toxygen/translations/*.qm
include toxygen/libs/libtox.dll include toxygen/libs/libtox.dll
include toxygen/libs/libsodium.a include toxygen/libs/libsodium.a

View File

@ -59,11 +59,6 @@ class Toxygen:
if platform.system() == 'Linux': if platform.system() == 'Linux':
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads) 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() encrypt_save = toxes.ToxES()
if self.path is not None: if self.path is not None:
@ -185,6 +180,16 @@ class Toxygen:
else: else:
settings.set_active_profile() 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']] lang = Settings.supported_languages()[settings['language']]
translator = QtCore.QTranslator() translator = QtCore.QTranslator()
translator.load(curr_directory() + '/translations/' + lang) translator.load(curr_directory() + '/translations/' + lang)

View File

@ -581,11 +581,10 @@ class InterfaceSettings(CenteredWidget):
self.label.setFont(font) self.label.setFont(font)
self.themeSelect = QtGui.QComboBox(self) self.themeSelect = QtGui.QComboBox(self)
self.themeSelect.setGeometry(QtCore.QRect(30, 40, 120, 30)) self.themeSelect.setGeometry(QtCore.QRect(30, 40, 120, 30))
list_of_themes = ['dark'] self.themeSelect.addItems(list(settings.built_in_themes().keys()))
self.themeSelect.addItems(list_of_themes)
theme = settings['theme'] theme = settings['theme']
if theme in list_of_themes: if theme in settings.built_in_themes().keys():
index = list_of_themes.index(theme) index = list(settings.built_in_themes().keys()).index(theme)
else: else:
index = 0 index = 0
self.themeSelect.setCurrentIndex(index) self.themeSelect.setCurrentIndex(index)
@ -726,6 +725,14 @@ class InterfaceSettings(CenteredWidget):
def closeEvent(self, event): def closeEvent(self, event):
settings = Settings.get_instance() settings = Settings.get_instance()
settings['theme'] = str(self.themeSelect.currentText()) 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() settings['smileys'] = self.smileys.isChecked()
restart = False restart = False
if settings['mirror_mode'] != self.mirror_mode.isChecked(): if settings['mirror_mode'] != self.mirror_mode.isChecked():

View File

@ -99,7 +99,7 @@ class Settings(dict, Singleton):
Default profile settings Default profile settings
""" """
return { return {
'theme': 'default', 'theme': 'dark',
'ipv6_enabled': True, 'ipv6_enabled': True,
'udp_enabled': True, 'udp_enabled': True,
'proxy_type': 0, 'proxy_type': 0,
@ -152,6 +152,13 @@ class Settings(dict, Singleton):
'Ukrainian': 'uk_UA' 'Ukrainian': 'uk_UA'
} }
@staticmethod
def built_in_themes():
return {
'dark': '/styles/dark_style.qss',
'default': ''
}
def upgrade(self): def upgrade(self):
default = Settings.get_default_settings() default = Settings.get_default_settings()
for key in default: for key in default:

View File

@ -41,6 +41,6 @@
<file>rc/radio_unchecked.png</file> <file>rc/radio_unchecked.png</file>
</qresource> </qresource>
<qresource prefix="qdarkstyle"> <qresource prefix="qdarkstyle">
<file>style.qss</file> <file>dark_style.qss</file>
</qresource> </qresource>
</RCC> </RCC>