From 635feb353229f6e94f7808789e79b97e5974dd18 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 3 Mar 2016 19:44:01 +0300 Subject: [PATCH] fixed bug with settings. interface and privacy settings added --- src/main.py | 3 ++- src/menu.py | 25 ++++++++++++++++++++++++- src/settings.py | 2 +- src/util.py | 12 ++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index 935c1b6..43a2189 100644 --- a/src/main.py +++ b/src/main.py @@ -6,7 +6,7 @@ import sys from PySide import QtCore, QtGui from callbacks import init_callbacks from bootstrap import node_generator -from util import curr_directory +from util import curr_directory, get_style class login(object): @@ -73,6 +73,7 @@ def main(): ms = MainWindow(tox) ms.show() + QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style # bootstrap for data in node_generator(): tox.bootstrap(*data) diff --git a/src/menu.py b/src/menu.py index 57dec9a..a99563e 100644 --- a/src/menu.py +++ b/src/menu.py @@ -1,6 +1,7 @@ from PySide import QtCore, QtGui from settings import Settings from profile import Profile +from util import get_style class AddContact(QtGui.QWidget): @@ -214,6 +215,10 @@ class PrivacySettings(QtGui.QWidget): self.typingNotifications.setObjectName("typingNotifications") self.retranslateUi() + settings = Settings() + self.typingNotifications.setChecked(settings['typing_notifications']) + self.fileautoaccept.setChecked(settings['allow_auto_accept']) + self.saveHistory.setChecked(settings['save_history']) QtCore.QMetaObject.connectSlotsByName(self) def retranslateUi(self): @@ -222,6 +227,13 @@ class PrivacySettings(QtGui.QWidget): self.fileautoaccept.setText(QtGui.QApplication.translate("privacySettings", "Allow file autoaccept", None, QtGui.QApplication.UnicodeUTF8)) self.typingNotifications.setText(QtGui.QApplication.translate("privacySettings", "Send typing notifications", None, QtGui.QApplication.UnicodeUTF8)) + def closeEvent(self, event): + settings = Settings() + settings['typing_notifications'] = self.typingNotifications.isChecked() + settings['allow_auto_accept'] = self.fileautoaccept.isChecked() + settings['save_history'] = self.saveHistory.isChecked() + settings.save() + class NotificationsSettings(QtGui.QWidget): """Notifications settings form""" @@ -293,10 +305,21 @@ class InterfaceSettings(QtGui.QWidget): font.setPointSize(17) self.themeSelect.setFont(font) self.themeSelect.setObjectName("themeSelect") - + list_of_themes = ['default', 'windows', 'gtk', 'cde', 'plastique', 'motif'] + self.themeSelect.addItems(list_of_themes) + theme = Settings()['theme'] + index = list_of_themes.index(theme) + self.themeSelect.setCurrentIndex(index) self.retranslateUi() QtCore.QMetaObject.connectSlotsByName(self) def retranslateUi(self): self.setWindowTitle(QtGui.QApplication.translate("interfaceForm", "Interface settings", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("interfaceForm", "Theme:", None, QtGui.QApplication.UnicodeUTF8)) + + def closeEvent(self, event): + settings = Settings() + style = str(self.themeSelect.currentText()) + settings['theme'] = style + settings.save() + QtGui.QApplication.setStyle(get_style(style)) diff --git a/src/settings.py b/src/settings.py index 5be6ac9..61c8ba9 100644 --- a/src/settings.py +++ b/src/settings.py @@ -4,7 +4,7 @@ import os from util import Singleton -class Settings(dict, Singleton): +class Settings(Singleton, dict): def __init__(self, name=''): self.path = Settings.get_default_path() + str(name) + '.json' diff --git a/src/util.py b/src/util.py index 54d3364..0504f56 100644 --- a/src/util.py +++ b/src/util.py @@ -1,5 +1,7 @@ import os import time +from platform import system + program_version = '0.0.1 (alpha)' @@ -17,6 +19,16 @@ def curr_time(): return time.strftime("%H:%M") +def get_style(style): + if style != 'default': + return style + else: + if system() == 'Linux': + return 'gtk' + elif system() == 'Windows': + return 'windows' + + class Singleton(object): def __new__(cls, *args):