コード例 #1
0
    def onCustomContextMenu(self, point):
        """
        Displays the context menu for whatever is under the supplied point.
        """
        item = self.tree.itemAt(point)
        if not item:
            return
        cm = QMenu(self.tree)
        if item.type() == self.SignalType:
            sig = item.data(NameCol, Qt.UserRole)

            # Add all actions defined on object
            for ac in sig.actions.values():
                cm.addAction(ac)

        elif item.type() == self.ModelType:
            model = item.data(NameCol, Qt.UserRole)

            # Add all actions defined on object
            for ac in model.actions.values():
                cm.addAction(ac)

            # Add "add component" actions
            cm.addSeparator()
            comp_actions = create_add_component_actions(self.tree,
                                                        model.add_component,
                                                        prefix="Add ")
            for ac in comp_actions.values():
                cm.addAction(ac)
        elif item.type() == self.ComponentType:
            comp = item.data(NameCol, Qt.UserRole)
            model = item.parent().data(NameCol, Qt.UserRole)

            # Fit action
            ac = QAction(tr("&Fit component"), self.tree)
            f = partial(model.fit_component, comp)
            self.connect(ac, SIGNAL('triggered()'), f)
            cm.addAction(ac)

            # Configure action
            ac = QAction(tr("&Configure"), self.tree)
            f = partial(self.edit_traits, comp)
            ac.triggered.connect(f)
            cm.addAction(ac)

            cm.addSeparator()

            # Remove action
            ac = QAction(tr("&Delete"), self.tree)
            f = partial(model.remove_component, comp)
            self.connect(ac, SIGNAL('triggered()'), f)
            cm.addAction(ac)
        cm.exec_(self.tree.mapToGlobal(point))
コード例 #2
0
ファイル: dataviewwidget.py プロジェクト: hyperspy/hyperspyUI
    def onCustomContextMenu(self, point):
        """
        Displays the context menu for whatever is under the supplied point.
        """
        item = self.tree.itemAt(point)
        if not item:
            return
        cm = QtWidgets.QMenu(self.tree)
        if item.type() == self.SignalType:
            sig = item.data(NameCol, Qt.UserRole)

            # Add all actions defined on object
            for ac in sig.actions.values():
                cm.addAction(ac)

        elif item.type() == self.ModelType:
            model = item.data(NameCol, Qt.UserRole)

            # Add all actions defined on object
            for ac in model.actions.values():
                cm.addAction(ac)

            # Add "add component" actions
            cm.addSeparator()
            comp_actions = create_add_component_actions(self.tree,
                                                        model.add_component,
                                                        prefix="Add ")
            for ac in comp_actions.values():
                cm.addAction(ac)
        elif item.type() == self.ComponentType:
            comp = item.data(NameCol, Qt.UserRole)
            model = item.parent().data(NameCol, Qt.UserRole)

            # Fit action
            ac = QtWidgets.QAction(tr("&Fit component"), self.tree)
            f = partial(model.fit_component, comp)
            ac.triggered.connect(f)
            cm.addAction(ac)

            # Configure action
            ac = QtWidgets.QAction(tr("&Configure"), self.tree)
            f = partial(self.edit_traits, comp)
            ac.triggered.connect(f)
            cm.addAction(ac)

            cm.addSeparator()

            # Remove action
            ac = QtWidgets.QAction(tr("&Delete"), self.tree)
            f = partial(model.remove_component, comp)
            ac.triggered.connect(f)
            cm.addAction(ac)
        cm.exec_(self.tree.mapToGlobal(point))
