From 14dd46b7162ebdaaa19fee98867cf506b20dad08 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Thu, 18 Feb 2016 19:15:38 +0300 Subject: [PATCH] tests + profile.py --- src/loginscreen.py | 11 +++++++---- src/main.py | 20 ++++++++++++++++++++ src/mainscreen.py | 1 + src/profile.py | 23 +++++++++++++++++++++++ src/settings.py | 37 +++++++++++++++++++------------------ tests/tests.py | 8 ++++++++ 6 files changed, 78 insertions(+), 22 deletions(-) diff --git a/src/loginscreen.py b/src/loginscreen.py index e39522d..c3522bf 100644 --- a/src/loginscreen.py +++ b/src/loginscreen.py @@ -4,7 +4,8 @@ from PySide import QtCore, QtGui import sys import os -class LoginScreen(object): + +class LoginScreen(QtGui.QWidget): def setupUi(self, Form): Form.setObjectName("Form") Form.resize(400, 200) @@ -63,15 +64,17 @@ class LoginScreen(object): self.groupBox_2.setTitle(QtGui.QApplication.translate("Form", "Create new profile", None, QtGui.QApplication.UnicodeUTF8)) self.toxygen.setText(QtGui.QApplication.translate("Form", "toxygen", None, QtGui.QApplication.UnicodeUTF8)) + def update_select(self, data): + list_of_profiles = [] + for elem in data: + list_of_profiles.append(self.tr(elem)) + self.comboBox.addItems(list_of_profiles) if __name__ == '__main__': - app = QtGui.QApplication(sys.argv) - ls = LoginScreen() win = QtGui.QMainWindow() ls.setupUi(win) win.show() - app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) app.exec_() diff --git a/src/main.py b/src/main.py index e69de29..dfa00f5 100644 --- a/src/main.py +++ b/src/main.py @@ -0,0 +1,20 @@ +from loginscreen import LoginScreen +from settings import Settings +import sys +from PySide import QtCore, QtGui + + +if __name__ == '__main__': + app = QtGui.QApplication(sys.argv) + settings = Settings() + if not settings['auto_profile']: + # show login screen if default profile not found + ls = LoginScreen() + win = QtGui.QMainWindow() + ls.setupUi(win) + + ls.update_select(['tox_save']) + win.show() + app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) + app.exec_() + # TODO: get result from loginscreen and open mainscreen diff --git a/src/mainscreen.py b/src/mainscreen.py index d624039..32b4aa5 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -111,6 +111,7 @@ class MainWindow(QtGui.QWidget): def initUI(self): grid = QtGui.QGridLayout() search = QtGui.QWidget() + grid.setColumnStretch(1, 1) self.setup_left_center(search) grid.addWidget(search, 1, 0) name = QtGui.QWidget() diff --git a/src/profile.py b/src/profile.py index e69de29..d7a737b 100644 --- a/src/profile.py +++ b/src/profile.py @@ -0,0 +1,23 @@ +from settings import Settings +import os + + +class Profile(object): + + @staticmethod + def find_profiles(): + path = Settings.get_default_path() + result = [] + # check default path + for fl in os.listdir(path): + if fl.endswith(".tox"): + name = fl[:-4] + result.append((path, name)) + path = os.path.dirname(os.path.abspath(__file__)) + # check current directory + for fl in os.listdir(path): + if fl.endswith(".tox"): + name = fl[:-4] + result.append((path, name)) + return result + diff --git a/src/settings.py b/src/settings.py index 90d8ccc..a10beb1 100644 --- a/src/settings.py +++ b/src/settings.py @@ -18,24 +18,25 @@ class Settings(dict): @staticmethod def get_default_settings(): return { - "theme": "default", - "ipv6_enabled": True, - "udp_enabled": True, - "proxy_type": 0, - "proxy_host": "0", - "proxy_port": 0, - "start_port": 0, - "end_port": 0, - "tcp_port": 0, - "notifications": True, - "sound_notifications": False, - "language": "en-en", - "save_history": False, - "allow_inline": True, - "allow_auto_accept": False, - "auto_accept_from_friends": [], - "friends_aliases": [], - "typing_notifications": True + 'theme': 'default', + 'ipv6_enabled': True, + 'udp_enabled': True, + 'proxy_type': 0, + 'proxy_host': '0', + 'proxy_port': 0, + 'start_port': 0, + 'end_port': 0, + 'tcp_port': 0, + 'notifications': True, + 'sound_notifications': False, + 'language': 'en-en', + 'save_history': False, + 'allow_inline': True, + 'allow_auto_accept': False, + 'auto_accept_from_friends': [], + 'friends_aliases': [], + 'typing_notifications': True, + 'auto_profile': '' } def save(self): diff --git a/tests/tests.py b/tests/tests.py index 7e8d628..42a1f7f 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,6 +1,7 @@ from src.settings import Settings from src.tox import Tox import sys +from src.profile import Profile import os @@ -34,3 +35,10 @@ class TestTox(): assert tox.get_savedata_size() except: assert 0 + + +class TestProfile(): + + def test_search(self): + arr = Profile.find_profiles() + assert arr