Browse Source

Replace floating dialog with message window inside mainwindow

master
Nils 4 years ago
parent
commit
e6fdeaabfa
  1. 28
      qtgui/designer/mainwindow.py
  2. 979
      qtgui/designer/mainwindow.ui
  3. 12
      qtgui/mainwindow.py
  4. 57
      qtgui/waitdialog.py

28
qtgui/designer/mainwindow.py

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
# Created by: PyQt5 UI code generator 5.14.2
#
# WARNING! All changes made in this file will be lost!
@ -17,8 +17,17 @@ class Ui_MainWindow(object):
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName("verticalLayout")
self.tabbyCat = QtWidgets.QTabWidget(self.centralwidget)
self.mainPageSwitcher = QtWidgets.QStackedWidget(self.centralwidget)
self.mainPageSwitcher.setLineWidth(0)
self.mainPageSwitcher.setObjectName("mainPageSwitcher")
self.tabPage = QtWidgets.QWidget()
self.tabPage.setObjectName("tabPage")
self.verticalLayout_12 = QtWidgets.QVBoxLayout(self.tabPage)
self.verticalLayout_12.setObjectName("verticalLayout_12")
self.tabbyCat = QtWidgets.QTabWidget(self.tabPage)
self.tabbyCat.setObjectName("tabbyCat")
self.tab_quick = QtWidgets.QWidget()
self.tab_quick.setObjectName("tab_quick")
@ -239,7 +248,18 @@ class Ui_MainWindow(object):
self.informationTreeWidget.header().setMinimumSectionSize(50)
self.verticalLayout_11.addWidget(self.informationTreeWidget)
self.tabbyCat.addTab(self.tab_information, "")
self.verticalLayout.addWidget(self.tabbyCat)
self.verticalLayout_12.addWidget(self.tabbyCat)
self.mainPageSwitcher.addWidget(self.tabPage)
self.messagePage = QtWidgets.QWidget()
self.messagePage.setObjectName("messagePage")
self.verticalLayout_13 = QtWidgets.QVBoxLayout(self.messagePage)
self.verticalLayout_13.setObjectName("verticalLayout_13")
self.messageLabel = QtWidgets.QLabel(self.messagePage)
self.messageLabel.setAlignment(QtCore.Qt.AlignCenter)
self.messageLabel.setObjectName("messageLabel")
self.verticalLayout_13.addWidget(self.messageLabel)
self.mainPageSwitcher.addWidget(self.messagePage)
self.verticalLayout.addWidget(self.mainPageSwitcher)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
@ -313,6 +333,7 @@ class Ui_MainWindow(object):
self.menubar.addAction(self.menuClientNameId.menuAction())
self.retranslateUi(MainWindow)
self.mainPageSwitcher.setCurrentIndex(0)
self.tabbyCat.setCurrentIndex(0)
self.quickStackedWidget.setCurrentIndex(1)
self.detailedStackedWidget.setCurrentIndex(1)
@ -349,6 +370,7 @@ class Ui_MainWindow(object):
self.informationTreeWidget.topLevelItem(4).setText(1, _translate("MainWindow", "Last Updated"))
self.informationTreeWidget.setSortingEnabled(__sortingEnabled)
self.tabbyCat.setTabText(self.tabbyCat.indexOf(self.tab_information), _translate("MainWindow", "Information"))
self.messageLabel.setText(_translate("MainWindow", "Processing"))
self.menuControl.setTitle(_translate("MainWindow", "Control"))
self.menuSession.setTitle(_translate("MainWindow", "SessionName"))
self.menuClientNameId.setTitle(_translate("MainWindow", "ClientNameId"))

979
qtgui/designer/mainwindow.ui

File diff suppressed because it is too large

12
qtgui/mainwindow.py

