def load_file(self, data_file): self.QCheckBox_LockStyle(self.bareCheck) self.QCheckBox_LockStyle(self.HLikeCheck) self.QCheckBox_LockStyle(self.HeLikeCheck) self.statusBar().showMessage("file loading...") self.cen_freq = float(self.cenFreqInput.text()) self.span = float(self.spanInput.text()) def load_file_worker(data_file): self.FileWork = IID(data_file, self.cen_freq, self.span, n_peak=10, GUI_mode=True) self.frequency_range, self.peak_sum, self.peak_list = self.FileWork.calc_peak() self.ion = self.peak_list["Ion"][0] def load_file_ready(): # check the bare ions self.bare_ions = self.peak_list[self.peak_list["Half-Life"].str.match("([\w.]+ ?[\w.]+)$")] self.QCheckBox_InputStyle(self.bareCheck) self.bareCheck.setChecked(True) # check the H-like ions if True in self.peak_list["Half-Life"].str.match("([\w.]+ ?[\w.]+) [\*]$").values: self.H_like_ions = self.peak_list[self.peak_list["Half-Life"].str.match("([\w.]+ ?[\w.]+) [\*]$")] self.QCheckBox_InputStyle(self.HLikeCheck) self.HLikeCheck.setChecked(True) # check the He-like ions if True in self.peak_list["Half-Life"].str.match("([\w.]+ ?[\w.]+) [\*]{2}$").values: self.He_like_ions = self.peak_list[self.peak_list["Half-Life"].str.match("([\w.]+ ?[\w.]+) [\*]{2}$")] self.QCheckBox_InputStyle(self.HeLikeCheck) self.HeLikeCheck.setChecked(True) self.statusBar().showMessage("Selected file has been loaded!") worker = Worker(load_file_worker, data_file) worker.signals.finished.connect(load_file_ready) self.threadPool.start(worker)
def connectPort(self): if (self.dropdown.currentText()): self.port = self.dropdown.currentText() ble = BLERadio() """ #add logic to pair with BLE """ print("Connected to:" + self.dropdown.currentText()) for element in self.comlist: if element.complete_name == self.dropdown.currentText( ) or self.dropdown.currentText() in str(element.address): #no check if uart service works try: if (UARTService in element.services or self.targetAddress in str(element.address)): self.uart_connection = ble.connect(element) print("Connected") self.device = element self.bleConnectionStatus = "Connected" self.updateStatus() worker = Worker(self.isConnectedBLE) worker.signals.finished.connect(self.finish) print("Starting hb") self.threadpool.start(worker) break else: raise Exception("No UART service") except: self.showError("No UART service")
def startThread(self, fn, resultFn=None, complete=None): worker = Worker( fn) # Any other args, kwargs are passed to the run function if resultFn is not None: worker.signals.result.connect(resultFn) if complete is not None: worker.signals.finished.connect(complete) #worker.signals.progress.connect(self.scannerProgress) self.threadpool.start(worker)
def button_status(): if self.statusButton.isChecked(): if not self.invisiablePanel.isVisible(): self.current_worker = Worker(Press_work, self.workMode) self.current_worker.signals.finished.connect(ready) self.current_worker.signals.progress.connect(process) self.current_worker.signals.result.connect(result) self.statusButton.setEnabled(False) self.threadPool.start(self.current_worker) else: self.step = self.stepInput.text() if int(self.step) <= 0: self.statusBar.showMessage("step input invaild! input again...") return self.current_worker = Worker(Debug_work, self.direct, self.step, self.stepDiff) self.current_worker.signals.finished.connect(ready) self.current_worker.signals.progress.connect(process) self.current_worker.signals.result.connect(result) self.statusButton.setEnabled(False) self.QLineEdit_RunStyle(self.stepInput) self.threadPool.start(self.current_worker) self.statusBar().showMessage("start press!")
def button_ionSearch(): if self.ionCheck.isChecked(): if self.ionInput.text() == "": self.statusBar().showMessage("No ion input for search! show the whole ion list instead.") self.ionInput.setText(self.ion) def data_flash_worker(): self.select_ions, self.peak_select_ions = self.calc_selected_ions(self.ionInput.text()) def data_flash_ready(): self.display(self.select_ions, self.peak_select_ions) self.statusBar().showMessage("Ion founded!") worker = Worker(data_flash_worker) worker.signals.finished.connect(data_flash_ready) self.threadPool.start(worker) else: self.statusBar().showMessage("Check the 'Ion' first!")
def button_ionCalibrate(): if self.calibrateBrhoCheck.isChecked(): if self.calibrateBrhoInput.text() == "": self.statusBar().showMessage("Invalid input!") return else: self.statusBar().showMessage("Calibrating...") else: if self.calibrateIonInput.text() == "" or self.calibratePeakLocInput.text() == "" or self.calibrateHarmInput.text() == "": self.statusBar().showMessage("Invalid input!") return if self.calibrateIonInput.text() in self.peak_list["Ion"].values: self.statusBar().showMessage("Calibrating...") else: self.statusBar().showMessage("Invalid input!") return def data_calibrate_worker(): if self.calibrateBrhoCheck.isChecked(): self.frequency_range, self.peak_sum, self.peak_list = self.FileWork.calibrate_Brho(float(self.calibrateBrhoInput.text())) else: self.frequency_range, self.peak_sum, self.peak_list = self.FileWork.calibrate_peak_loc(self.calibrateIonInput.text(), float(self.calibratePeakLocInput.text()), int(self.calibrateHarmInput.text())) self.ion = self.peak_list["Ion"][0]#[self.peak_list["Weight"].idxmax()] _, self.peak_select_ions = self.calc_selected_ions(self.ion) def data_calibrate_ready(): self.display(self.peak_list, self.peak_select_ions) self.statusBar().showMessage("Data has been calibrated!") if self.calibrateBrhoCheck.isChecked(): if self.calibrateIonInput.text() in self.peak_list["Ion"].values: self.calibratePeakLocInput.setText("{:.0f}".format(self.peak_list[self.peak_list["Ion"].isin([self.calibrateIonInput.text()])]["PeakLoc"].values[0])) self.calibrateHarmInput.setText("{:.0f}".format(self.peak_list[self.peak_list["Ion"].isin([self.calibrateIonInput.text()])]["Harmonic"].values[0])) else: self.calibrateIonInput.setText("") self.calibratePeakLocInput.setText("") self.calibrateHarmInput.setText("") self.calibrateBrhoInput.setText("{:.5f}".format(self.FileWork.Brho)) worker = Worker(data_calibrate_worker) worker.signals.finished.connect(data_calibrate_ready) self.threadPool.start(worker)
def scanHandle(self): worker = Worker(self.scan) worker.signals.finished.connect(self.scanDone) self.threadpool.start(worker)
def buildConnection(self): # build connection with mode def check_mode(b): if b.text() == "turn on " and b.isChecked() == True: self.statusBar().showMessage("turn on the IQ recorder") self.workMode = "2" if b.text() == "turn off" and b.isChecked() == True: self.statusBar().showMessage("turn off the IQ recorder") self.workMode = "1" self.modeShortButton.toggled.connect(lambda:check_mode(self.modeShortButton)) self.modeLongButton.toggled.connect(lambda:check_mode(self.modeLongButton)) # build connection with forward or backward def button_direction(b): if self.invisiablePanel.isVisible(): if b.text() == "forward" and b.isChecked() == True: self.direct = "1" if b.text() == "backward" and b.isChecked() == True: self.direct = "2" else: return self.operatForwardButton.toggled.connect(lambda:button_direction(self.operatForwardButton)) self.operatBackwardButton.toggled.connect(lambda:button_direction(self.operatBackwardButton)) # build connection with play or pause def button_status(): if self.statusButton.isChecked(): if not self.invisiablePanel.isVisible(): self.current_worker = Worker(Press_work, self.workMode) self.current_worker.signals.finished.connect(ready) self.current_worker.signals.progress.connect(process) self.current_worker.signals.result.connect(result) self.statusButton.setEnabled(False) self.threadPool.start(self.current_worker) else: self.step = self.stepInput.text() if int(self.step) <= 0: self.statusBar.showMessage("step input invaild! input again...") return self.current_worker = Worker(Debug_work, self.direct, self.step, self.stepDiff) self.current_worker.signals.finished.connect(ready) self.current_worker.signals.progress.connect(process) self.current_worker.signals.result.connect(result) self.statusButton.setEnabled(False) self.QLineEdit_RunStyle(self.stepInput) self.threadPool.start(self.current_worker) self.statusBar().showMessage("start press!") self.statusButton.setCheckable(True) self.statusButton.toggled.connect(button_status) self.statusButton.setEnabled(False) # short/long press work def Press_work(mode, stdscr): self.control.write(mode) while True: msg = self.control.read() stdscr.emit(int(msg)) if msg == "10" or msg == "11": break return self.stepDiff # free press work def Debug_work(direction, step, stepDiff, stdscr): self.control.write("3") time.sleep(0.05) self.control.write(direction + "," + step) while True: msg = self.control.read() stdscr.emit(int(msg)) if msg == "10" or msg == "11": break if direction == "1": return (stepDiff + int(step)) else: return (stepDiff - int(step)) def process(percentVal): if percentVal == 0: self.statusButton.setChecked(False) self.statusBar().showMessage("end press!") elif percentVal == 10: self.IQRstatus.setStyleSheet(self.off_style) self.IQRstatus.setFormat("off") elif percentVal == 11: self.IQRstatus.setStyleSheet(self.on_style) self.IQRstatus.setFormat("on") else: pass def ready(): self.statusButton.setEnabled(True) self.QLineEdit_StopStyle(self.stepInput) self.statusBar().showMessage("operation ends") if self.hide: if self.invisiablePanel.isVisible(): self.invisiablePanel.setVisible(False) self.modeLongButton.setEnabled(True) self.modeShortButton.setEnabled(True) self.modeLongButton.setStyleSheet(self.able_style) self.modeShortButton.setStyleSheet(self.able_style) self.statusBar().showMessage("hide the free mode") else: if not self.invisiablePanel.isVisible(): self.invisiablePanel.setVisible(True) self.modeLongButton.setEnabled(False) self.modeShortButton.setEnabled(False) self.modeLongButton.setStyleSheet(self.inable_style) self.modeShortButton.setStyleSheet(self.inable_style) self.statusBar().showMessage("show the free mode") if self.exit: self.statusBar().showMessage("exit the controller") self.control.disconnect() sys.exit() def result(stepDiff): self.stepDiff = stepDiff if self.stepDiff <= 0: self.stepChange.setText(str(self.stepDiff)) else: self.stepChange.setText("+" + str(self.stepDiff)) # intial the client def client_init(stdscr): self.control = ControlClient("10.10.91.96", 5052) self.control.write("init") msg = self.control.read() stdscr.emit(int(msg)) client_worker = Worker(client_init) client_worker.signals.progress.connect(process) client_worker.signals.finished.connect(ready) self.statusBar().showMessage("waiting for connecting...") self.threadPool.start(client_worker)