def _get_export_filename(self, filter='ASCII text (*.txt)'): initialdir = session.props.get('lastexportdir', session.dirname) filename, _ = QFileDialog.getSaveFileName(self, 'Select export file name', initialdir, filter) if filename == '': return '' expfilename = path_to_str(filename) session.props.lastexportdir = path.dirname(expfilename) return expfilename
def on_actionInsert_triggered(self): initialdir = session.dirname if not initialdir: with self.sgroup as settings: initialdir = settings.value('loadfiledirectory', '') filename, _ = QFileDialog.getOpenFileName(self, 'Select file name', initialdir, 'ufit files (*.ufit)') if filename == '': return self.insert_session(path_to_str(filename))
def on_settemplateBtn_clicked(self): previous = self.templateEdit.text() if previous: startdir = path.dirname(previous) else: startdir = '.' fn = path_to_str( QFileDialog.getOpenFileName(self, 'Choose a file', startdir, 'All files (*)')[0]) if not fn: return dtempl, numor = extract_template(fn) self.set_template(dtempl, numor)
def changeDir(self): """ Change directory from which are the data read """ if self.dir: startdir = self.dir else: startdir = '.' fn = path_to_str(QFileDialog.getOpenFileName( self, 'Choose a file', startdir, 'All files (*)')[0]) if not fn: return dtempl, numor = extract_template(fn) self.dir = dtempl self.ui.txtNumors.setText(str(numor)) print("directory changed to", self.dir)
def save_session_as(self): initialdir = session.dirname filename, _ = QFileDialog.getSaveFileName(self, 'Select file name', initialdir, 'ufit files (*.ufit)') if filename == '': return False session.set_filename(path_to_str(filename)) try: session.save() except Exception as err: logger.exception('Saving session failed') QMessageBox.warning(self, 'Error', 'Saving failed: %s' % err) return False return True
def open_data(self, final=False): try: prec = float(self.precisionEdit.text()) except ValueError: QMessageBox.information(self, 'Error', 'Enter a valid precision.') return floatmerge = self.rbFloatMerge.isChecked() xcol = str(self.xcolBox.currentText()) ycol = str(self.ycolBox.currentText()) dycol = str(self.dycolBox.currentText()) mcol = str(self.moncolBox.currentText()) fcol = str(self.filtercolBox.currentText()) if mcol == 'none': mcol = None if dycol == 'sqrt(Y)': dycol = None try: mscale = int(self.monscaleEdit.text()) except Exception: QMessageBox.information(self, 'Error', 'Monitor scale must be integer.') return if fcol == 'none': filter = None else: try: val = float(self.filtervalEdit.text()) except ValueError: val = bytes(self.filtervalEdit.text(), 'utf-8') filter = {fcol: val} dtempl = path_to_str(self.templateEdit.text()) self.loader.template = dtempl numors = str(self.numorsEdit.text()) try: datas = self.loader.load_numors(numors, prec, xcol, ycol, dycol, mcol, mscale, floatmerge, filter) except Exception as e: self.logger.exception('Error while loading data file') QMessageBox.information(self, 'Error', str(e)) return self.last_data = datas if final: self.newDatas.emit(datas, self.groupBox.currentText()) self.closeRequest.emit() else: self.plot()
def on_dirBtn_clicked(self): newdir = QFileDialog.getExistingDirectory(self, 'New directory', self.rootdir) self.set_directory(path_to_str(newdir))
def on_browseBtn_clicked(self): templ = path_to_str(self.templateEdit.text()) self.open_browser(path.dirname(templ))