def run(optimiser): app = QApplication(sys.argv) # Thread for running slow parts of the optimiser without pausing GUI opt_worker = OptWorker(optimiser) opt_thread = QThread() opt_worker.moveToThread(opt_thread) app.aboutToQuit.connect(opt_thread.quit) opt_thread.start() # Queue and thread for updating text field queue = Queue() sys.stdout = WriteStream(queue) window = BayesOptWindow(optimiser, opt_worker) window.show() write_thread = QThread() receiver = Receiver(queue) receiver.signal.connect(window.write_to_textfield) receiver.moveToThread(write_thread) write_thread.started.connect(receiver.run) app.aboutToQuit.connect(write_thread.quit) write_thread.start() # app.exec_() sys.exit(app.exec_())
def GeneratePreview(self): self.preview_thread = QThread() east_id = self.SearchTeamID(self.cloth_east, True) south_id = self.SearchTeamID(self.cloth_south, True) west_id = self.SearchTeamID(self.cloth_west, True) north_id = self.SearchTeamID(self.cloth_north, True) if self.config["save_route"] is None: save_to_route = THISDIR else: save_to_route = self.config["save_route"] self._createProgressBar() self.preview_worker = GenerateImageThread(self.background, self.table_border, east_id, south_id, west_id, north_id, self.technical_lines.isChecked(), save_to_route, self.bg_image, True) self.preview_worker.moveToThread(self.preview_thread) self.preview_thread.started.connect(self.preview_worker.run) self.preview_worker.update_progress.connect(self.UpdateStatus) self.preview_worker.finished.connect(self.preview_thread.quit) self.preview_worker.finished.connect(self.preview_worker.deleteLater) self.preview_thread.finished.connect(self.preview_thread.deleteLater) self.preview_thread.finished.connect(self.PreviewWindow) self.preview_thread.start()
def checkLock(i): if i == 1: self.lock1 = True if i == 2: self.lock2 = True if self.lock1 and self.lock2: self.updateSb(u"正在处理数据") self.th3 = QThread() self.comp = Comparer(self.file1, self.file2) self.comp.moveToThread(self.th3) self.th3.started.connect(self.comp.run) self.comp.finished.connect(self.th3.quit) self.comp.finished.connect(self.comp.deleteLater) self.th3.finished.connect(self.th3.deleteLater) self.comp.progress.connect(lambda p: up(p)) self.comp.output.connect(lambda c: self.logger(c)) self.comp.content1.connect( lambda content: self.writeFile(content, self.ofileadd)) self.comp.content2.connect( lambda content: self.writeFile(content, self.ofilerem)) self.th3.finished.connect( lambda: self.ui.progressBar.setValue(100)) self.comp.finished.connect( lambda: self.logger(u"数据处理完成,请检查生成的文件。\n")) self.comp.finished.connect(lambda: self.updateSb(u"处理完成")) self.th3.finished.connect( lambda: self.ui.pushButton_start.setEnabled(True)) self.th3.start()
def runFunctionInstallCoreBackend(self): """ Script that run a class as Thread to don't freeze main app """ nameOfFunction = sys._getframe().f_code.co_name nameOfFile = __file__ print(f'[{nameOfFile}][{nameOfFunction}] Started') # Step 1: Create worker # Step 2: Create a QThread object self.thread = QThread() # Step 3: Create a worker object self.worker = WorkerBashCommand() # Step 4: Move worker to the thread self.worker.moveToThread(self.thread) # Step 5: Connect signals and slots self.thread.started.connect( self.worker.runBashCommand(COMMAND_GIT_CLONE_CORE_BACKEND)) self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.thread.finished.connect( self.runFunctionInstallCoreBackendFinished) # Step 6: Start the thread self.thread.start() print(f'[{nameOfFile}][{nameOfFunction}] Finished')
def genData(self): if self.ofile == "": return self.thread = QThread() self.worker = Worker(self.adf, self.bbdf) self.worker.moveToThread(self.thread) self.thread.started.connect(self.worker.run) self.updateSb(u"正在处理数据") self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.worker.finished.connect(lambda: self.updateSb(u"处理完成")) self.worker.finished.connect( lambda: self.logger(u"数据处理完成,请检查生成的文件。\n")) self.thread.finished.connect(self.thread.deleteLater) self.worker.progress.connect(lambda p: self.ui.progressBar.setValue(p)) self.worker.output.connect(lambda c: self.logger(c)) self.worker.content.connect( lambda content: self.writeFile(content, self.ofile)) self.thread.start() self.ui.pushButton_start.setEnabled(False) self.thread.finished.connect( lambda: self.ui.pushButton_start.setEnabled(True))
def slot_remove_redundant(self) -> None: ''' Disables all constraints that only contain redundant information and don't create more relations ''' progress_dialog = self.api.get_progress_dialog( 'Constraint Cleaner', 'Removing redundant constraints...', False) progress_dialog.show() self.thread = QThread() self.worker = RemoveRedundantWorker() self.worker.moveToThread(self.thread) self.worker.signal_progress.connect( lambda progress: progress_dialog.set_progress(progress)) self.worker.signal_done.connect( lambda: ( # https://stackoverflow.com/a/13672943 self.thread.quit(), progress_dialog.close(), QMessageBox.information( self.api.main_window, 'Constraint Cleaner', 'All redundant constraints are removed.'))) self.worker.signal_fail.connect(lambda: ( self.thread.quit(), progress_dialog.close(), QMessageBox.critical( self.api.main_window, 'Constraint Cleaner', 'Failed to add a constraint.\nSee console for more information.' ))) self.thread.started.connect(self.worker.process) self.thread.start()
def main(): # initialize app = QApplication([]) # create connection to the server client = Client(address=('127.0.0.1', 8888), debug=True) client.client_connect() # create a main window window = MainWindow(window_width=400, window_height=600) window.setWindowTitle("Python chat") # waiting for messages global client_worker, network_thread # TODO: refactor this network_thread = QThread() network_thread.setTerminationEnabled(True) client_worker = ClientWorker(client_socket=client.client()) client_worker.recieved_message.connect(window.recieved_message_handler) client_worker.moveToThread(network_thread) network_thread.started.connect(client_worker.start) network_thread.start() window.show() return app.exec_()
def start(self, config, generic_log_handler, validation_log_handler): """ Starts the thread connecting the log panels to the relevant signals :param config: Config for the transformation to run :param generic_log_handler: The handler to consume all log records :param validation_log_handler: The handler to consume validation log records """ self.on_start() self.thread = QThread() self.worker = ControllerRunner(config) self.worker.moveToThread(self.thread) self.worker.finished.connect(self.on_finish) self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.thread.started.connect(self.worker.run) self.thread.finished.connect(self.thread.deleteLater) # connect the log handlers back to the main window self.worker.generic_log_record.connect(generic_log_handler.emit) self.worker.validation_log_record.connect(validation_log_handler.emit) self.thread.start()
def __init__(self): # gui self.app = QApplication([]) self.main_window = MainWindow(controller=self) # device self.device = Device() # fps stats self.fps_timer = QTimer() self.fps_timer.timeout.connect(self.update_ui_fps) self.spf = 1 # seconds per frame self.timestamp_last_capture = 0 # acquisition thread self.continuous_acquisition = False self.worker_wait_condition = QWaitCondition() self.acquisition_worker = AcquisitionWorker(self.worker_wait_condition, device=self.device) self.acquisition_thread = QThread() self.acquisition_worker.moveToThread(self.acquisition_thread) self.acquisition_thread.started.connect(self.acquisition_worker.run) self.acquisition_worker.finished.connect(self.acquisition_thread.quit) # self.acquisition_worker.finished.connect(self.acquisition_thread.deleteLater) # self.acquisition_thread.finished.connect(self.acquisition_worker.deleteLater) self.acquisition_worker.data_ready.connect(self.data_ready_callback) self.acquisition_thread.start() # default timebase self.set_timebase("20 ms") # on app exit self.app.aboutToQuit.connect(self.on_app_exit)
def handleClicked(self): if not self.ui.locationInput.text(): msgBox = QMessageBox() msgBox.setIcon(QMessageBox.Warning) msgBox.setText("지역을 설정해주세요.") else: filter = json.load(open("mod.json"))["filter"] filter_list = [] for c in self.checkboxes: if c.isChecked(): filter_list.append(filter[c.text()]) filter = ":".join(filter_list) #thread self.thread = QThread() self.worker = Worker(self.ui.locationInput.text(), filter) self.worker.moveToThread(self.thread) self.thread.started.connect(self.worker.run) self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.thread.finished.connect(self.thread.deleteLater) self.worker.progress.connect(self.ui.progressBar.setValue) self.thread.start() self.ui.startButton.setEnabled(False) self.thread.finished.connect(self.handleFinished)
def init_tracker(self, video_file): if self.current_state != State.Nothing_Loaded: self.prepare_destroy_tracker() self.destroyOnLoad = True self.tempVideoFile = video_file else: self.current_state = State.Initializing #Init tracker self.tracker = video_tracker(video_file, self.debugging) #Setup tracker thread self.tracker_thread = QThread(self) self.tracker.moveToThread(self.tracker_thread) #Setup Property Editor self.pe = pe_controller(self.ui.propertyEditor, self.tracker, self.debugging) #Connect signals and slots self.tracker.gen_start.connect(self.tracker.receive_signal) self.tracker.finished.connect(self.tracker_thread.quit) self.tracker.FrameSignal.connect(self.update_frames) self.tracker.stopped.connect(self.tracker_stopped) self.tracker.gen_history.connect(self.tracker.render_history) self.tracker_thread.start() self.current_state = State.Idle self.init_controls(self.tracker.video_data.num_frames)
def create_log_parser(self): thread = QThread() log_path = self.game_path / 'Logs' log_file = log_path / self.settings_data.get('log_file', '') if log_file.exists(): self.log_parser = LogParserThreadObject(log_file) self.log_parser.data_ready.connect(self.process_log_data) self.log_parser.moveToThread(thread) thread.started.connect(self.log_parser.run) return thread
def add_worker(self, worker, auto_start=True): thread = QThread() if auto_start: self.threads.append(thread) worker.moveToThread(thread) thread.started.connect(worker.run) worker.finished.connect(lambda success, worker=worker, thread=thread: self.worker_finished(worker, thread, success)) thread.finished.connect(lambda thread=thread: self.thread_finished(thread)) worker.error.connect(lambda error, worker=worker: self.worker_error.emit(str(worker), error)) worker.progress.connect(lambda progress, worker=worker: self._worker_progress(worker, progress)) self.workers[str(worker)] = thread
def slot_start_server(self) -> None: self.server_thread = QThread() self.server_worker = ServerWorker() self.server_worker.signal_connected.connect(self.slot_connected) self.server_worker.signal_error.connect(self.slot_error) self.server_worker.signal_started.connect(self.slot_server_started) self.server_worker.signal_shutdown.connect(self.slot_server_stopped) self.server_worker.signal_script_addr.connect(self.slot_script_addr) self.server_worker.moveToThread(self.server_thread) self.server_thread.started.connect(self.server_worker.process) self.server_thread.start() self.slot_server_running(True)
def __init__(self, songQueue, marqueeFunc, parent=None): self.parent = parent self.player = vlc.MediaPlayer() self.songQueue = songQueue self.currentSong = None self.marqueeFunc = marqueeFunc self.thread = QThread() self.worker = Worker(self) self.worker.moveToThread(self.thread) self.worker.check.connect(self.songEndCheck) self.thread.started.connect(self.worker.run) self.thread.start()
def slot_start_server(self) -> None: self.server_thread = QThread() self.server_worker = ServerWorker() self.server_worker.signal_connected.connect(self.slot_connected) self.server_worker.signal_disconnected.connect(self.slot_disconnected) self.server_worker.signal_error.connect(self.slot_error) self.server_worker.signal_c_code.connect(self.slot_received_c_code) self.server_worker.signal_started.connect(self.slot_server_started) self.server_worker.signal_shutdown.connect(self.slot_server_stopped) self.server_worker.signal_extract_data.connect(self.slot_extract_data) self.server_worker.signal_fetch_decompilation.connect( self.slot_fetch_decompilation) self.server_worker.signal_upload_function.connect( self.slot_download_requested) self.server_worker.moveToThread(self.server_thread) self.server_thread.started.connect(self.server_worker.process) self.server_thread.start() self.slot_server_running(True)
def GenerateImage(self): self.statusBar().showMessage('Generating image...') self._createProgressBar() if self.config["save_route"] is None: self.config["save_route"] = THISDIR save_to_route = QFileDialog.getExistingDirectory(self, "Where to save the image", self.config["save_route"], QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) if self.config["save_route"] != save_to_route: temp_file = open(THISDIR + "\\config\\config.json", "r", encoding="utf-8") fp_teams = json.loads(temp_file.read()) fp_teams["save_route"] = save_to_route fp_teams["image_route"] = self.bg_image new_file = open(THISDIR + "\\config\\config.json", "w+", encoding="utf-8") new_file.write(json.dumps(fp_teams, indent=4)) new_file.close() self.background = Image.open(THISDIR + "\\images\\mat.png") self.table_border = Image.open(THISDIR + "\\images\\table_border.png") self.tech_lines = Image.open(THISDIR + "\\images\\technical_lines.png") self.thread = QThread() east_id = self.SearchTeamID(self.cloth_east, True) south_id = self.SearchTeamID(self.cloth_south, True) west_id = self.SearchTeamID(self.cloth_west, True) north_id = self.SearchTeamID(self.cloth_north, True) self.worker = GenerateImageThread(self.background, self.table_border, east_id, south_id, west_id, north_id, self.technical_lines.isChecked(), save_to_route, self.bg_image) self.worker.moveToThread(self.thread) self.thread.started.connect(self.worker.run) self.worker.update_progress.connect(self.UpdateStatus) self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.thread.finished.connect(self.thread.deleteLater) self.thread.finished.connect(self.GeneratedDialog) self.thread.start()
def mcts_players(self, players: typing.Sequence[MctsPlayer]): self.stop_workers() self.log_display = LogDisplay() self.mcts_workers = {player.player_number: MctsWorker(player) for player in players} if not self.mcts_workers: self.worker_thread = None else: self.worker_thread = QThread() for worker in self.mcts_workers.values(): worker.move_chosen.connect(self.make_move) # type: ignore worker.move_analysed.connect(self.analyse_move) # type: ignore # noinspection PyUnresolvedReferences self.move_needed.connect(worker.choose_move) # type: ignore # noinspection PyUnresolvedReferences self.move_made.connect(worker.analyse_move) # type: ignore worker.moveToThread(self.worker_thread) self.worker_thread.start()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.l, m = load_gif(self) self.l.setGeometry(0, 0, 20, 20) self.app: QApplication = QApplication.instance() self.calc: QThread = QThread() self.frm: QFrame = QFrame(self) self.tray_icon_menu: QMenu = QMenu(self) self.tray_icon: QSystemTrayIcon = QSystemTrayIcon(self) self.app.view_main = self Setting() About() self.init_settings() self.init_main_window() self.init_tray_icon() self.init_frm() self.setAttribute(Qt.WA_TransparentForMouseEvents) self.shortcut_settings = QShortcut(QKeySequence("Ctrl+,"), self) self.shortcut_settings.activated.connect(self.show_settings) self.shortcut_refresh = QShortcut(QKeySequence("Ctrl+r"), self) self.shortcut_refresh.activated.connect(self.start_to_hope) self.shortcut_refresh = QShortcut(QKeySequence("Ctrl+q"), self) self.shortcut_refresh.activated.connect(self.close) if 'darwin' in sys.platform: menubar = self.menuBar() hope_menu = menubar.addMenu('Hope') hope_menu.addAction( QAction('About', self, triggered=self.show_about)) hope_menu.addAction( QAction('Settings', self, triggered=self.show_settings)) self.show() # self.show_settings() self.start_to_check_update()
def slot_start_server(self) -> None: if self.ui.checkBoxCopySaves.isChecked( ) and self.ui.lineEditSaveFolder.text().strip() == '': self.api.show_error( 'Entity Explorer Bridge', 'You need to set the folder where to store the copies.') return self.server_thread = QThread() self.server_worker = ServerWorker() self.server_worker.signal_connected.connect(self.slot_connected) self.server_worker.signal_disconnected.connect(self.slot_disconnected) self.server_worker.signal_error.connect(self.slot_error) self.server_worker.signal_started.connect(self.slot_server_started) self.server_worker.signal_shutdown.connect(self.slot_server_stopped) self.server_worker.moveToThread(self.server_thread) self.server_thread.started.connect(self.server_worker.process) self.server_thread.start() self.slot_server_running(True) self.set_folders_active(False)
def __init__(self): super(App, self).__init__() self.combo = None self.MainProcess = MainProcess() self.MainProcess.get_image_functions() self.fps_label = QLabel('FPS: XXX') self.initUI() self._thread = QThread(self) self.video_worker = VideoThread(self.MainProcess.list_of_filters) #self.combo.currentIndexChanged.connect(self.video_worker.new_filter_slot) self.combo.currentIndexChanged.connect(self._new_ind) self.video_worker.change_pixmap_signal.connect(self.update_image) self.video_worker.update_fps_signal.connect(self._new_fps) self.video_worker.moveToThread(self._thread) self.combo.setCurrentIndex(self.MainProcess.blank_index) # connect the buttons self.start_button.clicked.connect(self.video_worker.start) self.quit_button.clicked.connect( self.close) # force this to run on current thread self._thread.start()
def __init__(self, parent=None): super().__init__(parent) self.thread = QThread() self.worker = None grid_layout = QGridLayout(self) login_group_box = self.create_login_group() data_group_box = self.create_data_group() self.enable_editables.connect(login_group_box.setEnabled) self.enable_editables.connect(data_group_box.setEnabled) self.import_button = QPushButton('Importar', self) self.import_button.setEnabled(False) self.enable_editables.connect(self.import_button.setEnabled) self.import_button.clicked.connect(self.enable_editables) self.import_button.clicked.connect(self.load_data) self.bgg_user_line_edit.textChanged.connect(self.enable_import) self.ludo_mail_line_edit.textChanged.connect(self.enable_import) self.ludo_pass_line_edit.textChanged.connect(self.enable_import) grid_layout.addWidget(login_group_box, 1, 1, 1, 2) grid_layout.addWidget(data_group_box, 2, 1, 1, 2) grid_layout.addWidget(self.import_button, 8, 2) self.log_widget = QTextEdit(self) self.log_widget.setReadOnly(True) grid_layout.addWidget(self.log_widget, 9, 1, 30, 2)
def runLongTask(self): # 创建 QThread self.thread = QThread() # 创建 worker 对象 self.worker = Worker() # 将 work 移到 thread self.worker.moveToThread(self.thread) # 连接信号和槽 self.thread.started.connect(self.worker.run) self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.thread.finished.connect(self.thread.deleteLater) self.worker.progress.connect(self.reportProgress) # 启动线程 self.thread.start() # 结束 self.longRunningBtn.setEnabled(False) self.thread.finished.connect( lambda: self.longRunningBtn.setEnabled(True)) self.thread.finished.connect( lambda: self.stepLabel.setText("Long-Running Step: 0"))
def slot_test_shiftability(self) -> None: progress_dialog = self.api.get_progress_dialog( 'Shiftability Tester', 'Testing shiftability...', False) progress_dialog.show() self.thread = QThread() self.worker = TestShiftabilityWorker() self.worker.moveToThread(self.thread) self.worker.signal_progress.connect( lambda progress: progress_dialog.set_progress(progress)) self.worker.signal_done.connect( lambda: (self.thread.quit(), progress_dialog.close(), self.api.show_message( 'Shiftability Tester', 'Test complete. See console for more information.'))) self.worker.signal_fail.connect( lambda message: (self.thread.quit(), progress_dialog.close( ), self.api.show_error('Shiftability Tester', message))) self.worker.signal_locations.connect(self.slot_set_locations) self.thread.started.connect(self.worker.process) self.thread.start()
def __init__( self, config_file: str ) -> None: super().__init__() # load config try: self.config = Config(config_file) except Exception as e: QMessageBox.critical(self, 'Config error', str(e)) QTimer.singleShot(0, self.close) return # load settings self.settings = Settings() # state self.state_key: Optional[int] = None # label widget self.label_ping = ClickableLabel('Loading ...', self.post_history) self.label_ping.setTextFormat(Qt.RichText) self.label_ping.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum) layout_ping = QGridLayout() layout_ping.setContentsMargins(0, 0, 0, 0) layout_ping.addWidget(self.label_ping) self.widget_ping = QWidget() self.widget_ping.setLayout(layout_ping) self.addWidget(self.widget_ping) # alert widget self.label_alert = QLabel() self.label_alert.setWordWrap(True) self.label_alert.setAlignment(Qt.AlignCenter) self.label_alert.setStyleSheet(f'background: #dddddd;') self.addWidget(self.label_alert) # context menu self.action_report_done = QAction('Report done ...') self.action_report_done.triggered.connect(self.report_done) self.action_exit = QAction('Exit') self.action_exit.triggered.connect(self.close) self.action_frameless = QAction('Frameless window') self.action_frameless.setCheckable(True) self.action_frameless.triggered.connect(self.set_frameless_window) self.action_homepage = QAction('Open homepage') self.action_homepage.triggered.connect(self.open_homepage) self.context_menu = QMenu() self.context_menu.addAction(self.action_report_done) self.context_menu.addAction(self.action_exit) self.context_menu.addAction(self.action_frameless) self.context_menu.addAction(self.action_homepage) # threads self.thread_communication = QThread() self.thread_communication.start() # workers self.worker_communication = CommunicationWorker( netloc=self.config.netloc, base_path=self.config.base_path, api_key=self.config.api_key, guild=self.config.guild, member=self.config.member) self.worker_communication.moveToThread(self.thread_communication) # signals self.worker_communication.signal_get_ping_done.connect(self.get_ping_done) self.worker_communication.signal_post_history_done.connect(self.post_history_done) self.signal_get_ping.connect(self.worker_communication.get_ping) self.signal_post_history.connect(self.worker_communication.post_history) # get ping timer QTimer.singleShot(0, self.get_ping) self.timer_ping = QTimer() self.timer_ping.timeout.connect(self.get_ping) self.timer_ping.setTimerType(Qt.VeryCoarseTimer) self.timer_ping.start(self.INTERVAL_SECS * 1000) # switch label timer self.timer_label = QTimer() self.timer_label.timeout.connect(lambda: self.setCurrentWidget(self.widget_ping)) self.timer_label.setSingleShot(True) self.timer_label.setTimerType(Qt.CoarseTimer) # window attributes size = self.settings.get('window', 'size', type_=QSize) if size is not None: self.resize(size) pos = self.settings.get('window', 'pos', type_=QPoint) if pos is not None: self.move(pos) frameless = self.settings.get('window', 'frameless', type_=bool) if frameless is not None and frameless: QTimer.singleShot(100, self.action_frameless.trigger) self.setWindowFlag(Qt.WindowStaysOnTopHint, self.config.window_stays_on_top) self.setAttribute(Qt.WA_TranslucentBackground) self.setWindowTitle('Evelyn Reminder')
data=data) # mittagspause ende schedule.every().day.at("13:30").do(data_picker, data=data) schedule.every().day.at("14:15").do(data_picker, data=data) schedule.every().day.at("15:00").do(data_picker, data=data) # FEIERABEND #-------------------- # 6 SAVE JSON INFO in SQLITE #-------------------- # Zwwischenspeicherung der Daten , unnötige requests vermeiden. #---------------------------------------- # APP #---------------------------------------- # Step 2: Create a QThread object thread = QThread() # Step 3: Create a worker object worker = Worker() # Step 4: Move worker to the thread worker.moveToThread(thread) # Step 5: Connect signals and slots thread.started.connect(worker.run) worker.finished.connect(thread.quit) worker.finished.connect(worker.deleteLater) thread.finished.connect(thread.deleteLater) # Step 6: Start the thread thread.start() app = QtWidgets.QApplication([])
def genComp(self): if self.ofile == "": return self.file1 = pd.DataFrame() self.file2 = pd.DataFrame() def updateFile(f, id): if id == 1: self.file1 = f if id == 2: self.file2 = f self.p = 0 self.lock1 = False self.lock2 = False def checkLock(i): if i == 1: self.lock1 = True if i == 2: self.lock2 = True if self.lock1 and self.lock2: self.updateSb(u"正在处理数据") self.th3 = QThread() self.comp = Comparer(self.file1, self.file2) self.comp.moveToThread(self.th3) self.th3.started.connect(self.comp.run) self.comp.finished.connect(self.th3.quit) self.comp.finished.connect(self.comp.deleteLater) self.th3.finished.connect(self.th3.deleteLater) self.comp.progress.connect(lambda p: up(p)) self.comp.output.connect(lambda c: self.logger(c)) self.comp.content1.connect( lambda content: self.writeFile(content, self.ofileadd)) self.comp.content2.connect( lambda content: self.writeFile(content, self.ofilerem)) self.th3.finished.connect( lambda: self.ui.progressBar.setValue(100)) self.comp.finished.connect( lambda: self.logger(u"数据处理完成,请检查生成的文件。\n")) self.comp.finished.connect(lambda: self.updateSb(u"处理完成")) self.th3.finished.connect( lambda: self.ui.pushButton_start.setEnabled(True)) self.th3.start() def up(wp): self.p += 0.4 * wp self.ui.progressBar.setValue(self.p) self.th1 = QThread() self.th2 = QThread() self.worker1 = Worker(self.adf, self.bbdf) self.worker2 = Worker(self.andf, self.bbdf) self.worker1.moveToThread(self.th1) self.worker2.moveToThread(self.th2) self.th1.started.connect(self.worker1.run) self.worker1.content.connect(lambda f: updateFile(f, 1)) self.worker1.finished.connect(self.th1.quit) self.worker1.finished.connect(self.worker1.deleteLater) self.worker1.finished.connect(lambda: checkLock(1)) self.th1.finished.connect(self.th1.deleteLater) self.th2.started.connect(self.worker2.run) self.worker2.content.connect(lambda f: updateFile(f, 2)) self.worker2.finished.connect(self.th2.quit) self.worker2.finished.connect(self.worker2.deleteLater) self.worker2.finished.connect(lambda: checkLock(2)) self.th2.finished.connect(self.th2.deleteLater) self.worker1.progress.connect(lambda p: up(p)) self.worker2.progress.connect(lambda p: up(p)) # self.worker1.output.connect(lambda c: self.logger(c)) # self.worker2.output.connect(lambda c: self.logger(c)) self.th1.start() self.th2.start() self.ui.pushButton_start.setEnabled(False)
for event in list(events): (_, type_names, path, filename) = event if filename[-3:] == 'qml' and 'IN_MODIFY' in type_names: reload = True break if reload: self.requestReload.emit() if __name__ == "__main__": app = QGuiApplication(sys.argv) engine = QQmlApplicationEngine() workerThread = QThread() workerThread.start() worker = Worker() worker.moveToThread(workerThread) master = Master() master.command.connect(worker.run) worker.requestReload.connect(master.reload) master.command.emit() # Stop application gracefully: signal.signal(signal.SIGINT, signal.SIG_DFL) status = app.exec_() worker.stop() workerThread.quit() workerThread.wait()