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,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
include toxygen/libs/libsodium64.a

View File

@ -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)

View File

@ -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():

View File

@ -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:

View File

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