def launch(): """ Instantiate a new QAplication and mainWindow classes and takes stdin input for savefile name :param app: (optional) If given, will not generate a new instance but use the one given, default is None :param win: (optional) if given, will not generate a new instance but use the one given, default is None :type app: PySide2.QtWidgets.QApplication :type app: PySide2.QtWidgets.QMainWindow """ global app try: app = QApplication(sys.argv) app.setApplicationName("partyAlignmentChartTool") app.setApplicationDisplayName("Party Alignment Chart Tool") app.setApplicationVersion("1.0.2") app.setOrganizationName("Julien Alardot") win = MainWindow(input("Savefile Name: ")) win.resize(0, 0) app.setWindowIcon(QIcon(os.path.join(PATH, "UI", "AlignmentTool.icon"))) app.connect(app, SIGNAL("lastWindowClosed()"), app, SLOT("quit()")) app.setActiveWindow(win) app.focusWindow() app.exec_() app.deleteLater() del app except Exception: tr.print_exc()
QtCore.SIGNAL("TICK_{}(double)".format(id(self))), t) class ClockDisplay(): def __init__(self): super(ClockDisplay, self).__init__() def Display(self, t): print(id(self), "->Received: ", t) if __name__ == "__main__": app = QApplication(sys.argv) #create two clocks and tow displays clock_1 = MyClock() display1 = ClockDisplay() time.sleep(0.5) clock_2 = MyClock() display2 = ClockDisplay() #connect clocks to display using a custom signal app.connect(QtCore.SIGNAL("TICK_{}(double)".format(id(clock_1))), display1.Display) app.connect(QtCore.SIGNAL("TICK_{}(double)".format(id(clock_2))), display2.Display) sys.exit(app.exec_())
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #Texts are not updated in GUI unless processEvents is called # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! print('step2') app.emit(QtCore.SIGNAL("SEND_MESSAGE(QString)"), 'step2') for i in range(1000000): app.processEvents() #let the main loop process gui events. print('finish') app.emit(QtCore.SIGNAL("SEND_MESSAGE(QString)"), 'finish') #Create the demo container wdFrm = QtWidgets.QWidget() layout = QtWidgets.QVBoxLayout(wdFrm) #A line edit to display computation step wdLineEdit = QtWidgets.QLineEdit("No computation running") layout.addWidget(wdLineEdit) #connect to the custom signal to print the step in the QLineEdit app.connect(QtCore.SIGNAL("SEND_MESSAGE(QString)"), wdLineEdit.setText) #Create a button to launch the computation wdButtonCompute = QtWidgets.QPushButton("Compute") layout.addWidget(wdButtonCompute) wdButtonCompute.clicked.connect(Compute) wdFrm.show() sys.exit(app.exec_())
# self.app.emit(QtCore.SIGNAL("UPDATE(str)"),self.iCounter) #DOES NOT WORK : func's prototype is wrong self.iCounter += 1 time.sleep(self.fDelay) if __name__ == "__main__": app = QApplication(sys.argv) wdFrm = QtWidgets.QFrame() layout = QtWidgets.QVBoxLayout() wdFrm.setLayout(layout) #Create two labels that will display a counter wdCounter = QtWidgets.QLineEdit("0") layout.addWidget(wdCounter) #Create a function for widget updating def UpdateCounter(iCounter): wdCounter.setText(str(iCounter)) app.connect(QtCore.SIGNAL("UPDATE(int)"),UpdateCounter) #Launch the updating thread timerThread = TimerUpdate(app, 0.005) timerThread.start() wdFrm.show() sys.exit(app.exec_())