コード例 #3
0
ファイル: mainwindow.py プロジェクト: hyperspy/hyperspyUI
    def create_default_actions(self):
        super(MainWindow, self).create_default_actions()

        # Files:
        self.add_action('open', "&Open", self.load,
                        shortcut=QtGui.QKeySequence.Open,
                        icon='open.svg',
                        tip="Open existing file(s)")
        self.add_action('open_stack', "Open S&tack", self.load_stack,
                        tip="Open files and combine into one signal (stacked)")
        self.add_action('close', "&Close", self.close_signal,
                        shortcut=QtGui.QKeySequence.Close,
                        icon='close_window.svg',
                        selection_callback=self.select_signal,
                        tip="Close the selected signal(s)")
        self.add_action('new_editor', "&New editor", self.new_editor,
                        shortcut=QtGui.QKeySequence.New,
                        tip="Opens a new code editor")

        close_all_key = QtGui.QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_F4,
                                           Qt.CTRL + Qt.ALT + Qt.Key_W)
        self.add_action('close_all', "&Close All", self.close_all_signals,
                        shortcut=close_all_key,
                        icon='close_windows.svg',
                        tip="Close all signals")
        self.add_action('exit', "E&xit", self.close,
                        shortcut=QtGui.QKeySequence.Quit,
                        tip="Exits the application")

        # I/O:
        self.add_action('save', "&Save", self.save,
                        shortcut=QtGui.QKeySequence.Save,
                        icon='save.svg',
                        selection_callback=self.select_signal,
                        tip="Save the selected signal(s)")
        self.add_action('save_fig', "Save &figure", self.save_figure,
                        tip="Save the active figure")

        self.add_action('add_model', "Create Model", self.add_model,
                        selection_callback=self.select_signal,
                        tip="Create a model for the selected signal")

        # Settings:
        self.add_action('plugin_manager', "Plugin manager",
                        self.show_plugin_manager,
                        tip="Show the plugin manager")
        self.add_action('hspy_settings', "HyperSpy settings",
                        self.edit_hspy_settings,
                        tip="Edit the HyperSpy package settings")
        self.add_action('edit_settings', "Edit settings", self.edit_settings,
                        tip="Edit the application and plugins settings")

        # Help:
        self.add_action('documentation', "Documentation",
                        self.open_documentation,
                        tip="Open the HyperSpyUI documentation in a browser.")

        # --- Add signal type selection actions ---
        signal_type_ag = QtWidgets.QActionGroup(self)
        signal_type_ag.setExclusive(True)
        for st in self.signal_types.keys():
            f = partial(self.set_signal_type, st)
            st_ac = self.add_action('signal_type_' + st, st, f)
            st_ac.setCheckable(True)
            signal_type_ag.addAction(st_ac)
        self.signal_type_ag = signal_type_ag

        # --- Add signal data type selection actions ---
        signal_datatype_ag = QtWidgets.QActionGroup(self)
        signal_datatype_ag.setExclusive(True)
        import numpy as np
        for t in [np.bool, np.bool8, np.byte, np.complex, np.complex64,
                  np.complex128, np.float, np.float16, np.float32, np.float64,
                  np.int, np.int8, np.int16, np.int32, np.int64, np.long,
                  np.uint, np.uint8, np.uint16, np.uint32, np.uint64, 'Custom'
                  ]:
            f = partial(self.set_signal_dtype, t)
            if isinstance(t, str):
                st = t.lower()
            else:
                st = t.__name__

            sdt_ac = self.add_action('signal_data_type_' + st, st, f)
            sdt_ac.setCheckable(True)
            signal_datatype_ag.addAction(sdt_ac)
        self.signal_datatype_ag = signal_datatype_ag

        # Start disabled until a valid figure is selected
        self.signal_type_ag.setEnabled(False)
        self.signal_datatype_ag.setEnabled(False)

        # --- Add "add component" actions ---
        comp_actions = create_add_component_actions(self, self.make_component)
        self.comp_actions = []
        for ac_name, ac in comp_actions.items():
            self.actions[ac_name] = ac
            self.comp_actions.append(ac_name)
            self._action_selection_cbs[ac_name] = self._check_add_component_ok
            ac.setEnabled(False)
