コード例 #1
0
ファイル: mainwindow.py プロジェクト: DanNixon/mantid
    def create_actions(self):
        # --- general application menu options --
        # file menu
        action_open = create_action(self, "Open",
                                    on_triggered=self.open_file,
                                    shortcut="Ctrl+O",
                                    shortcut_context=Qt.ApplicationShortcut,
                                    icon_name="fa.folder-open")
        action_save = create_action(self, "Save",
                                    on_triggered=self.save_file,
                                    shortcut="Ctrl+S",
                                    shortcut_context=Qt.ApplicationShortcut,
                                    icon_name="fa.save")
        action_manage_directories = create_action(self, "Manage User Directories",
                                                  on_triggered=self.open_manage_directories,
                                                  icon_name="fa.folder")

        action_quit = create_action(self, "&Quit", on_triggered=self.close,
                                    shortcut="Ctrl+Q",
                                    shortcut_context=Qt.ApplicationShortcut,
                                    icon_name="fa.power-off")
        self.file_menu_actions = [action_open, action_save, action_manage_directories, None, action_quit]

        # view menu
        action_restore_default = create_action(self, "Restore Default Layout",
                                               on_triggered=self.prep_window_for_reset,
                                               shortcut="Shift+F10",
                                               shortcut_context=Qt.ApplicationShortcut)
        self.view_menu_actions = [action_restore_default, None] + self.create_widget_actions()
コード例 #2
0
ファイル: mainwindow.py プロジェクト: ess-dmsc-dram/mantid
    def create_actions(self):
        # --- general application menu options --
        # file menu
        action_open = create_action(self, "Open",
                                    on_triggered=self.open_file,
                                    shortcut="Ctrl+O",
                                    shortcut_context=Qt.ApplicationShortcut,
                                    icon_name="fa.folder-open")
        action_save = create_action(self, "Save",
                                    on_triggered=self.save_file,
                                    shortcut="Ctrl+S",
                                    shortcut_context=Qt.ApplicationShortcut,
                                    icon_name="fa.save")
        action_manage_directories = create_action(self, "Manage User Directories",
                                                  on_triggered=self.open_manage_directories,
                                                  icon_name="fa.folder")

        action_quit = create_action(self, "&Quit", on_triggered=self.close,
                                    shortcut="Ctrl+Q",
                                    shortcut_context=Qt.ApplicationShortcut,
                                    icon_name="fa.power-off")
        self.file_menu_actions = [action_open, action_save, action_manage_directories, None, action_quit]

        # view menu
        action_restore_default = create_action(self, "Restore Default Layout",
                                               on_triggered=self.prep_window_for_reset,
                                               shortcut="Shift+F10",
                                               shortcut_context=Qt.ApplicationShortcut)
        self.view_menu_actions = [action_restore_default, None] + self.create_widget_actions()
