def freeResources(self): if isinstance(self.__ftpWatcherThread, QThread): if self.__processBean.isLaserWatcherRunning(): Logger().debug("Stop laser watcher thread") QMetaObject.invokeMethod(self.__ftpWatcher, "stopProcess") if isinstance(self.__fsWatcherThread, QThread): if self.__processBean.isCameraWatcherRunning(): Logger().debug("Stop camera watcher thread") QMetaObject.invokeMethod(self.__fsWatcher, "stopProcess")
def turn_on(self): if self.is_on: self.ui.Launch_Measurements.setEnabled(True) self.ui.power_button.setText("Turn ON") QMetaObject.invokeMethod(self.discoWorker, "turn_off") self.is_on = False else: self.ui.Launch_Measurements.setEnabled(False) self.ui.power_button.setText("Turn OFF") QMetaObject.invokeMethod(self.discoWorker, "turn_on") self.is_on = True
def qt_message_handler(mode, context, message): global engine_point global mObjMsg if mode == QtCore.QtInfoMsg: mode = 'Info' elif mode == QtCore.QtWarningMsg: mode = 'Warning' if message.find(".qml")!=-1: root = engine_point.rootObjects()[0] QMetaObject.invokeMethod(root, "closeBusy") if not message in mObjMsg.getMessages(): root.setProperty("argsFucntionLastCall",["warning:\n"+message]) QMetaObject.invokeMethod(root, "_messageWarningPySide") mObjMsg.addMessage(message) elif mode == QtCore.QtCriticalMsg: mode = 'critical' elif mode == QtCore.QtFatalMsg: mode = 'fatal' else: mode = 'Debug' if mode=='Debug': print("%s: %s" % (mode, message)) else: print("%s: %s (%s:%d, %s)" % (mode, message, context.file, context.line, context.file))
def closeEvent(self, event): Logger().debug("Chiusura applicazione") if isinstance(self.obs, Observer): if self.obs.isAlive(): Logger().info("Chiusura Observer") self.obs.stop() self.obs.join() Logger().info("Observer thread terminato") res = QMetaObject.invokeMethod(self.tailer, "stopProcess", Qt.BlockingQueuedConnection) QCoreApplication.processEvents() self.tailer.thread().wait() Logger().debug("Tailer listener thread terminato") super(MainWindow, self).closeEvent(event)
runs_on_target = True for o, a in opts: if (o == '-d'): runs_on_target = False # Setup Qt application app = QApplication(sys.argv) signal.signal(signal.SIGINT, sigint_handler) bt_thread = QThread() bt_thread.start() bt_listener = BtListener() bt_listener.moveToThread(bt_thread) QMetaObject.invokeMethod(bt_listener, 'run') thermometer = Thermometer() bt_listener.data_updated.connect(thermometer.update) engine = QQmlApplicationEngine() root = engine.rootContext() root.setContextProperty('thermometer', thermometer) root.setContextProperty('runsOnTarget', runs_on_target) engine.load('./main.qml') exit_code = app.exec_() # TODO: stopping asyncio thread does not work # bt_listener.stop()
def closeBusy(self): if self.autoBusy: if self.m_engine != None: root = self.m_engine.rootObjects()[0] QMetaObject.invokeMethod(root, "closeBusy")
def stopLaserWatcher(self): Logger().debug("Stop laser watcher thread") QMetaObject.invokeMethod(self.__ftpWatcher, "stopProcess")
def stopCameraWatcher(self): Logger().debug("Stop camera watcher thread") QMetaObject.invokeMethod(self.__fsWatcher, "stopProcess")
def invoke(self, func, *args): self.queue.put(lambda: func(*args)) QMetaObject.invokeMethod(self, "handler", Qt.QueuedConnection)
def invoke(self, func, *args): f = lambda: func(*args) self.queue.put(f) QMetaObject.invokeMethod(self, "handler", Qt.QueuedConnection)
def runLastCall(self): if not self.tempCallData.isEmpty(): if self.tempCallData.count() == 5: if str(self.tempCallData.at(1).toString()) == "order": if self.tempCallData.at(0).toBool( ) == True: #// call direct obsolete, betterbetter to use recursivecall if not self.tempCallFunctionArgs.isEmpty(): nameObject = self.tempCallFunctionArgs.at( 0).toString() nameFunction = self.tempCallFunctionArgs.at( 1).toString() root = self.m_engine.rootObjects()[0] object_qml = root.findChild(QObject, nameObject) if self.tempCallFunctionArgs.at(2).isArray(): args = self.tempCallFunctionArgs.at( 2).toArray() #.toVariantList() if args.count() == 0: QMetaObject.invokeMethod( object_qml, nameFunction) else: root.setProperty("argsFucntionLastCall", args) QMetaObject.invokeMethod( object_qml, nameFunction) # https://bugreports.qt.io/browse/PYSIDE-1262 # Q_ARG missing, invokeMethod doesn't work currently with arguments in PySide2. # if args.count()==1: # print("\nnnn",args.at(0),"\nnnnn") # QMetaObject.invokeMethod(object_qml, nameFunction, # QGenericArgument(QByteArray(b'QVariant'), 69)) # # if args.count()==2: # QMetaObject.invokeMethod(object_qml, nameFunction, # QGenericArgument('QVariant', args.at(0)), # QGenericArgument('QVariant', args.at(1))) # # if args.count()==3: # QMetaObject.invokeMethod(object_qml, nameFunction, # QGenericArgument('QVariant', args.at(0)), # QGenericArgument('QVariant', args.at(1)), # QGenericArgument('QVariant', args.at(2))) # # if args.count()==4: # QMetaObject.invokeMethod(object_qml, nameFunction, # QGenericArgument('QVariant', args.at(0)), # QGenericArgument('QVariant', args.at(1)), # QGenericArgument('QVariant', args.at(2)), # QGenericArgument('QVariant', args.at(3))) # else: self.call( self.tempCallData.at(2).toString(), self.tempCallData.at(3).toString(), self.tempCallData.at(4).toArray()) if self.tempCallData.at(1).toString() == "report": self.runReport( self.tempCallData.at(2).toString(), self.tempCallData.at(3).toString(), self.tempCallData.at(4).toArray()) self.tempCallData = QJsonArray() self.tempCallFunctionArgs = QJsonArray()
def clearMessagesWarning(self): root = self.m_engine.rootObjects()[0] QMetaObject.invokeMethod(root, "clearMessages")
def recursiveCall(self, pid, method, par): self.clearMessagesWarning() self.boolRecursive = True result = self.callDirect(pid, method, par) if result["data"].__contains__("result"): if self.mpid != "open@": self.boolRecursive = False return result not_complete = True while not_complete: reValue = result["data"] if reValue.__class__() == 0 and (reValue == 401 or reValue == 403): mok = False textinput = self.tr("Re-enter Password:"******"Password", textinput, QLineEdit.Password) if mok: result = self.openConect(self.usuario, inputPass, self.mhost, self.mport, self.mdbase, True) else: not_complete = False result['data'] = 'error' self.boolRecursive = False root = self.m_engine.rootObjects()[0] QMetaObject.invokeMethod(root, "backLogin") elif reValue.__class__() == {}: if reValue.__contains__("result"): if self.mpid != "open@": not_complete = False else: if self.boolConnect: result = self.callDirect(pid, method, par) else: mok = False textinput = self.tr( "Incorrect, Re-enter Password:"******"Incorrect Password", textinput, QLineEdit.Password) if mok: result = self.openConect( self.usuario, inputPass, self.mhost, self.mport, self.mdbase, True) else: not_complete = False self.boolRecursive = False result['data'] = 'error' root = self.m_engine.rootObjects()[0] QMetaObject.invokeMethod(root, "backLogin") elif reValue.__contains__("error"): if reValue["error"].__class__() == []: if 'UserWarning' in reValue["error"]: cb = QCheckBox("Always ignore this warning.") msgBox = QMessageBox() msgBox.setText(reValue["error"][1][0]) msgBox.setInformativeText(reValue["error"][1][1]) msgBox.setStandardButtons(QMessageBox.No | QMessageBox.Yes) msgBox.setDefaultButton(QMessageBox.Yes) msgBox.setCheckBox(cb) rbox = msgBox.exec_() if rbox == QMessageBox.Yes: result = self.callDirect( pid, 'model.res.user.warning.create', [[{ 'always': cb.isChecked(), 'user': self.token[0], 'name': reValue["error"][1][0] }], self.preferences]) if result["data"].__contains__("result"): result = self.callDirect(pid, method, par) else: not_complete = False result['data'] = 'error' elif reValue["error"][0].__contains__( "403") or reValue["error"][0].__contains__( "401"): mok = False textinput = self.tr("Re-enter Password:"******"error"][0].__contains__("401"): textinput = "Authorization Required \n" + textinput inputPass, mok = QInputDialog.getText( None, "Password", textinput, QLineEdit.Password) if mok: result = self.openConect( self.usuario, inputPass, self.mhost, self.mport, self.mdbase, True) else: not_complete = False result['data'] = 'error' self.boolRecursive = False root = self.m_engine.rootObjects()[0] QMetaObject.invokeMethod(root, "backLogin") else: not_complete = False else: not_complete = False else: not_complete = False self.boolRecursive = False return result