From d8b06efd7c38cd27f9409b974068c0e7e2f39a0a Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Fri, 19 Feb 2016 13:41:54 +0300 Subject: [PATCH] ui update. communication between login screen and main app added --- src/images/icon.png | Bin 0 -> 2595 bytes src/loginscreen.py | 88 +++++++++++++++++++++++++++++++------------- src/main.py | 53 ++++++++++++++++++++++---- 3 files changed, 108 insertions(+), 33 deletions(-) create mode 100644 src/images/icon.png diff --git a/src/images/icon.png b/src/images/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a790ae173b3c955d4af625081c4aada886478861 GIT binary patch literal 2595 zcmX|Dc{tQ-8-9OdCNl;xob3Bh6HzKl_N`{J?~)ixb!^RK8$y0eLNZ38s8F&CC84B= zLZ=cXWu1{6Bn)+!uhH?1?~m`juIIh4=f3afpZB_+`+BonoQ{Zz$cq2~#7IP2Hvz(1 zh2AE(yUhb%3ji5yP4YksP7*pKQ_y3m#ADF_Z2P`dkaDciK>;ZjW9Jj&PB|4r3yeAm zXf&E`=$Y{7;6Un0T}ssH8%w70g26J9t(8ao=;Eyes-w4JZ_TgrMUPLLhd#u4;4^)! z)p29lpNp$?^d#;5vwVFeH4D{W6b4yKs-ZnKE}^FicG%RH4|~bwR1A|o?D7rDA^zgO z?J!(Eh+pl0Iy)Y{%>TVo^lI;q$>dpn`+7;@lJPV5x;uC76uPeP`pOLkq-CLcC=RNE z)yqVyn^IF`gsM^}SiWTG0Y!`MzQ~Xl0~W}OkOHjWq}CjT?L&2fZ~0(#8yn}d-PBX< zXD#d9B$6j!kQ78*l<3plYlsOFSWKe;#rLYbzixsK61YEg9L8a~T7Lk(5*}=F*iHWo zXyZ|QVM;#OIFxWrQ=Hv@kd=#cF-&siREi6Xx&FUU=g^yGoLWX#t2;W$60r-r={Pp$ zm+nLWlbX=yt`w9}*)(@i5%Sl7{A5&fY-DHl6u0p9?^WeGT){pLO2JD9uc9o%3{caUo~z>y5C^ z@?es8VqBWJCfbqT*Q^#(Mmm%E)M1V`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VMI3`%t_4Nr$Xi*iUsq-ZaJKiXQKs4sykq z(0gRS!djmyNb}afS?>K%uZ@|dQJ;q**{N=Bsy9wuK*F;6NIotloFF7 z5v8d+V?7C@$M2_(7&P4ImvMM3^rLxQXtr^L=YETrlZa8e(F yMiFf_h~f9fV$wp+gadY_k0xe&g(kyJt*MA|OVG5r^&Nr_9U$2`*)~{{)BXztB7!pj literal 0 HcmV?d00001 diff --git a/src/loginscreen.py b/src/loginscreen.py index c3522bf..d20deb8 100644 --- a/src/loginscreen.py +++ b/src/loginscreen.py @@ -6,37 +6,44 @@ import os class LoginScreen(QtGui.QWidget): - def setupUi(self, Form): - Form.setObjectName("Form") - Form.resize(400, 200) - Form.setMinimumSize(QtCore.QSize(400, 200)) - Form.setMaximumSize(QtCore.QSize(400, 200)) - Form.setBaseSize(QtCore.QSize(400, 200)) - self.new_profile = QtGui.QPushButton(Form) + + def __init__(self): + super(LoginScreen, self).__init__() + self.initUI() + + def initUI(self): + self.setObjectName("login") + self.resize(400, 200) + self.setMinimumSize(QtCore.QSize(400, 200)) + self.setMaximumSize(QtCore.QSize(400, 200)) + self.setBaseSize(QtCore.QSize(400, 200)) + self.new_profile = QtGui.QPushButton(self) self.new_profile.setGeometry(QtCore.QRect(20, 150, 171, 27)) self.new_profile.setObjectName("new_profile") - self.label = QtGui.QLabel(Form) + self.new_profile.clicked.connect(self.create_profile) + self.label = QtGui.QLabel(self) self.label.setGeometry(QtCore.QRect(20, 70, 101, 17)) self.label.setObjectName("label") - self.new_name = QtGui.QPlainTextEdit(Form) + self.new_name = QtGui.QPlainTextEdit(self) self.new_name.setGeometry(QtCore.QRect(20, 100, 171, 31)) self.new_name.setObjectName("new_name") - self.load_profile = QtGui.QPushButton(Form) + self.load_profile = QtGui.QPushButton(self) self.load_profile.setGeometry(QtCore.QRect(220, 150, 161, 27)) self.load_profile.setObjectName("load_profile") - self.default = QtGui.QCheckBox(Form) + self.load_profile.clicked.connect(self.load_ex_profile) + self.default = QtGui.QCheckBox(self) self.default.setGeometry(QtCore.QRect(220, 110, 131, 22)) self.default.setObjectName("default") - self.groupBox = QtGui.QGroupBox(Form) + self.groupBox = QtGui.QGroupBox(self) self.groupBox.setGeometry(QtCore.QRect(210, 40, 181, 151)) self.groupBox.setObjectName("groupBox") self.comboBox = QtGui.QComboBox(self.groupBox) self.comboBox.setGeometry(QtCore.QRect(10, 30, 161, 27)) self.comboBox.setObjectName("comboBox") - self.groupBox_2 = QtGui.QGroupBox(Form) + self.groupBox_2 = QtGui.QGroupBox(self) self.groupBox_2.setGeometry(QtCore.QRect(10, 40, 191, 151)) self.groupBox_2.setObjectName("groupBox_2") - self.toxygen = QtGui.QLabel(Form) + self.toxygen = QtGui.QLabel(self) self.groupBox.raise_() self.groupBox_2.raise_() self.comboBox.raise_() @@ -50,25 +57,56 @@ class LoginScreen(QtGui.QWidget): font.setPointSize(16) self.toxygen.setFont(font) self.toxygen.setObjectName("toxygen") + self.type = 0 + self.number = -1 + self.load_as_default = False + self.name = None + self.retranslateUi() + QtCore.QMetaObject.connectSlotsByName(self) + self.center() - self.retranslateUi(Form) - QtCore.QMetaObject.connectSlotsByName(Form) + def center(self): + qr = self.frameGeometry() + cp = QtGui.QDesktopWidget().availableGeometry().center() + qr.moveCenter(cp) + self.move(qr.topLeft()) - def retranslateUi(self, Form): - Form.setWindowTitle(QtGui.QApplication.translate("Form", "Log in", None, QtGui.QApplication.UnicodeUTF8)) - self.new_profile.setText(QtGui.QApplication.translate("Form", "Create", None, QtGui.QApplication.UnicodeUTF8)) - self.label.setText(QtGui.QApplication.translate("Form", "Profile name:", None, QtGui.QApplication.UnicodeUTF8)) - self.load_profile.setText(QtGui.QApplication.translate("Form", "Load profile", None, QtGui.QApplication.UnicodeUTF8)) - self.default.setText(QtGui.QApplication.translate("Form", "Use as default", None, QtGui.QApplication.UnicodeUTF8)) - self.groupBox.setTitle(QtGui.QApplication.translate("Form", "Load existing profile", None, QtGui.QApplication.UnicodeUTF8)) - 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 retranslateUi(self): + self.setWindowTitle(QtGui.QApplication.translate("login", "Log in", None, QtGui.QApplication.UnicodeUTF8)) + self.new_profile.setText(QtGui.QApplication.translate("login", "Create", None, QtGui.QApplication.UnicodeUTF8)) + self.label.setText(QtGui.QApplication.translate("login", "Profile name:", None, QtGui.QApplication.UnicodeUTF8)) + self.load_profile.setText(QtGui.QApplication.translate("login", "Load profile", None, QtGui.QApplication.UnicodeUTF8)) + self.default.setText(QtGui.QApplication.translate("login", "Use as default", None, QtGui.QApplication.UnicodeUTF8)) + self.groupBox.setTitle(QtGui.QApplication.translate("login", "Load existing profile", None, QtGui.QApplication.UnicodeUTF8)) + self.groupBox_2.setTitle(QtGui.QApplication.translate("login", "Create new profile", None, QtGui.QApplication.UnicodeUTF8)) + self.toxygen.setText(QtGui.QApplication.translate("login", "toxygen", None, QtGui.QApplication.UnicodeUTF8)) + + def create_profile(self): + self.type = 1 + self.name = self.new_name.toPlainText() + self.close() + + def load_ex_profile(self): + if not self.create_only: + self.type = 2 + self.number = self.comboBox.currentIndex() + self.load_as_default = self.default.isChecked() + self.close() 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) + self.create_only = not list_of_profiles + + def update_on_close(self, func): + self.onclose = func + + def closeEvent(self, event): + self.onclose(self.type, self.number, self.load_as_default, self.name) + event.accept() + if __name__ == '__main__': app = QtGui.QApplication(sys.argv) diff --git a/src/main.py b/src/main.py index c165e96..84128ad 100644 --- a/src/main.py +++ b/src/main.py @@ -1,27 +1,64 @@ from loginscreen import LoginScreen from settings import Settings +from mainscreen import MainWindow from profile import Profile import sys from PySide import QtCore, QtGui -if __name__ == '__main__': +class login(object): + def __init__(self, arr): + self.arr = arr + + def login_screen_close(self, t, number=-1, default=False, name=None): + print str(t), str(number), str(default), str(name) + self.t = t + self.num = number + self.default = default + self.name = name + + def get_data(self): + return self.arr[self.num] + + +def main(): app = QtGui.QApplication(sys.argv) + app.setWindowIcon(QtGui.QIcon('images/icon.png')) settings = Settings() if not settings['auto_profile']: # show login screen if default profile not found ls = LoginScreen() - win = QtGui.QMainWindow() - ls.setupUi(win) + ls.setWindowIconText("Toxygen") profiles = Profile.find_profiles() ls.update_select(map(lambda x: x[1], profiles)) - win.show() + _login = login(profiles) + ls.update_on_close(_login.login_screen_close) + ls.show() app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) app.exec_() - # TODO: get result from loginscreen - # add new default profile (if needed) - # save selected profile to open - # create new profile? + if not _login.t: + return + elif _login.t == 1: # create new profile + # TODO: add creation of new profile + path = Settings.get_default_path() + name = _login.name if _login.name else 'Toxygen User' + return + else: # load existing profile + path, name = _login.get_data() + if _login.default: + settings['auto_profile'] = (path, name) + settings.save() else: path, name = settings['auto_profile'] + # loading profile + print str(path), str(name) + data = Profile.open_profile(path, name) + ms = MainWindow() + ms.show() + app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) + app.exec_() # TODO: open mainscreen + + +if __name__ == '__main__': + main()