def run(self): class ProcessRunnable(QRunnable): def __init__(self, run_task): super().__init__() self.setAutoDelete(True) self.task = run_task self.results = [] def run(self): print('processing...', self.task.filename) if self.task.load_data(): print('data loaded...', self.task.filename) else: print('data not loaded...', self.task.filename) # Emit signal that task may have results self.task.results_ready.emit(QVariant(self.task)) print('BackgroundProcessForImporters starting load threads') pool = QThreadPool() # Disable expiration pool.setExpiryTimeout(-1) print('MaxThread count: ', pool.maxThreadCount()) # Starting all threads for importation runnable_list = [] for task in self.tasks: # Connect signals task.update_progress.connect(self.update_current_task_progress) # Add to list runnable_list.append(ProcessRunnable(task)) # Connect results ready signals task.results_ready.connect(self.results_ready) # Start last inserted runnable pool.start(runnable_list[-1], priority=QThread.NormalPriority) # Wait for all runnable threads if pool.waitForDone(): print('All threads done!')
def run(self): # 2. Implement run() ui = Ui_MainWindow() window = QMainWindow() version = self.build_settings['version'] ui.setupUi(window) window.setWindowTitle("HotelManagementSystem v" + version) #Setup Charts for isolated UI editing ui.chartView = QtChart.QChartView(window) ui.chartView_2 = QtChart.QChartView(window) ui.gridLayout_3 = QtWidgets.QGridLayout(ui.groupBox_2) ui.gridLayout_3.addWidget(ui.chartView, 0, 0, 1, 1) ui.gridLayout_4 = QtWidgets.QGridLayout(ui.groupBox_3) ui.gridLayout_4.addWidget(ui.chartView_2, 0, 0, 1, 1) window.showMaximized() #Database connection, instead of sqlite3 db = QSqlDatabase('QSQLITE') db.setDatabaseName(self.get_resource('hotel.db')) model = QSqlTableModel(self.app, db) #Threading thrd = QThreadPool().globalInstance() thrd.setExpiryTimeout(5) hlist = ['Reserv. ID','Customer ID','Room #','From','To','Discount','Extension','Net Total'] worker = TableWorker(update_table("CurrentReservation", hlist, ui.current_res, db, model)) #We pass a function for the worker to execute thrd.tryStart(worker) #Setup Signals ui.newRes.triggered.connect(lambda: self.new_res_dialog(db, ui, model)) ui.newRoom.triggered.connect(lambda: self.new_room_dialog(db)) ui.newService.triggered.connect(lambda: self.new_srv_dialog(db)) ui.newCustomer.triggered.connect(lambda: self.new_customer_dialog(db)) ui.cancelRes.triggered.connect(lambda: self.new_cancel_dialog(window, db, ui.current_res.currentIndex(), thrd, model, hlist, ui.current_res)) #TODO Add new dialog for adding/deleting services to a current Reservation ui.current_res.doubleClicked.connect(lambda: self.new_addservice_dialog(window, db, ui.current_res.currentIndex(), thrd)) return self.app.exec_() # 3. End run() with this line