def build_menu(
                    self, display_type_menu: UserInterface.Menu,
                    selected_display_panel: typing.Optional[
                        DisplayPanel.DisplayPanel]
                ) -> typing.Sequence[UserInterface.MenuAction]:
                    # return a list of actions that have been added to the menu.
                    def switch_to_live_controller(
                        hardware_source: video_base.VideoHardwareSource
                    ) -> None:
                        d = {
                            "type":
                            "image",
                            "controller_type":
                            VideoDisplayPanelController.type,
                            "hardware_source_id":
                            hardware_source.hardware_source_id
                        }
                        if selected_display_panel:
                            selected_display_panel.change_display_panel_content(
                                d)

                    action = display_type_menu.add_menu_item(
                        hardware_source.display_name,
                        functools.partial(switch_to_live_controller,
                                          hardware_source))
                    display_panel_controller = selected_display_panel.display_panel_controller if selected_display_panel else None
                    action.checked = isinstance(
                        display_panel_controller, VideoDisplayPanelController
                    ) and display_panel_controller.hardware_source_id == hardware_source.hardware_source_id
                    return [action]
예제 #2
0
    def add_action_to_menu(
            self, menu: UserInterface.Menu, action_id: str,
            action_context: ActionContext) -> typing.Optional[Action]:
        action = actions.get(action_id)
        if action:
            key_sequence = action_shortcuts.get(action_id,
                                                dict()).get("window")
            assert menu is not None

            def perform_action() -> None:
                self.perform_action_in_context(action_id, action_context)

            def queue_perform_action() -> None:
                # delay execution to ensure menu closes properly
                # this would manifest itself by export dialog crashes in nionswift.
                self.queue_task(perform_action)

            menu_action = menu.add_menu_item(action.action_name,
                                             queue_perform_action,
                                             key_sequence=key_sequence,
                                             action_id=action_id)
            title = action.get_action_name(action_context)
            enabled = action and action.is_enabled(action_context)
            checked = action and action.is_checked(action_context)
            menu_action.apply_state(
                UserInterface.MenuItemState(title=title,
                                            enabled=enabled,
                                            checked=checked))
        return action
예제 #3
0
 def __about_to_show_recent_projects_menu(self, window: UIWindow.Window,
                                          menu: UserInterface.Menu) -> None:
     # recent project actions are stored with the window so they can be deleted.
     if hasattr(window, "_dynamic_recent_project_actions"):
         for recent_project_action in window._dynamic_recent_project_actions:
             menu.remove_action(recent_project_action)
     window._dynamic_recent_project_actions = []
     project_references = filter(lambda pr: pr.project_state != "loaded",
                                 self.__profile.project_references)
     project_references = sorted(project_references,
                                 key=operator.attrgetter("last_used"),
                                 reverse=True)
     for project_reference in project_references[:20]:
         if project_reference.project_state != "loaded":
             project_title = project_reference.title
             if project_reference.project_state == "needs_upgrade":
                 project_title += " " + _("(NEEDS UPGRADE)")
             elif project_reference.project_state != "unloaded" or project_reference.project_version != FileStorageSystem.PROJECT_VERSION:
                 project_title += " " + _("(MISSING OR UNREADABLE)")
             action = menu.add_menu_item(
                 project_title,
                 functools.partial(self.open_project_reference,
                                   project_reference))
             window._dynamic_recent_project_actions.append(action)
예제 #4
0
 def _menu_about_to_show(self, menu: UserInterface.Menu) -> None:
     if self.app and self.app._menu_about_to_show(self, menu):
         pass
     elif menu.menu_id == "file":
         self._file_menu_about_to_show()
     elif menu.menu_id == "edit":
         self._edit_menu_about_to_show()
     elif menu.menu_id == "window":
         self._window_menu_about_to_show()
     # perform enable/disable/title for all menus
     action_context = self._get_action_context()
     for menu_action in menu.get_menu_actions():
         if menu_action.action_id:
             action = actions.get(menu_action.action_id)
             if action:
                 title = action.get_action_name(action_context)
                 enabled = action and action.is_enabled(action_context)
                 checked = action and action.is_checked(action_context)
                 menu_action.apply_state(UserInterface.MenuItemState(title=title, enabled=enabled, checked=checked))