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 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))