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 save_figure(self, *args): filetypes = self.canvas.get_supported_filetypes_grouped() sorted_filetypes = sorted(filetypes.items()) start = self.canvas.get_default_filename() filters = [] for name, exts in sorted_filetypes: if 'eps' in exts or 'emf' in exts or 'jpg' in exts or \ 'pgf' in exts or 'raw' in exts: continue exts_list = " ".join(['*.%s' % ext for ext in exts]) filter = '%s (%s)' % (name, exts_list) filters.append(filter) filters = ';;'.join(filters) fname, _ = QFileDialog.getSaveFileName(self, 'Choose a filename to save to', start, filters) if fname: try: self.canvas.print_figure(text_type(fname)) except Exception as e: logger.exception('Error saving file') QMessageBox.critical(self, 'Error saving file', str(e))
def on_dirBtn_clicked(self): newdir = QFileDialog.getExistingDirectory(self, 'New directory', self.rootdir) self.set_directory(path_to_str(newdir))