diff --git a/src/calibre/gui2/actions/booklist_context_menu.py b/src/calibre/gui2/actions/booklist_context_menu.py index e69884ecb5..6f2937f94b 100644 --- a/src/calibre/gui2/actions/booklist_context_menu.py +++ b/src/calibre/gui2/actions/booklist_context_menu.py @@ -2,6 +2,8 @@ # License: GPLv3 Copyright: 2022, Charles Haley # +from qt.core import QToolButton + from calibre.gui2.actions import InterfaceAction @@ -11,6 +13,7 @@ class BooklistContextMenuAction(InterfaceAction): action_spec = (_('Book list header menu'), 'context_menu.png', _('Show the book list header context menu'), None) action_type = 'current' + popup_type = QToolButton.ToolButtonPopupMode.InstantPopup action_add_menu = False dont_add_to = frozenset(['context-menu-device', 'menubar-device']) diff --git a/src/calibre/gui2/actions/manage_categories.py b/src/calibre/gui2/actions/manage_categories.py index a6cb87543b..d3eccb4508 100644 --- a/src/calibre/gui2/actions/manage_categories.py +++ b/src/calibre/gui2/actions/manage_categories.py @@ -2,6 +2,8 @@ # License: GPLv3 Copyright: 2022, Charles Haley # +from qt.core import QMenu, QToolButton + from calibre.gui2.actions import InterfaceAction @@ -9,20 +11,30 @@ class ManageCategoriesAction(InterfaceAction): name = 'Manage categories' action_spec = (_('Manage categories'), 'tags.png', - _('Manage categories: authors, tags, series, etc.'), ()) + _('Manage categories: authors, tags, series, etc.'), None) action_type = 'current' + popup_type = QToolButton.ToolButtonPopupMode.InstantPopup action_add_menu = True dont_add_to = frozenset(['context-menu-device', 'menubar-device']) def genesis(self): self.menu = m = self.qaction.menu() - self.qaction.triggered.connect(self.show_menu) m.aboutToShow.connect(self.about_to_show_menu) - # We want to show the menu when a toolbar button is clicked. Apparently - # the only way to do that is to scan the toolbar(s) for the action button - # then exec the associated menu. The search is done here to take adding and - # removing the action from toolbars into account. + # Create a "hidden" menu that can have a shortcut. + self.hidden_menu = QMenu() + self.shortcut_action = self.create_menu_action( + menu=self.hidden_menu, + unique_name=_('Manage categories'), + text=_('Manage categories: authors, tags, series, etc.'), + icon='tags.png', + triggered=self.show_menu) + + + # We want to show the menu when a shortcut is used. Apparently the only way + # to do that is to scan the toolbar(s) for the action button then exec the + # associated menu. The search is done here to take adding and removing the + # action from toolbars into account. # # If a shortcut is triggered and there isn't a toolbar button visible then # show the menu in the upper left corner of the library view pane. Yes, this diff --git a/src/calibre/gui2/actions/saved_searches.py b/src/calibre/gui2/actions/saved_searches.py index fc66d12133..709c24fc3d 100644 --- a/src/calibre/gui2/actions/saved_searches.py +++ b/src/calibre/gui2/actions/saved_searches.py @@ -2,7 +2,7 @@ # License: GPLv3 Copyright: 2022, Charles Haley # -from qt.core import QPoint +from qt.core import QPoint, QMenu, QToolButton from calibre.gui2.actions import InterfaceAction @@ -57,20 +57,29 @@ class SavedSearchesAction(InterfaceAction): name = 'Saved searches' action_spec = (_('Saved searches'), 'folder_saved_search.png', - _('Show a menu of saved searches'), ()) + _('Show a menu of saved searches'), None) action_type = 'current' + popup_type = QToolButton.ToolButtonPopupMode.InstantPopup action_add_menu = True dont_add_to = frozenset(('context-menu-device', 'menubar-device')) def genesis(self): self.menu = m = self.qaction.menu() - self.qaction.triggered.connect(self.show_menu) m.aboutToShow.connect(self.about_to_show_menu) - # We want to show the menu when a toolbar button is clicked. Apparently - # the only way to do that is to scan the toolbar(s) for the action button - # then exec the associated menu. The search is done here to take adding and - # removing the action from toolbars into account. + # Create a "hidden" menu that can have a shortcut. + self.hidden_menu = QMenu() + self.shortcut_action = self.create_menu_action( + menu=self.hidden_menu, + unique_name=_('Saved searches'), + text=_('Show a menu of saved searches'), + icon='folder_saved_search.png', + triggered=self.show_menu) + + # We want to show the menu when a shortcut is used. Apparently the only way + # to do that is to scan the toolbar(s) for the action button then exec the + # associated menu. The search is done here to take adding and removing the + # action from toolbars into account. # # If a shortcut is triggered and there isn't a toolbar button visible then # show the menu in the upper left corner of the library view pane. Yes, this diff --git a/src/calibre/gui2/bars.py b/src/calibre/gui2/bars.py index 8eb3accd6a..ff738e1958 100644 --- a/src/calibre/gui2/bars.py +++ b/src/calibre/gui2/bars.py @@ -15,7 +15,7 @@ from calibre.constants import ismacos from calibre.gui2 import gprefs, native_menubar_defaults, config from calibre.gui2.throbber import ThrobbingButton from polyglot.builtins import itervalues - +from calibre.gui2.widgets2 import RightClickButton class RevealBar(QWidget): # {{{ @@ -679,7 +679,7 @@ class BarsManager(QObject): for ac in self.search_tool_bar_actions: self.search_tool_bar.removeWidget(ac) - self.search_tool_bar.setContentsMargins(0, 0, 0, 0) + self.search_tool_bar.setContentsMargins(0, 0, 10, 0) self.search_tool_bar.setSpacing(0) self.search_tool_bar_actions = [] @@ -693,8 +693,10 @@ class BarsManager(QObject): self.search_tool_bar.addWidget(frame) self.search_tool_bar_actions.append(frame) elif what in self.parent().iactions: - qact = self.parent().iactions[what].qaction - tb = QToolButton() + act = self.parent().iactions[what] + qact = act.qaction + tb = RightClickButton() + tb.menu = qact.menu tb.setContentsMargins(0, 0, 0, 0) tb.setDefaultAction(qact) if not gprefs['search_tool_bar_shows_text']: @@ -702,7 +704,7 @@ class BarsManager(QObject): else: tb.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonTextBesideIcon) tb.setCursor(Qt.CursorShape.PointingHandCursor) - tb.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup) + tb.setPopupMode(act.popup_type) tb.setAutoRaise(True) self.search_tool_bar.addWidget(tb) self.search_tool_bar_actions.append(tb)