コード例 #3
0
 def test_add_actions_with_qtoolbar_target(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = create_action(None, "Test Action 2")
     test_toolbar = QToolBar()
     # There seems to be no easy access to check the size of the list
     # so check the number of children increases by 2
     nchildren_before = len(test_toolbar.children())
     add_actions(test_toolbar, [test_act_1, test_act_2])
     self.assertEquals(nchildren_before + 2, len(test_toolbar.children()))
コード例 #4
0
 def test_add_actions_with_qtoolbar_target(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = create_action(None, "Test Action 2")
     test_toolbar = QToolBar()
     # There seems to be no easy access to check the size of the list
     # so check the number of children increases by 2
     nchildren_before = len(test_toolbar.children())
     add_actions(test_toolbar, [test_act_1, test_act_2])
     self.assertEquals(nchildren_before + 2, len(test_toolbar.children()))
コード例 #5
0
    def __init__(self, parent, presenter):
        super(EmbeddedFindReplaceDialogView, self).__init__(parent)
        self.setupUi(self)
        self.resize(self.width(), 100)

        self.find.completer().setCaseSensitivity(Qt.CaseSensitive)
        self.replace.completer().setCaseSensitivity(Qt.CaseSensitive)

        self.presenter = presenter

        self.hide_find_replace = create_action(
            self, '', on_triggered=self.presenter.hide, shortcut=Qt.Key_Escape)
        self.addAction(self.hide_find_replace)

        self.enter_to_search = create_action(
            self,
            '',
            on_triggered=self.presenter.action_next,
            shortcut=[Qt.Key_Return, Qt.Key_Enter])
        self.addAction(self.enter_to_search)

        self.shift_enter_to_search_backwards = create_action(
            self,
            '',
            on_triggered=self.presenter.action_previous,
            shortcut=["Shift+Enter", "Shift+Return"])
        self.addAction(self.shift_enter_to_search_backwards)

        self.find.lineEdit().setPlaceholderText("Find")
        self.replace.lineEdit().setPlaceholderText("Replace with")

        self.setAttribute(Qt.WA_DeleteOnClose, True)

        arrow_up_icon = get_icon("mdi.arrow-up")
        arrow_down_icon = get_icon("mdi.arrow-down")
        x_icon = get_icon("mdi.close")

        self.next_button.setIcon(arrow_down_icon)
        self.previous_button.setIcon(arrow_up_icon)
        self.close_button.setIcon(x_icon)

        self.next_button.clicked.connect(self.presenter.action_next)
        self.previous_button.clicked.connect(self.presenter.action_previous)

        self.close_button.clicked.connect(self.presenter.action_close_button)

        self.replace_button.clicked.connect(self.presenter.action_replace)
        self.replace_all_button.clicked.connect(
            self.presenter.action_replace_all)

        self.find.currentTextChanged.connect(self.presenter.clear_search)
        self.match_case.stateChanged.connect(self.presenter.clear_search)
        self.words.stateChanged.connect(self.presenter.clear_search)
        self.regex.stateChanged.connect(self.presenter.clear_search)
        self.wrap_around.stateChanged.connect(self.presenter.clear_search)
コード例 #6
0
ファイル: view.py プロジェクト: mantidproject/mantid
    def __init__(self, parent, presenter):
        super(EmbeddedFindReplaceDialogView, self).__init__(parent)
        self.setupUi(self)
        self.resize(self.width(), 100)

        self.find.completer().setCaseSensitivity(Qt.CaseSensitive)
        self.replace.completer().setCaseSensitivity(Qt.CaseSensitive)

        self.presenter = presenter

        self.hide_find_replace = create_action(self, '',
                                               on_triggered=self.presenter.hide,
                                               shortcut=Qt.Key_Escape)
        self.addAction(self.hide_find_replace)

        self.enter_to_search = create_action(self, '',
                                             on_triggered=self.presenter.action_next,
                                             shortcut=[Qt.Key_Return, Qt.Key_Enter])
        self.addAction(self.enter_to_search)

        self.shift_enter_to_search_backwards = create_action(self, '',
                                                             on_triggered=self.presenter.action_previous,
                                                             shortcut=["Shift+Enter", "Shift+Return"])
        self.addAction(self.shift_enter_to_search_backwards)

        self.find.lineEdit().setPlaceholderText("Find")
        self.replace.lineEdit().setPlaceholderText("Replace with")

        self.setAttribute(Qt.WA_DeleteOnClose, True)

        arrow_up_icon = get_icon("mdi.arrow-up")
        arrow_down_icon = get_icon("mdi.arrow-down")
        x_icon = get_icon("mdi.close")

        self.next_button.setIcon(arrow_down_icon)
        self.previous_button.setIcon(arrow_up_icon)
        self.close_button.setIcon(x_icon)

        self.next_button.clicked.connect(self.presenter.action_next)
        self.previous_button.clicked.connect(self.presenter.action_previous)

        self.close_button.clicked.connect(self.presenter.action_close_button)

        self.replace_button.clicked.connect(self.presenter.action_replace)
        self.replace_all_button.clicked.connect(self.presenter.action_replace_all)

        self.find.currentTextChanged.connect(self.presenter.clear_search)
        self.match_case.stateChanged.connect(self.presenter.clear_search)
        self.words.stateChanged.connect(self.presenter.clear_search)
        self.regex.stateChanged.connect(self.presenter.clear_search)
        self.wrap_around.stateChanged.connect(self.presenter.clear_search)
コード例 #7
0
ファイル: mainwindow.py プロジェクト: samueljackson92/mantid
    def create_actions(self):
        # --- general application menu options --
        # file menu
        action_open = create_action(self, "Open Script",
                                    on_triggered=self.open_file,
                                    shortcut="Ctrl+O",
                                    shortcut_context=Qt.ApplicationShortcut)
        action_load_project = create_action(self, "Open Project",
                                            on_triggered=self.load_project)
        action_save_script = create_action(self, "Save Script",
                                           on_triggered=self.save_script,
                                           shortcut="Ctrl+S",
                                           shortcut_context=Qt.ApplicationShortcut)
        action_save_project = create_action(self, "Save Project",
                                            on_triggered=self.save_project)
        action_save_project_as = create_action(self, "Save Project as...",
                                               on_triggered=self.save_project_as)

        action_manage_directories = create_action(self, "Manage User Directories",
                                                  on_triggered=self.open_manage_directories)

        action_quit = create_action(self, "&Quit", on_triggered=self.close,
                                    shortcut="Ctrl+Q",
                                    shortcut_context=Qt.ApplicationShortcut)
        self.file_menu_actions = [action_open, action_load_project, None, action_save_script, action_save_project,
                                  action_save_project_as, None, action_manage_directories, None, action_quit]
        # view menu
        action_restore_default = create_action(self, "Restore Default Layout",
                                               on_triggered=self.prep_window_for_reset,
                                               shortcut="Shift+F10",
                                               shortcut_context=Qt.ApplicationShortcut)
        self.view_menu_actions = [action_restore_default, None] + self.create_widget_actions()
コード例 #8
0
    def populate_menu(self):
        # Check cache is present or don't do anything.
        scripts = self._get_scripts_from_settings()

        if len(scripts) > 0:
            for script_path in scripts:
                script_name = self.size_path_correctly(script_path)
                new_action = create_action(parent=self.mainwindow,
                                           text=script_name,
                                           on_triggered=functools.partial(
                                               self.open_script, script_path))
                self.addAction(new_action)
        else:
            self.addAction(
                create_action(parent=self.mainwindow,
                              text="No recently closed scripts found"))
コード例 #9
0
ファイル: test_qt_utils.py プロジェクト: JoachimCoenen/mantid
 def test_multiple_shortcuts_are_set_if_given(self):
     expected_shortcuts = ("Ctrl+S", "Ctrl+W")
     action = create_action(None,
                            "Test Action",
                            shortcut=expected_shortcuts)
     for expected, actual in zip(expected_shortcuts, action.shortcuts()):
         self.assertEqual(expected, actual.toString())
コード例 #10
0
 def test_parent_and_name_only_required(self):
     class Parent(QObject):
         pass
     parent = Parent()
     action = create_action(parent, "Test Action")
     self.assertTrue(isinstance(action, QAction))
     self.assertEquals(parent, action.parent())
コード例 #11
0
 def test_parent_and_name_only_required(self):
     class Parent(QObject):
         pass
     parent = Parent()
     action = create_action(parent, "Test Action")
     self.assertTrue(isinstance(action, QAction))
     self.assertEquals(parent, action.parent())
コード例 #12
0
ファイル: editor.py プロジェクト: samueljackson92/mantid
    def __init__(self, parent):
        super(MultiFileEditor, self).__init__(parent)

        # layout
        self.editors = MultiPythonFileInterpreter(default_content=DEFAULT_CONTENT,
                                                  parent=self)
        layout = QVBoxLayout()
        layout.addWidget(self.editors)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        # attributes
        self.run_action = create_action(self, "Run",
                                        on_triggered=self.editors.execute_current,
                                        shortcut="Ctrl+Return",
                                        shortcut_context=Qt.ApplicationShortcut)
        self.abort_action = create_action(self, "Abort",
                                          on_triggered=self.editors.abort_current)

        self.editor_actions = [self.run_action, self.abort_action]
コード例 #13
0
 def test_supplied_triggered_callback_attaches_to_triggered_signal(self):
     class Receiver(QObject):
         @Slot()
         def test_slot(self):
             pass
     recv = Receiver()
     action = create_action(None, "Test Action", on_triggered=recv.test_slot)
     if NEW_STYLE_SIGNAL:
         self.assertEqual(1, action.receivers(action.triggered))
     else:
         self.assertEqual(1, action.receivers(SIGNAL("triggered()")))
コード例 #14
0
 def test_supplied_triggered_callback_attaches_to_triggered_signal(self):
     class Receiver(QObject):
         @Slot()
         def test_slot(self):
             pass
     recv = Receiver()
     action = create_action(None, "Test Action", on_triggered=recv.test_slot)
     if NEW_STYLE_SIGNAL:
         self.assertEqual(1, action.receivers(action.triggered))
     else:
         self.assertEqual(1, action.receivers(SIGNAL("triggered()")))
コード例 #15
0
    def __init__(self, parent):
        super(MultiFileEditor, self).__init__(parent)

        # layout
        self.editors = MultiPythonFileInterpreter(
            default_content=DEFAULT_CONTENT, parent=self)
        layout = QVBoxLayout()
        layout.addWidget(self.editors)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        # attributes
        self.run_action = create_action(
            self,
            "Run",
            on_triggered=self.editors.execute_current,
            shortcut="Ctrl+Return",
            shortcut_context=Qt.ApplicationShortcut)
        self.abort_action = create_action(
            self, "Abort", on_triggered=self.editors.abort_current)

        self.editor_actions = [self.run_action, self.abort_action]
コード例 #16
0
    def create_actions(self):
        # --- general application menu options --
        # file menu
        action_open = create_action(self,
                                    "Open Script",
                                    on_triggered=self.open_file,
                                    shortcut="Ctrl+O",
                                    shortcut_context=Qt.ApplicationShortcut)
        action_load_project = create_action(self,
                                            "Open Project",
                                            on_triggered=self.load_project)
        action_save_script = create_action(
            self,
            "Save Script",
            on_triggered=self.save_script,
            shortcut="Ctrl+S",
            shortcut_context=Qt.ApplicationShortcut)
        action_save_project = create_action(self,
                                            "Save Project",
                                            on_triggered=self.save_project)
        action_save_project_as = create_action(
            self, "Save Project as...", on_triggered=self.save_project_as)

        action_manage_directories = create_action(
            self,
            "Manage User Directories",
            on_triggered=self.open_manage_directories)

        action_quit = create_action(self,
                                    "&Quit",
                                    on_triggered=self.close,
                                    shortcut="Ctrl+Q",
                                    shortcut_context=Qt.ApplicationShortcut)
        self.file_menu_actions = [
            action_open, action_load_project, None, action_save_script,
            action_save_project, action_save_project_as, None,
            action_manage_directories, None, action_quit
        ]
        # view menu
        action_restore_default = create_action(
            self,
            "Restore Default Layout",
            on_triggered=self.prep_window_for_reset,
            shortcut="Shift+F10",
            shortcut_context=Qt.ApplicationShortcut)
        self.view_menu_actions = [action_restore_default, None
                                  ] + self.create_widget_actions()
コード例 #17
0
    def populate_layout_menu(self):
        self.view_menu_layouts.clear()
        try:
            layout_dict = CONF.get("MainWindow/user_layouts")
        except KeyError:
            layout_dict = {}
        layout_keys = sorted(layout_dict.keys())
        layout_options = []
        for item in layout_keys:
            layout_options.append(self.create_load_layout_action(item, layout_dict[item]))
        layout_options.append(None)
        action_settings = create_action(
            self, "Settings", on_triggered=self.open_settings_layout_window)
        layout_options.append(action_settings)

        add_actions(self.view_menu_layouts, layout_options)
コード例 #18
0
ファイル: mainwindow.py プロジェクト: JoachimCoenen/mantid
    def create_actions(self):
        # --- general application menu options --
        # file menu
        action_open = create_action(
            self, "Open Script", on_triggered=self.open_file,
            shortcut="Ctrl+O", shortcut_context=Qt.ApplicationShortcut)
        action_load_project = create_action(
            self, "Open Project", on_triggered=self.load_project)
        action_save_script = create_action(
            self, "Save Script", on_triggered=self.save_script,
            shortcut="Ctrl+S", shortcut_context=Qt.ApplicationShortcut)
        action_save_script_as = create_action(
            self, "Save Script as...", on_triggered=self.save_script_as)
        action_save_project = create_action(
            self, "Save Project", on_triggered=self.save_project)
        action_save_project_as = create_action(
            self, "Save Project as...", on_triggered=self.save_project_as)
        action_manage_directories = create_action(
            self, "Manage User Directories",
            on_triggered=self.open_manage_directories)
        action_settings = create_action(
            self, "Settings", on_triggered=self.open_settings_window)
        action_quit = create_action(
            self, "&Quit", on_triggered=self.close, shortcut="Ctrl+Q",
            shortcut_context=Qt.ApplicationShortcut)
        self.file_menu_actions = [action_open, action_load_project, None,
                                  action_save_script, action_save_script_as,
                                  action_save_project, action_save_project_as,
                                  None, action_settings, None,
                                  action_manage_directories, None, action_quit]
        # view menu
        action_restore_default = create_action(
            self, "Restore Default Layout",
            on_triggered=self.prep_window_for_reset,
            shortcut="Shift+F10", shortcut_context=Qt.ApplicationShortcut)

        self.view_menu_actions = [action_restore_default, None] + self.create_widget_actions()

        # help menu
        action_mantid_help = create_action(
            self, "Mantid Help", on_triggered=self.open_mantid_help,
            shortcut='F1', shortcut_context=Qt.ApplicationShortcut)
        action_algorithm_descriptions = create_action(
            self, 'Algorithm Descriptions',
            on_triggered=self.open_algorithm_descriptions_help)
        action_mantid_concepts = create_action(
            self, "Mantid Concepts", on_triggered=self.open_mantid_concepts_help)
        action_mantid_homepage = create_action(
            self, "Mantid Homepage", on_triggered=self.open_mantid_homepage)
        action_mantid_forum = create_action(
            self, "Mantid Forum", on_triggered=self.open_mantid_forum)

        self.help_menu_actions = [
            action_mantid_help, action_mantid_concepts,
            action_algorithm_descriptions, None,
            action_mantid_homepage, action_mantid_forum]
コード例 #19
0
 def test_add_actions_with_invalid_parameter_raises_value_error(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = QObject()
     test_toolbar = QToolBar()
     self.assertRaises(ValueError, add_actions, test_toolbar, [test_act_1, test_act_2])
コード例 #20
0
 def test_add_actions_with_bad_target_raises_attribute_error(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = create_action(None, "Test Action 2")
     test_toolbar = QObject()
     self.assertRaises(AttributeError, add_actions, test_toolbar, [test_act_1, test_act_2])
コード例 #21
0
ファイル: test_qt_utils.py プロジェクト: mantidproject/mantid
 def test_multiple_shortcuts_are_set_if_given(self):
     expected_shortcuts = ("Ctrl+S", "Ctrl+W")
     action = create_action(None, "Test Action", shortcut=expected_shortcuts)
     for expected, actual in zip(expected_shortcuts, action.shortcuts()):
         self.assertEqual(expected, actual.toString())
コード例 #22
0
 def test_add_actions_with_qmenu_target(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = create_action(None, "Test Action 2")
     test_menu = QMenu()
     add_actions(test_menu, [test_act_1, test_act_2])
     self.assertFalse(test_menu.isEmpty())
コード例 #23
0
 def test_shortcut_is_set_if_given(self):
     action = create_action(None, "Test Action", shortcut="Ctrl+S")
     self.assertEqual("Ctrl+S", action.shortcut())
コード例 #24
0
ファイル: mainwindow.py プロジェクト: arezooamirpour/mantid
 def create_load_layout_action(self, layout_name, layout):
     action_load_layout = create_action(
         self, layout_name, on_triggered=lambda: self.restoreState(layout))
     return action_load_layout
コード例 #25
0
    def setup_options_actions(self, parent):
        """
        Setup the actions for the Options menu. The actions are handled by the parent widget
        """
        container_widget = QWidget(self)
        layout = QHBoxLayout(container_widget)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        container_widget.setLayout(layout)
        self.setCornerWidget(container_widget, Qt.TopRightCorner)

        run_button = QPushButton(container_widget)
        run_button.setObjectName(self.RUN_BUTTON_OBJECT_NAME)
        run_button.setIcon(get_icon("mdi.play", PLAY_BUTTON_GREEN_COLOR, 1.6))
        run_button.clicked.connect(parent.execute_current_async)
        layout.addWidget(run_button)

        abort_button = QPushButton(container_widget)
        abort_button.setObjectName(self.ABORT_BUTTON_OBJECT_NAME)
        abort_button.setIcon(
            get_icon("mdi.square", ABORT_BUTTON_RED_COLOR, 1.1))
        abort_button.clicked.connect(parent.abort_current)
        layout.addWidget(abort_button)

        options_button = QPushButton(container_widget)
        options_button.setObjectName(self.OPTIONS_BUTTON_OBJECT_NAME)
        options_button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        options_button.setText("Options")

        options_menu = QMenu("", self)
        options_button.setMenu(options_menu)
        layout.addWidget(options_button)

        self.tabCloseRequested.connect(parent.close_tab)

        run_action = create_action(self,
                                   "Run",
                                   on_triggered=parent.execute_current_async,
                                   shortcut=("Ctrl+Enter", "Ctrl+Return"),
                                   shortcut_context=Qt.ApplicationShortcut,
                                   shortcut_visible_in_context_menu=True)

        run_all_action = create_action(self,
                                       "Run All",
                                       on_triggered=parent.execute_async,
                                       shortcut=("Ctrl+Shift+Enter",
                                                 "Ctrl+Shift+Return"),
                                       shortcut_context=Qt.ApplicationShortcut,
                                       shortcut_visible_in_context_menu=True)

        abort_action = create_action(self,
                                     "Abort",
                                     on_triggered=parent.abort_current,
                                     shortcut="Ctrl+D",
                                     shortcut_context=Qt.ApplicationShortcut,
                                     shortcut_visible_in_context_menu=True)

        # menu action to toggle the find/replace dialog
        toggle_find_replace = create_action(
            self,
            'Find/Replace...',
            on_triggered=parent.toggle_find_replace_dialog,
            shortcut='Ctrl+F',
            shortcut_visible_in_context_menu=True)

        toggle_comment_action = create_action(
            self,
            "Comment/Uncomment",
            on_triggered=parent.toggle_comment_current,
            shortcut="Ctrl+/",
            shortcut_context=Qt.ApplicationShortcut,
            shortcut_visible_in_context_menu=True)

        tabs_to_spaces_action = create_action(
            self,
            'Tabs to Spaces',
            on_triggered=parent.tabs_to_spaces_current,
            shortcut_visible_in_context_menu=True)

        spaces_to_tabs_action = create_action(
            self,
            'Spaces to Tabs',
            on_triggered=parent.spaces_to_tabs_current,
            shortcut_visible_in_context_menu=True)

        toggle_whitespace_action = create_action(
            self,
            'Toggle Whitespace Visible',
            on_triggered=parent.toggle_whitespace_visible_all,
            shortcut_visible_in_context_menu=True)

        # Store actions for adding to menu bar; None will add a separator
        editor_actions = [
            run_action, run_all_action, abort_action, None,
            toggle_find_replace, None, toggle_comment_action,
            toggle_whitespace_action, None, tabs_to_spaces_action,
            spaces_to_tabs_action
        ]

        add_actions(options_menu, editor_actions)
コード例 #26
0
 def test_parent_can_be_none(self):
     action = create_action(None, "Test Action")
     self.assertTrue(isinstance(action, QAction))
     self.assertTrue(action.parent() is None)
コード例 #27
0
ファイル: mainwindow.py プロジェクト: arezooamirpour/mantid
    def create_actions(self):
        # --- general application menu options --
        # file menu
        action_open = create_action(self,
                                    "Open Script",
                                    on_triggered=self.open_file,
                                    shortcut="Ctrl+O",
                                    shortcut_context=Qt.ApplicationShortcut)
        action_load_project = create_action(self,
                                            "Open Project",
                                            on_triggered=self.load_project)
        action_save_script = create_action(
            self,
            "Save Script",
            on_triggered=self.save_script,
            shortcut="Ctrl+S",
            shortcut_context=Qt.ApplicationShortcut)
        action_save_script_as = create_action(self,
                                              "Save Script as...",
                                              on_triggered=self.save_script_as)
        action_generate_ws_script = create_action(
            self,
            "Generate Recovery Script",
            on_triggered=self.generate_script_from_workspaces)
        action_save_project = create_action(self,
                                            "Save Project",
                                            on_triggered=self.save_project)
        action_save_project_as = create_action(
            self, "Save Project as...", on_triggered=self.save_project_as)
        action_manage_directories = create_action(
            self,
            "Manage User Directories",
            on_triggered=self.open_manage_directories)
        action_script_repository = create_action(
            self,
            "Script Repository",
            on_triggered=self.open_script_repository)
        action_settings = create_action(self,
                                        "Settings",
                                        on_triggered=self.open_settings_window)
        action_quit = create_action(self,
                                    "&Quit",
                                    on_triggered=self.close,
                                    shortcut="Ctrl+Q",
                                    shortcut_context=Qt.ApplicationShortcut)
        self.file_menu_actions = [
            action_open, action_load_project, None, action_save_script,
            action_save_script_as, action_generate_ws_script, None,
            action_save_project, action_save_project_as, None, action_settings,
            None, action_manage_directories, None, action_script_repository,
            None, action_quit
        ]

        # view menu
        action_restore_default = create_action(
            self,
            "Restore Default Layout",
            on_triggered=self.setup_default_layouts,
            shortcut="Shift+F10",
            shortcut_context=Qt.ApplicationShortcut)

        self.view_menu_layouts = self.view_menu.addMenu("&User Layouts")
        self.populate_layout_menu()

        self.view_menu_actions = [action_restore_default, None
                                  ] + self.create_widget_actions()

        # help menu
        action_mantid_help = create_action(
            self,
            "Mantid Help",
            on_triggered=self.open_mantid_help,
            shortcut='F1',
            shortcut_context=Qt.ApplicationShortcut)
        action_algorithm_descriptions = create_action(
            self,
            'Algorithm Descriptions',
            on_triggered=self.open_algorithm_descriptions_help)
        action_mantid_concepts = create_action(
            self,
            "Mantid Concepts",
            on_triggered=self.open_mantid_concepts_help)
        action_mantid_homepage = create_action(
            self, "Mantid Homepage", on_triggered=self.open_mantid_homepage)
        action_mantid_forum = create_action(
            self, "Mantid Forum", on_triggered=self.open_mantid_forum)
        action_about = create_action(self,
                                     "About Mantid Workbench",
                                     on_triggered=self.open_about)

        self.help_menu_actions = [
            action_mantid_help, action_mantid_concepts,
            action_algorithm_descriptions, None, action_mantid_homepage,
            action_mantid_forum, None, action_about
        ]
コード例 #28
0
 def test_shortcut_is_set_if_given(self):
     action = create_action(None, "Test Action", shortcut="Ctrl+S")
     self.assertEqual("Ctrl+S", action.shortcut())
コード例 #29
0
 def test_parent_can_be_none(self):
     action = create_action(None, "Test Action")
     self.assertTrue(isinstance(action, QAction))
     self.assertTrue(action.parent() is None)
コード例 #30
0
 def test_add_actions_with_bad_target_raises_attribute_error(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = create_action(None, "Test Action 2")
     test_toolbar = QObject()
     self.assertRaises(AttributeError, add_actions, test_toolbar,
                       [test_act_1, test_act_2])
コード例 #31
0
 def test_shortcut_context_not_used_if_shortcut_given(self):
     action = create_action(None,
                            "Test Action",
                            shortcut_context=Qt.ApplicationShortcut)
     self.assertEqual(Qt.WindowShortcut, action.shortcutContext())
コード例 #32
0
    def __init__(self, parent):
        super(MultiFileEditor, self).__init__(parent)

        # layout
        self.editors = MultiPythonFileInterpreter(
            default_content=DEFAULT_CONTENT, parent=self)
        layout = QVBoxLayout()
        layout.addWidget(self.editors)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        self.setAcceptDrops(True)

        # attributes
        self.tabs_open_on_closing = None

        self.run_action = create_action(
            self,
            "Run",
            on_triggered=self.editors.execute_current,
            shortcut=("Ctrl+Return", "Ctrl+Enter"),
            shortcut_context=Qt.ApplicationShortcut)

        self.abort_action = create_action(
            self, "Abort", on_triggered=self.editors.abort_current)

        # menu action to toggle the find/replace dialog
        self.toggle_find_replace = create_action(
            self,
            'Find/Replace...',
            on_triggered=self.editors.toggle_find_replace_dialog,
            shortcut='Ctrl+F')

        self.toggle_comment_action = create_action(
            self.editors.current_editor(),
            "Comment/Uncomment",
            on_triggered=self.editors.toggle_comment_current,
            shortcut="Ctrl+/",
            shortcut_context=Qt.ApplicationShortcut)

        self.tabs_to_spaces_action = create_action(
            self,
            'Tabs to Spaces',
            on_triggered=self.editors.tabs_to_spaces_current)

        self.spaces_to_tabs_action = create_action(
            self,
            'Spaces to Tabs',
            on_triggered=self.editors.spaces_to_tabs_current)

        self.toggle_whitespace_action = create_action(
            self,
            'Toggle Whitespace Visible',
            on_triggered=self.editors.toggle_whitespace_visible_all)

        # Store actions for adding to menu bar; None will add a separator
        self.editor_actions = [
            self.run_action, self.abort_action, None, self.toggle_find_replace,
            None, self.toggle_comment_action, self.toggle_whitespace_action,
            None, self.tabs_to_spaces_action, self.spaces_to_tabs_action, None
        ]
コード例 #33
0
 def test_shortcut_context_not_used_if_shortcut_given(self):
     action = create_action(None, "Test Action", shortcut_context=Qt.ApplicationShortcut)
     self.assertEqual(Qt.WindowShortcut, action.shortcutContext())
コード例 #34
0
ファイル: mainwindow.py プロジェクト: mantidproject/mantid
    def create_actions(self):
        # --- general application menu options --
        # file menu
        action_open = create_action(
            self, "Open Script", on_triggered=self.open_file,
            shortcut="Ctrl+O", shortcut_context=Qt.ApplicationShortcut)
        action_load_project = create_action(
            self, "Open Project", on_triggered=self.load_project)
        action_save_script = create_action(
            self, "Save Script", on_triggered=self.save_script,
            shortcut="Ctrl+S", shortcut_context=Qt.ApplicationShortcut)
        action_save_script_as = create_action(
            self, "Save Script as...", on_triggered=self.save_script_as)
        action_save_project = create_action(
            self, "Save Project", on_triggered=self.save_project)
        action_save_project_as = create_action(
            self, "Save Project as...", on_triggered=self.save_project_as)
        action_manage_directories = create_action(
            self, "Manage User Directories",
            on_triggered=self.open_manage_directories)
        action_settings = create_action(
            self, "Settings", on_triggered=self.open_settings_window)
        action_quit = create_action(
            self, "&Quit", on_triggered=self.close, shortcut="Ctrl+Q",
            shortcut_context=Qt.ApplicationShortcut)
        self.file_menu_actions = [action_open, action_load_project, None,
                                  action_save_script, action_save_script_as,
                                  action_save_project, action_save_project_as,
                                  None, action_settings, None,
                                  action_manage_directories, None, action_quit]
        # view menu
        action_restore_default = create_action(
            self, "Restore Default Layout",
            on_triggered=self.prep_window_for_reset,
            shortcut="Shift+F10", shortcut_context=Qt.ApplicationShortcut)

        self.view_menu_actions = [action_restore_default, None] + self.create_widget_actions()

        # help menu
        action_mantid_help = create_action(
            self, "Mantid Help", on_triggered=self.open_mantid_help,
            shortcut='F1', shortcut_context=Qt.ApplicationShortcut)
        action_algorithm_descriptions = create_action(
            self, 'Algorithm Descriptions',
            on_triggered=self.open_algorithm_descriptions_help)
        action_mantid_concepts = create_action(
            self, "Mantid Concepts", on_triggered=self.open_mantid_concepts_help)
        action_mantid_homepage = create_action(
            self, "Mantid Homepage", on_triggered=self.open_mantid_homepage)
        action_mantid_forum = create_action(
            self, "Mantid Forum", on_triggered=self.open_mantid_forum)

        self.help_menu_actions = [
            action_mantid_help, action_mantid_concepts,
            action_algorithm_descriptions, None,
            action_mantid_homepage, action_mantid_forum]
コード例 #35
0
 def test_add_actions_with_invalid_parameter_raises_value_error(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = QObject()
     test_toolbar = QToolBar()
     self.assertRaises(ValueError, add_actions, test_toolbar,
                       [test_act_1, test_act_2])
コード例 #36
0
 def test_add_actions_with_qmenu_target(self):
     test_act_1 = create_action(None, "Test Action 1")
     test_act_2 = create_action(None, "Test Action 2")
     test_menu = QMenu()
     add_actions(test_menu, [test_act_1, test_act_2])
     self.assertFalse(test_menu.isEmpty())