def _update_actions(self): """ Refresh Options menu. """ show_dock_actions = self.windowwidget is None self.undock_action.setVisible(show_dock_actions) self.close_action.setVisible(show_dock_actions) self.dock_action.setVisible(not show_dock_actions) if sys.platform == 'darwin': set_menu_icons(self.get_menu(PluginMainWidgetMenus.Options), True) self.update_actions() self._update_style()
def create_application_menu(self, menu_id, title): """ Create a Spyder application menu. Parameters ---------- menu_id: str The menu unique identifier string. title: str The localized menu title to be displayed. """ if menu_id in self._APPLICATION_MENUS: raise SpyderAPIError( 'Menu with id "{}" already added!'.format(menu_id)) menu = ApplicationMenu(self.main, title) menu.menu_id = menu_id self._APPLICATION_MENUS[menu_id] = menu self.main.menuBar().addMenu(menu) # Show and hide shortcuts and icons in menus for macOS if sys.platform == 'darwin': menu.aboutToShow.connect( lambda menu=menu: self._show_shortcuts(menu)) menu.aboutToHide.connect( lambda menu=menu: self._hide_shortcuts(menu)) menu.aboutToShow.connect( lambda menu=menu: set_menu_icons(menu, False)) menu.aboutToShow.connect(self._hide_options_menus) return menu
def _refresh_actions(self): """Refresh Options menu.""" self._options_menu.clear() # Decide what additional actions to show if self._undocked_window is None: additional_actions = [ MENU_SEPARATOR, self._undock_action, self._close_plugin_action ] else: additional_actions = [MENU_SEPARATOR, self._dock_action] # Create actions list self._plugin_actions = self.get_plugin_actions() + additional_actions add_actions(self._options_menu, self._plugin_actions) if sys.platform == 'darwin': set_menu_icons(self._options_menu, True)
def _update_actions(self): """ Refresh Options menu. """ show_dock_actions = self.windowwidget is None self.undock_action.setVisible(show_dock_actions) self.close_action.setVisible(show_dock_actions) self.dock_action.setVisible(not show_dock_actions) if sys.platform == 'darwin': try: set_menu_icons( self.get_menu(PluginMainWidgetMenus.Options), True) except KeyError: # Prevent unexpected errors on the test suite. pass # Widget setup # -------------------------------------------------------------------- self.update_actions()
def _setup_menus(self): """Setup menus.""" # Show and hide shortcuts and icons in menus for macOS if sys.platform == 'darwin': for menu_id in self._APPLICATION_MENUS: menu = self._APPLICATION_MENUS[menu_id] if menu is not None: menu.aboutToShow.connect( lambda menu=menu: self._show_shortcuts(menu)) menu.aboutToHide.connect( lambda menu=menu: self._hide_shortcuts(menu)) menu.aboutToShow.connect( lambda menu=menu: set_menu_icons(menu, False)) menu.aboutToShow.connect(self._hide_options_menus)
def create_application_menu(self, menu_id: str, title: str, dynamic: bool = True): """ Create a Spyder application menu. Parameters ---------- menu_id: str The menu unique identifier string. title: str The localized menu title to be displayed. """ if menu_id in self._APPLICATION_MENUS: raise SpyderAPIError( 'Menu with id "{}" already added!'.format(menu_id)) menu = ApplicationMenu(self.main, title, dynamic=dynamic) menu.menu_id = menu_id self._APPLICATION_MENUS[menu_id] = menu self.main.menuBar().addMenu(menu) # Show and hide shortcuts and icons in menus for macOS if sys.platform == 'darwin': menu.aboutToShow.connect( lambda menu=menu: self._show_shortcuts(menu)) menu.aboutToHide.connect( lambda menu=menu: self._hide_shortcuts(menu)) menu.aboutToShow.connect( lambda menu=menu: set_menu_icons(menu, False)) menu.aboutToShow.connect(self._hide_options_menus) if menu_id in self._ITEM_QUEUE: pending_items = self._ITEM_QUEUE.pop(menu_id) for pending in pending_items: (item, section, before_item, before_section) = pending self.add_item_to_application_menu( item, menu_id=menu_id, section=section, before=before_item, before_section=before_section) return menu
def _setup(self): """ Setup Options menu, create toggle action and connect signals. """ # Creat toggle view action self._create_toggle_view_action() # Create Options menu self._plugin_actions = self.get_plugin_actions() + [ MENU_SEPARATOR, self._undock_action ] add_actions(self._options_menu, self._plugin_actions) self.options_button.setMenu(self._options_menu) self._options_menu.aboutToShow.connect(self._refresh_actions) # Show icons in Mac plugin menus if sys.platform == 'darwin': self._options_menu.aboutToHide.connect( lambda menu=self._options_menu: set_menu_icons(menu, False)) # Update title self.sig_update_plugin_title.connect(self._update_plugin_title) self.setWindowTitle(self.get_plugin_title())
def _setup(self): """ Setup default actions, create options menu, and connect signals. """ # Tabs children = self.findChildren(Tabs) if children: for child in children: self._is_tab = True # For widgets that use tabs, we add the corner widget using # the setCornerWidget method. child.setCornerWidget(self._corner_widget) self._corner_widget.setStyleSheet(str(PANES_TABBAR_STYLESHEET)) break self._options_button = self.create_toolbutton( PluginMainWidgetWidgets.OptionsToolButton, text=_('Options'), icon=self.create_icon('tooloptions'), ) if self.ENABLE_SPINNER: self.add_corner_widget( PluginMainWidgetWidgets.Spinner, self._spinner, ) self.add_corner_widget( PluginMainWidgetWidgets.OptionsToolButton, self._options_button, ) # Widget setup # -------------------------------------------------------------------- self._main_toolbar.setVisible(not self._is_tab) self._corner_toolbar.setVisible(not self._is_tab) self._options_button.setPopupMode(QToolButton.InstantPopup) # Create default widget actions self.dock_action = self.create_action( name=PluginMainWidgetActions.DockPane, text=_("Dock"), tip=_("Dock the pane"), icon=self.create_icon('dock'), triggered=self.close_window, ) self.undock_action = self.create_action( name=PluginMainWidgetActions.UndockPane, text=_("Undock"), tip=_("Undock the pane"), icon=self.create_icon('undock'), triggered=self.create_window, ) self.close_action = self.create_action( name=PluginMainWidgetActions.ClosePane, text=_("Close"), tip=_("Close the pane"), icon=self.create_icon('close_pane'), triggered=self.close_dock, ) # We use this instead of the QDockWidget.toggleViewAction self.toggle_view_action = self.create_action( name='switch to ' + self._name, text=self.get_title(), toggled=lambda checked: self.toggle_view(checked), context=Qt.WidgetWithChildrenShortcut, shortcut_context='_', ) bottom_section = OptionsMenuSections.Bottom for item in [self.undock_action, self.close_action, self.dock_action]: self.add_item_to_menu( item, self._options_menu, section=bottom_section, ) self._options_button.setMenu(self._options_menu) self._options_menu.aboutToShow.connect(self._update_actions) # Hide icons in Mac plugin menus if sys.platform == 'darwin': self._options_menu.aboutToHide.connect( lambda menu=self._options_menu: set_menu_icons(menu, False)) # For widgets that do not use tabs, we add the corner widget to the # corner toolbar if not self._is_tab: self.add_item_to_toolbar( self._corner_widget, toolbar=self._corner_toolbar, section="corner", ) self._corner_widget.setStyleSheet(str(PANES_TOOLBAR_STYLESHEET)) # Update title self.setWindowTitle(self.get_title())
def _setup(self, options=DEFAULT_OPTIONS): """ Setup default actions, create options menu, and connect signals. """ # Tabs children = self.findChildren(Tabs) if children: for child in children: self._is_tab = True # For widgets that use tabs, we add the corner widget using # the setCornerWidget method. child.setCornerWidget(self._corner_widget) # This is needed to ensure the corner ToolButton (hamburguer # menu) is aligned with plugins that use Toolbars vs # CornerWidgets # See: spyder-ide/spyder#13600 # left, top, right, bottom if os.name == "nt": self._corner_widget.setContentsMargins(0, 0, 2, 0) else: self._corner_widget.setContentsMargins(0, 2, 2, 0) break self._options_button = self.create_toolbutton( PluginMainWidgetWidgets.OptionsToolButton, text=_('Options'), icon=self.create_icon('tooloptions'), ) self.add_corner_widget( PluginMainWidgetWidgets.OptionsToolButton, self._options_button, ) if self.ENABLE_SPINNER: self.add_corner_widget( PluginMainWidgetWidgets.Spinner, self._spinner, ) # Widget setup # -------------------------------------------------------------------- self._main_toolbar.setVisible(not self._is_tab) self._corner_toolbar.setVisible(not self._is_tab) self._options_button.setPopupMode(QToolButton.InstantPopup) # Create default widget actions self.dock_action = self.create_action( name=PluginMainWidgetActions.DockPane, text=_("Dock"), tip=_("Dock the pane"), icon=self.create_icon('dock'), triggered=self.close_window, ) self.undock_action = self.create_action( name=PluginMainWidgetActions.UndockPane, text=_("Undock"), tip=_("Undock the pane"), icon=self.create_icon('undock'), triggered=self.create_window, ) self.close_action = self.create_action( name=PluginMainWidgetActions.ClosePane, text=_("Close"), tip=_("Close the pane"), icon=self.create_icon('close_pane'), triggered=self.close_dock, ) # We use this instead of the QDockWidget.toggleViewAction self.toggle_view_action = self.create_action( name='switch to ' + self._name, text=self.get_title(), toggled=lambda checked: self.toggle_view(checked), context=Qt.WidgetWithChildrenShortcut, shortcut_context='_', ) bottom_section = OptionsMenuSections.Bottom for item in [self.undock_action, self.close_action, self.dock_action]: self.add_item_to_menu( item, self._options_menu, section=bottom_section, ) self._options_button.setMenu(self._options_menu) self._options_menu.aboutToShow.connect(self._update_actions) # Hide icons in Mac plugin menus if sys.platform == 'darwin': self._options_menu.aboutToHide.connect( lambda menu=self._options_menu: set_menu_icons(menu, False)) # For widgets that do not use tabs, we add the corner widget to the # corner toolbar if not self._is_tab: self.add_item_to_toolbar( self._corner_widget, toolbar=self._corner_toolbar, section="corner", ) # Update title self.setWindowTitle(self.get_title()) self._update_style()
def _setup(self, options=DEFAULT_OPTIONS): """ Setup default actions, create options menu, and connect signals. """ # Tabs children = self.findChildren(Tabs) if children: for child in children: self._is_tab = True child.setCornerWidget(self._corner_widget) break if self._is_tab: corner_widget = None else: corner_widget = self._corner_widget self._main_toolbar = MainWidgetToolbar( parent=self, title='widget_toolbar', corner_widget=corner_widget, ) if self._is_tab: # This disables the toolbar on all tabbed plugins self.get_main_toolbar().setVisible(not self._is_tab) self._options_menu = self.create_menu( PluginMainWidgetMenus.Options, text='', ) self._options_button = self.create_toolbutton( PluginMainWidgetWidgets.OptionsToolButton, text=_('Options'), icon=self.create_icon('tooloptions'), ) self.add_corner_widget( PluginMainWidgetWidgets.OptionsToolButton, self._options_button, ) self.add_corner_widget( PluginMainWidgetWidgets.Spinner, self._spinner, ) self._toolbars['main'] = self._main_toolbar # Setup the a dictionary in which pointers to additional toolbars # added to the plugin interface are going to be saved. self._aux_toolbars = {Qt.TopToolBarArea: [], Qt.BottomToolBarArea: []} # Widget setup # -------------------------------------------------------------------- self._options_button.setPopupMode(QToolButton.InstantPopup) self.setWindowFlags(Qt.Widget) self.addToolBar(self._main_toolbar) self.addToolBarBreak(Qt.TopToolBarArea) # Create default widget actions self.dock_action = self.create_action( name=PluginMainWidgetActions.DockPane, text=_("Dock"), tip=_("Dock the pane"), icon=self.create_icon('dock'), triggered=self.close_window, ) self.undock_action = self.create_action( name=PluginMainWidgetActions.UndockPane, text=_("Undock"), tip=_("Undock the pane"), icon=self.create_icon('undock'), triggered=self.create_window, ) self.close_action = self.create_action( name=PluginMainWidgetActions.ClosePane, text=_("Close"), tip=_("Close the pane"), icon=self.create_icon('close_pane'), triggered=self.close_dock, ) # We use this instead of the QDockWidget.toggleViewAction self.toggle_view_action = self.create_action( name='switch to ' + self._name, text=self.get_title(), toggled=lambda checked: self.toggle_view(checked), context=Qt.WidgetShortcut, shortcut_context='_', ) self.toggle_view_action.setChecked(True) bottom_section = OptionsMenuSections.Bottom for item in [self.undock_action, self.close_action, self.dock_action]: self.add_item_to_menu( item, self._options_menu, section=bottom_section, ) self._options_button.setMenu(self._options_menu,) self._options_menu.aboutToShow.connect(self._update_actions) # Hide icons in Mac plugin menus if sys.platform == 'darwin': self._options_menu.aboutToHide.connect( lambda menu=self._options_menu: set_menu_icons(menu, False)) # Update title self.setWindowTitle(self.get_title()) self._update_style()