コード例 #4
0
    def create_default_actions(self):
        super(MainWindow, self).create_default_actions()

        # Files:
        self.add_action('open',
                        "&Open",
                        self.load,
                        shortcut=QtGui.QKeySequence.Open,
                        icon='open.svg',
                        tip="Open existing file(s)")
        self.add_action('open_stack',
                        "Open S&tack",
                        self.load_stack,
                        tip="Open files and combine into one signal (stacked)")
        self.add_action('close',
                        "&Close",
                        self.close_signal,
                        shortcut=QtGui.QKeySequence.Close,
                        icon='close_window.svg',
                        selection_callback=self.select_signal,
                        tip="Close the selected signal(s)")
        self.add_action('new_editor',
                        "&New editor",
                        self.new_editor,
                        shortcut=QtGui.QKeySequence.New,
                        tip="Opens a new code editor")

        close_all_key = QtGui.QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_F4,
                                           Qt.CTRL + Qt.ALT + Qt.Key_W)
        self.add_action('close_all',
                        "&Close All",
                        self.close_all_signals,
                        shortcut=close_all_key,
                        icon='close_windows.svg',
                        tip="Close all signals")
        self.add_action('exit',
                        "E&xit",
                        self.close,
                        shortcut=QtGui.QKeySequence.Quit,
                        tip="Exits the application")

        # I/O:
        self.add_action('save',
                        "&Save",
                        self.save,
                        shortcut=QtGui.QKeySequence.Save,
                        icon='save.svg',
                        selection_callback=self.select_signal,
                        tip="Save the selected signal(s)")
        self.add_action('save_fig',
                        "Save &figure",
                        self.save_figure,
                        tip="Save the active figure")

        self.add_action('add_model',
                        "Create Model",
                        self.add_model,
                        selection_callback=self.select_signal,
                        tip="Create a model for the selected signal")

        # Settings:
        self.add_action('plugin_manager',
                        "Plugin manager",
                        self.show_plugin_manager,
                        tip="Show the plugin manager")
        self.add_action('hspy_settings',
                        "HyperSpy settings",
                        self.edit_hspy_settings,
                        tip="Edit the HyperSpy package settings")
        self.add_action('edit_settings',
                        "Edit settings",
                        self.edit_settings,
                        tip="Edit the application and plugins settings")

        # Help:
        self.add_action('documentation',
                        "Documentation",
                        self.open_documentation,
                        tip="Open the HyperSpyUI documentation in a browser.")

        # --- Add signal type selection actions ---
        signal_type_ag = QtWidgets.QActionGroup(self)
        signal_type_ag.setExclusive(True)
        for st in self.signal_types.keys():
            f = partial(self.set_signal_type, st)
            st_ac = self.add_action('signal_type_' + st, st, f)
            st_ac.setCheckable(True)
            signal_type_ag.addAction(st_ac)
        self.signal_type_ag = signal_type_ag

        # --- Add signal data type selection actions ---
        signal_datatype_ag = QtWidgets.QActionGroup(self)
        signal_datatype_ag.setExclusive(True)
        import numpy as np
        for t in [
                np.bool, np.bool8, np.byte, np.complex, np.complex64,
                np.complex128, np.float, np.float16, np.float32, np.float64,
                np.int, np.int8, np.int16, np.int32, np.int64, np.long,
                np.uint, np.uint8, np.uint16, np.uint32, np.uint64, 'Custom'
        ]:
            f = partial(self.set_signal_dtype, t)
            if isinstance(t, str):
                st = t.lower()
            else:
                st = t.__name__

            sdt_ac = self.add_action('signal_data_type_' + st, st, f)
            sdt_ac.setCheckable(True)
            signal_datatype_ag.addAction(sdt_ac)
        self.signal_datatype_ag = signal_datatype_ag

        # Start disabled until a valid figure is selected
        self.signal_type_ag.setEnabled(False)
        self.signal_datatype_ag.setEnabled(False)

        # --- Add "add component" actions ---
        comp_actions = create_add_component_actions(self, self.make_component)
        self.comp_actions = []
        for ac_name, ac in comp_actions.items():
            self.actions[ac_name] = ac
            self.comp_actions.append(ac_name)
            self._action_selection_cbs[ac_name] = self._check_add_component_ok
            ac.setEnabled(False)