Exemplo n.º 1
0
 def replot(self, limits=True):
     plotter = self.canvas.plotter
     plotter.reset(limits=limits)
     try:
         plotter.plot_data(self.fitter.data)
         plotter.plot_model_full(self.fitter.model, self.fitter.data)
     except Exception:
         logger.exception('Error while plotting')
     else:
         plotter.draw()
Exemplo n.º 2
0
 def save_session(self):
     if session.filename is None:
         return self.save_session_as()
     try:
         session.save()
     except Exception as err:
         logger.exception('Saving session failed')
         QMessageBox.warning(self, 'Error', 'Saving failed: %s' % err)
         return False
     return True
Exemplo n.º 3
0
 def plot(self, limits=True, canvas=None):
     canvas = canvas or self.canvas
     plotter = canvas.plotter
     plotter.reset(limits)
     try:
         plotter.plot_image(self.item.data)
     except Exception:
         logger.exception('Error while plotting')
     else:
         canvas.draw()
Exemplo n.º 4
0
 def on_actionExportParams_triggered(self):
     items = self.selected_items(ScanDataItem)
     dlg = ParamExportDialog(self, items)
     if dlg.exec_() != QDialog.Accepted:
         return
     expfilename = self._get_export_filename()
     if expfilename:
         try:
             dlg.do_export(expfilename)
         except Exception as e:
             logger.exception('While exporting parameters')
             QMessageBox.warning(self, 'Error', 'Could not export '
                                 'parameters: %s' % e)
Exemplo n.º 5
0
 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
Exemplo n.º 6
0
 def exec_callback(self):
     try:
         from ufit.gui.console import ConsoleWindow
     except ImportError:
         logger.exception('Qt console window cannot be opened without '
                          'IPython; import error was:')
         QMessageBox.information(
             self, 'ufit', 'Please install IPython with qtconsole to '
             'activate this function.')
         return
     w = ConsoleWindow(self)
     w.ipython.executeCommand('from ufit.lab import *')
     w.ipython.pushVariables({
         'fig':
         self.canvas.figure,
         'ax':
         self.canvas.figure.gca(),
         'D': [item for group in session.groups for item in group.items],
     })
     w.show()
Exemplo n.º 7
0
 def load_session(self, filename=None):
     if not filename:
         # Recent files action
         action = self.sender()
         if isinstance(action, QAction):
             if not self.check_save():
                 return
             filename = action.data()
     try:
         session.load(filename)
         with self.sgroup as settings:
             settings.setValue('loadfiledirectory', path.dirname(filename))
     except Exception as err:
         logger.exception('Loading session %r failed' % filename)
         QMessageBox.warning(self, 'Error', 'Loading failed: %s' % err)
     else:
         self.re_expand_tree()
         self.setWindowModified(False)
         # if there are annotations, show the window automatically
         if session.props.get('annotations'):
             self.on_actionAnnotations_triggered()
Exemplo n.º 8
0
    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))