class MainWindow_EXEC(): def __init__(self): app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() self.ui = Ui_MainWindow() self.ui.setupUi(MainWindow) self.update_tree() self.update_calendar() self.update_progressbar() MainWindow.show() sys.exit(app.exec_()) #---------------------------------------------------------- def update_tree(self): self.ui.treeWidget.headerItem().setText(1, 'Header 2') self.ui.treeWidget.topLevelItem(0).setText(1, "Item 2") self.ui.treeWidget.topLevelItem(0).addChild( QtWidgets.QTreeWidgetItem()) self.ui.treeWidget.topLevelItem(0).child(0).setText(1, "Subitem 2") def print_tree(self): header0 = self.ui.treeWidget.headerItem().text(0) header1 = self.ui.treeWidget.headerItem().text(1) print(header0 + '\n' + header1 + '\n') #---------------------------------------------------------- def update_calendar(self): self.ui.calendarWidget.selectionChanged.connect(self.update_date) def update_date(self): self.ui.dateEdit.setDate(self.ui.calendarWidget.selectedDate()) #---------------------------------------------------------- def update_progressbar(self): self.ui.radioButton_start.clicked.connect(self.start_progressbar) self.ui.radioButton_stop.clicked.connect(self.stop_progressbar) self.ui.radioButton_reset.clicked.connect(self.reset_progressbar) self.progress_value = 0 self.stop_progress = False def start_progressbar(self): self.stop_progress = False self.progress_value = self.ui.progressBar.value() while (self.progress_value <= 100.1) and not (self.stop_progress): self.ui.progressBar.setValue(self.progress_value) self.progress_value += 0.0001 QtWidgets.QApplication.processEvents() def stop_progressbar(self): self.stop_progress = True def reset_progressbar(self): self.progress_value = 0 self.ui.progressBar.reset() self.stop_progress = False
class MainWindow_EXEC(): def __init__(self): app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() self.ui = Ui_MainWindow() self.ui.setupUi(MainWindow) self.update_tree() self.update_calendar() self.update_progressbar() MainWindow.show() sys.exit(app.exec_()) #---------------------------------------------------------- def update_tree(self): # self.print_tree() self.ui.treeWidget.headerItem().setText(1, 'Header 2') self.ui.treeWidget.topLevelItem(0).setText(1, "Item 2") self.ui.treeWidget.topLevelItem(0).addChild( QtWidgets.QTreeWidgetItem()) self.ui.treeWidget.topLevelItem(0).child(0).setText(1, "Subitem 2") # self.print_tree() # print(self.ui.treeWidget.topLevelItem(0).text(1)) # print(self.ui.treeWidget.topLevelItem(0).text(0)) # print(self.ui.treeWidget.topLevelItem(0).child(0).text(0)) # print(self.ui.treeWidget.topLevelItem(0).child(0).text(1)) def print_tree(self): header0 = self.ui.treeWidget.headerItem().text(0) header1 = self.ui.treeWidget.headerItem().text(1) print(header0 + '\n' + header1 + '\n') #---------------------------------------------------------- def update_calendar(self): self.ui.calendarWidget.selectionChanged.connect(self.update_date) def update_date(self): self.ui.dateEdit.setDate(self.ui.calendarWidget.selectedDate()) #---------------------------------------------------------- def update_progressbar(self): self.ui.radioButton_start.clicked.connect(self.start_progressbar) self.ui.radioButton_stop.clicked.connect(self.stop_progressbar) self.ui.radioButton_reset.clicked.connect(self.reset_progressbar) def start_progressbar(self): pass def stop_progressbar(self): pass def reset_progressbar(self): pass
class MainWindow_EXEC(): def __init__(self): self.threadpool = QtCore.QThreadPool() app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() self.ui = Ui_MainWindow() self.ui.setupUi(MainWindow) self.update_tree() self.update_calendar() self.update_progressbar() MainWindow.show() sys.exit(app.exec_()) #---------------------------------------------------------- def update_tree(self): self.ui.treeWidget.headerItem().setText(1, 'Header 2') self.ui.treeWidget.topLevelItem(0).setText(1, "Item 2") self.ui.treeWidget.topLevelItem(0).addChild(QtWidgets.QTreeWidgetItem()) self.ui.treeWidget.topLevelItem(0).child(0).setText(1, "Subitem 2") def print_tree(self): header0 = self.ui.treeWidget.headerItem().text(0) header1 = self.ui.treeWidget.headerItem().text(1) print(header0 + '\n' + header1 + '\n') #---------------------------------------------------------- def update_calendar(self): self.ui.calendarWidget.selectionChanged.connect(self.update_date) def update_date(self): self.ui.dateEdit.setDate(self.ui.calendarWidget.selectedDate()) #---------------------------------------------------------- def update_progressbar(self): self.ui.radioButton_start.clicked.connect(self.oh_no) # self.ui.radioButton_start.clicked.connect(self.start_progressbar) self.ui.radioButton_stop.clicked.connect(self.stop_progressbar) self.ui.radioButton_reset.clicked.connect(self.reset_progressbar) self.progress_value = 0 self.stop_progress = False def test(self, progress_value): while progress_value < 10: print('hi') sleep(0.1) def oh_no(self): # Pass the function to execute # worker = Worker(self.start_progressbar) # Any other args, kwargs are passed to the run function # WORKS! worker = Worker(self.test, self.progress_value) # Any other args, kwargs are passed to the run function # worker = Worker(self.start_progressbar_run, self.stop_progress, self.progress_value, self.ui.progressBar) worker = Worker(self.start_progressbar_run, self.stop_progress, self.ui.progressBar) # Execute self.threadpool.start(worker) def start_progressbar_run(self, stop_progress, progressBar): # def start_progressbar_run(self, stop_progress, progress_value, progressBar): print('inside run') print(progressBar) stop_progress = False progress_value = progressBar.value() print(progress_value) while progress_value <= 101 and not stop_progress: print(progress_value) progress_value += 1 sleep(0.1) # while (progress_value <= 101) and not (stop_progress): # progressBar.setValue(progress_value) # progress_value += 1 # sleep(0.1) def start_progressbar(self): self.stop_progress = False self.progress_value = self.ui.progressBar.value() while (self.progress_value <= 101) and not (self.stop_progress): self.ui.progressBar.setValue(self.progress_value) self.progress_value += 1 sleep(0.1) # QtWidgets.QApplication.processEvents() def stop_progressbar(self): self.stop_progress = True def reset_progressbar(self): self.progress_value = 0 self.ui.progressBar.reset() self.stop_progress = False
class MainWindow_EXEC(): def __init__(self): app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() self.ui = Ui_MainWindow() self.ui.setupUi(MainWindow) self.update_tree() self.update_calendar() self.update_progressbar() MainWindow.show() sys.exit(app.exec_()) #---------------------------------------------------------- def update_tree(self): self.ui.treeWidget.headerItem().setText(1, 'Header 2') self.ui.treeWidget.topLevelItem(0).setText(1, "Item 2") self.ui.treeWidget.topLevelItem(0).addChild( QtWidgets.QTreeWidgetItem()) self.ui.treeWidget.topLevelItem(0).child(0).setText(1, "Subitem 2") def print_tree(self): header0 = self.ui.treeWidget.headerItem().text(0) header1 = self.ui.treeWidget.headerItem().text(1) print(header0 + '\n' + header1 + '\n') #---------------------------------------------------------- def update_calendar(self): self.ui.calendarWidget.selectionChanged.connect(self.update_date) def update_date(self): self.ui.dateEdit.setDate(self.ui.calendarWidget.selectedDate()) #---------------------------------------------------------- def update_progressbar(self): self.ui.radioButton_start.clicked.connect(self.start_progressbar) self.ui.radioButton_stop.clicked.connect(self.stop_progressbar) self.ui.radioButton_reset.clicked.connect(self.reset_progressbar) self.progress_value = 0 self.stop_progress = False def progressbar_counter(self, start_value=0): self.run_thread = RunThread(parent=None, counter_start=start_value) self.run_thread.start() self.run_thread.counter_value.connect(self.set_progressbar) def set_progressbar(self, counter): if not self.stop_progress: self.ui.progressBar.setValue(counter) def start_progressbar(self): self.stop_progress = False self.progress_value = self.ui.progressBar.value() self.progressbar_counter(self.progress_value) def stop_progressbar(self): self.stop_progress = True try: self.run_thread.stop() except: pass def reset_progressbar(self): self.stop_progressbar() self.progress_value = 0 self.stop_progress = False self.ui.progressBar.reset()