@ -115,6 +115,8 @@ class MainWindow(QtWidgets.QMainWindow):
self.ui.setupUi(self)
self.fPalBlue = setPaletteAndFont(self.qtApp)
self.ui.mainPageSwitcher.setCurrentIndex(0) #1 is messageLabel 0 is the tab widget
#TODO: Hide information tab until the feature is ready
self.ui.tabbyCat.removeTab(2)
@ -189,7 +191,7 @@ class MainWindow(QtWidgets.QMainWindow):
self.toggleVisible(force=True)
getattr(self, "raise")() #raise is python syntax. Can't use that directly
self.activateWindow()
text = QtCore.QCoreApplication.translate("activateAndRaise", "Another GUI tried to launch.")
text = QtCore.QCoreApplication.translate("mainWindow", "Another GUI tried to launch.")
self.systemTray.showMessage("Argodejo", text, QtWidgets.QSystemTrayIcon.Information, 2000) #title, message, icon, timeout. #has messageClicked() signal.
def _updateGUIWithCachedPrograms(self):
@ -216,14 +218,14 @@ class MainWindow(QtWidgets.QMainWindow):
def updateProgramDatabase(self):
"""Display a progress-dialog that waits for the database to be build.
Automatically called on first start or when instructed by the user"""
text = QtCore.QCoreApplication.translate("updateProgramDatabase", "Updating Program Database")
informativeText = QtCore.QCoreApplication.translate("updateProgramDatabase", "Thank you for your patience.")
title = QtCore.QCoreApplication.translate("updateProgramDatabase", "Updating")
text = QtCore.QCoreApplication.translate("mainWindow", "Updating Program Database.\nThank you for your patience.")
settings = QtCore.QSettings("LaborejoSoftwareSuite", METADATA["shortName"])
settings.remove("programDatabase")
logger.info("Asking api to getSystemPrograms while waiting")
diag = WaitDialog(self, title, text, informativeText, api.buildSystemPrograms) #save in local var to keep alive
diag = WaitDialog(self, text, api.buildSystemPrograms) #save in local var to keep alive
settings.setValue("programDatabase", api.getSystemPrograms())
self._updateGUIWithCachedPrograms()

57
qtgui/waitdialog.py

@ -23,57 +23,50 @@ import logging; logger = logging.getLogger(__name__); logger.info("import")
#Standard Library
#Third Party
from PyQt5 import QtCore, QtGui, QtWidgets
class WaitThread(QtCore.QThread):
def __init__(self, longRunningFunction):
def __init__(self, mainWindow, longRunningFunction):
self.longRunningFunction = longRunningFunction
self.mainWindow = mainWindow
self.finished = False
QtCore.QThread.__init__(self)
def __del__(self):
"""This gets called rather early in the objects life but is in the main thread!"""
self.wait()
#This is after run
self.finished = True
logger.info(f"Thread done {self.longRunningFunction}")
def run(self):
"""This is in the side-thread. We can't access qt widgets here"""
logger.info(f"Thread running {self.longRunningFunction}")
self.longRunningFunction()
self.finished = True
class WaitDialog(QtWidgets.QMessageBox):
"""An information box that closes itself once a task is done.
class WaitDialog(object):
"""An information text that closes itself once a task is done.
Executes and shows on construction"""
def __init__(self, mainWindow, title, text, informativeText, longRunningFunction):
#text = QtCore.QCoreApplication.translate("AskBeforeQuit", "About to quit but session {} still open").format(nsmSessionName)
#informativeText = QtCore.QCoreApplication.translate("AskBeforeQuit", "Do you want to save?")
#title = QtCore.QCoreApplication.translate("AskBeforeQuit", "About to quit")
def __init__(self, mainWindow, text, longRunningFunction):
super().__init__()
logger.info(f"Starting blocking dialog {title} for {longRunningFunction}")
self.mainWindow = mainWindow
self.setWindowFlag(QtCore.Qt.Popup, True)
self.setIcon(self.Information)
self.setText(text)
self.setWindowTitle(title)
self.setInformativeText(informativeText)
self.setStandardButtons(QtWidgets.QMessageBox.NoButton) #no buttons
wt = WaitThread(longRunningFunction)
wt.finished.connect(self.realClose)
logger.info(f"Starting blocking message for {longRunningFunction}")
self.mainWindow = mainWindow
self.mainWindow.ui.messageLabel.setText(text)
self.mainWindow.ui.mainPageSwitcher.setCurrentIndex(1) #1 is messageLabel 0 is the tab widget
self.mainWindow.ui.menubar.setEnabled(False) #TODO: this will leave the options in the TrayIcon menu available.. but well, who cares...
wt = WaitThread(mainWindow, longRunningFunction)
#wt.finished.connect(self.threadDone) #does NOT trigger
wt.start()
while not wt.finished:
self.mainWindow.qtApp.processEvents()
self.exec()
def realClose(self):
self.closeEvent = QtWidgets.QMessageBox.closeEvent
logger.info("Thread done")
self.done(True)
def keyPressEvent(self, event):
event.ignore()
self.mainWindow.ui.menubar.setEnabled(True)
self.mainWindow.ui.mainPageSwitcher.setCurrentIndex(0) #1 is messageLabel 0 is the tab widget
def closeEvent(self, event):
event.ignore()

Loading…
Cancel
Save