예제 #1
0
    def load(self, filenames=None):
        """
        Load 'filenames', or if 'filenames' is None, open a dialog to let the
        user interactively browse for files. It then load these files using
        hyperspy.io.load and wraps them and adds them to self.signals.
        """

        import hyperspy.io
        if filenames is None:
            extensions = self.get_accepted_extensions()
            type_choices = ';;'.join(["*." + e for e in extensions])
            type_choices = ';;'.join(("Python code (*.py)", type_choices))
            type_choices = ';;'.join(("All types (*.*)", type_choices))
            filenames = self.prompt_files(type_choices)
            if not filenames:
                return False
            self.cur_dir = filenames[0]

        files_loaded = []
        for filename in filenames:
            self.set_status("Loading \"" + filename + "\"...")
            ext = os.path.splitext(filename)[1]
            if ext == '.py':
                e = EditorWidget(self, self, filename)
                self.editors.append(e)
                e.show()
                files_loaded.append(filename)
                continue
            self.setUpdatesEnabled(False)   # Prevent flickering during load
            try:
                escaped = glob_escape.sub(r'[\1]', filename)    # glob escapes
                sig = hyperspy.io.load(escaped)
                if isinstance(sig, list):
                    for s in sig:
                        s.plot()
                else:
                    sig.plot()
                files_loaded.append(filename)
            except (IOError, ValueError) as e:
                self.set_status("Failed to load \"" + filename + "\"")
                exc_type, exc_value, exc_traceback = sys.exc_info()
                tb = traceback.extract_tb(exc_traceback)[-1]
                warnings.warn_explicit(
                    ("Failed to load file '%s'. Internal exception:\n %s: %s"
                     % (filename, exc_type.__name__, str(e))),
                    RuntimeWarning, tb[0], tb[1])
            finally:
                self.setUpdatesEnabled(True)    # Always resume updates!

        if len(files_loaded) == 1:
            self.set_status("Loaded \"" + files_loaded[0] + "\"")
        elif len(files_loaded) > 1:
            self.set_status("Loaded %d files" % len(files_loaded))
        self.record_code('ui.load({0})'.format(files_loaded))

        return files_loaded
예제 #2
0
 def start_recording(self):
     self.btn_start.setEnabled(False)
     self.btn_stop.setEnabled(True)
     r = Recorder()
     self.recorder = r
     self.update_filter()
     self.ui.recorders.append(r)
     e = EditorWidget(self.ui, self.ui)
     e.setWindowTitle(tr("Recorded Code"))
     self.editor = e
     self.ui.editors.append(e)
     r.record.connect(e.append_code)
     self.editor.finished.connect(lambda: self.ui.editors.remove(e))
     self.editor.finished.connect(lambda: self.disconnect_editor(e))
     e.show()
예제 #3
0
 def start_recording(self):
     self.btn_start.setEnabled(False)
     self.btn_stop.setEnabled(True)
     r = Recorder()
     self.recorder = r
     self.update_filter()
     self.ui.recorders.append(r)
     e = EditorWidget(self.ui, self.ui)
     e.setWindowTitle(tr("Recorded Code"))
     self.editor = e
     self.ui.editors.append(e)
     r.record.connect(e.append_code)
     self.editor.finished.connect(lambda: self.ui.editors.remove(e))
     self.editor.finished.connect(lambda: self.disconnect_editor(e))
     e.show()
예제 #4
0
 def new_editor(self):
     e = EditorWidget(self, self)
     self.editors.append(e)
     e.show()
예제 #5
0
 def new_editor(self):
     e = EditorWidget(self, self)
     self.editors.append(e)
     e.show()