#! /usr/bin/env python3 # -*- coding: utf-8 -*- """ Copyright 2020, Nils Hilbricht, Germany ( https://www.hilbricht.net ) This file is part of the Laborejo Software Suite ( https://www.laborejo.org ) This application is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ 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): self.longRunningFunction = longRunningFunction QtCore.QThread.__init__(self) def __del__(self): self.wait() def run(self): self.longRunningFunction() class WaitDialog(QtWidgets.QMessageBox): """An information box 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") super().__init__() 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) wt.start() self.exec() def realClose(self): self.closeEvent = QtWidgets.QMessageBox.closeEvent self.done(True) def keyPressEvent(self, event): event.ignore() def closeEvent(self, event): event.ignore()