From f5ef1027d008eedd5bb20d2cb3b9e1b42cfedf18 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Tue, 29 Sep 2015 12:47:20 +0200 Subject: [PATCH] Refactored main window creation The main window was created in a somewhat stupid way, that required multiple steps to be taken from the main module. Now it's all in one call. --- relational_gui.py | 29 ++++------------------------- relational_gui/guihandler.py | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/relational_gui.py b/relational_gui.py index 4537598..dc1b726 100755 --- a/relational_gui.py +++ b/relational_gui.py @@ -81,14 +81,14 @@ if __name__ == "__main__": x11 = False if x11: - import sip # needed on windows from PyQt5 import QtGui, QtWidgets try: - from relational_gui import maingui, guihandler, about, surveyForm, resources + from relational_gui import guihandler, about, surveyForm except: print ( - "Module relational_gui is missing.\nPlease install relational package.", + "Module relational_gui is missing.\n" + "Please install relational package.", file=sys.stderr ) sys.exit(3) @@ -102,28 +102,7 @@ if __name__ == "__main__": app.setApplicationName('relational') app.setOrganizationDomain("None") - ui = maingui.Ui_MainWindow() - form = guihandler.relForm(ui) - ui.setupUi(form) - f = QtGui.QFont() - size = f.pointSize() - if sys.platform.startswith('win'): - winFont = 'Cambria' - symbolFont = 'Segoe UI Symbol' - increment = 4 - else: - winFont = f.family() - symbolFont = f.family() - increment = 2 - - ui.lstHistory.setFont(QtGui.QFont(winFont, size + increment)) - ui.txtMultiQuery.setFont(QtGui.QFont(winFont, size + increment)) - ui.txtQuery.setFont(QtGui.QFont(winFont, size + increment)) - ui.groupOperators.setFont(QtGui.QFont(winFont, size + increment)) - ui.cmdClearMultilineQuery.setFont(QtGui.QFont(symbolFont)) - ui.cmdClearQuery.setFont(QtGui.QFont(symbolFont)) - - form.restore_settings() + form = guihandler.relForm() m = enumerate(map(os.path.isfile, files)) invalid = ' '.join( diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index ee41b6e..73a2141 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -15,7 +15,9 @@ # along with this program. If not, see . # # author Salvo "LtWorf" Tomaselli -from PyQt5 import QtCore, QtWidgets, QtWidgets +import sys + +from PyQt5 import QtCore, QtWidgets, QtWidgets, QtGui from relational import relation, parser, optimizer, rtypes from relational.maintenance import UserInterface @@ -28,17 +30,42 @@ from relational_gui import maingui class relForm(QtWidgets.QMainWindow): - def __init__(self, ui): + def __init__(self): QtWidgets.QMainWindow.__init__(self) self.About = None self.Survey = None self.undo = None # UndoQueue for queries self.selectedRelation = None - self.ui = ui + self.ui = maingui.Ui_MainWindow() self.qcounter = 1 # Query counter self.user_interface = UserInterface() + # Creates the UI + self.ui.setupUi(self) + + #Setting fonts for symbols + f = QtGui.QFont() + size = f.pointSize() + if sys.platform.startswith('win'): + winFont = 'Cambria' + symbolFont = 'Segoe UI Symbol' + increment = 4 + else: + winFont = f.family() + symbolFont = f.family() + increment = 2 + font = QtGui.QFont(winFont, size + increment) + sfont = QtGui.QFont(symbolFont) + self.ui.lstHistory.setFont(font) + self.ui.txtMultiQuery.setFont(font) + self.ui.txtQuery.setFont(font) + self.ui.groupOperators.setFont(font) + self.ui.cmdClearMultilineQuery.setFont(sfont) + self.ui.cmdClearQuery.setFont(sfont) + self.settings = QtCore.QSettings() + self._restore_settings() + def checkVersion(self): from relational import maintenance @@ -263,7 +290,7 @@ class relForm(QtWidgets.QMainWindow): self.settings.setValue('maingui/splitter', self.ui.splitter.saveState()) self.settings.setValue('maingui/relations', self.user_interface.session_dump()) - def restore_settings(self): + def _restore_settings(self): self.user_interface.session_restore(self.settings.value('maingui/relations')) self.updateRelations()