diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index fcf68dc2bd..81e79a5895 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1077,6 +1077,13 @@ class ActionSavedSearches(InterfaceActionBase): description = _('Show a menu of saved searches') +class ActionLayoutActions(InterfaceActionBase): + name = 'Layout actions' + author = 'Charles Haley' + actual_plugin = 'calibre.gui2.actions.layout_actions:LayoutActions' + description = _("Show a menu of actions to change calibre's layout") + + class ActionBooklistContextMenu(InterfaceActionBase): name = 'Booklist context menu' author = 'Charles Haley' @@ -1125,7 +1132,8 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog, ActionPluginUpdater, ActionPickRandom, ActionEditToC, ActionSortBy, ActionMarkBooks, ActionEmbed, ActionTemplateTester, ActionTagMapper, ActionAuthorMapper, ActionVirtualLibrary, ActionBrowseAnnotations, ActionTemplateFunctions, ActionAutoscrollBooks, - ActionFullTextSearch, ActionManageCategories, ActionBooklistContextMenu, ActionSavedSearches] + ActionFullTextSearch, ActionManageCategories, ActionBooklistContextMenu, ActionSavedSearches, + ActionLayoutActions] # }}} diff --git a/src/calibre/gui2/actions/layout_actions.py b/src/calibre/gui2/actions/layout_actions.py new file mode 100644 index 0000000000..90594879a5 --- /dev/null +++ b/src/calibre/gui2/actions/layout_actions.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +# License: GPLv3 Copyright: 2022, Charles Haley +# + +from functools import partial + +from qt.core import QIcon, QToolButton + +from calibre.gui2.actions import InterfaceAction + + +class LayoutActions(InterfaceAction): + + name = 'Layout Actions' + action_spec = (_('Layout Actions'), 'tags.png', + _('Add/remove layout items: search bar, tag browser, etc.'), None) + action_type = 'current' + popup_type = QToolButton.ToolButtonPopupMode.InstantPopup + action_add_menu = True + dont_add_to = frozenset(['context-menu-device', 'menubar-device']) + + # The button names used by change_item_by_name() come from gui2.init. They are + # 'sb' => Search Bar + # 'tb' => Tag Browser + # 'bd' => Book Details + # 'gv' => Grid View + # 'cb' => Cover Browser + # 'qv' => QuickView + + def gui_layout_complete(self): + m = self.qaction.menu() + self.button_names = {} + m.addAction(_('Hide all'), self.hide_all) + for i,b in enumerate(self.gui.layout_buttons): + m.addSeparator() + self.button_names[self.gui.button_order[i]] = b + ic = QIcon.ic(b.icname) + m.addAction(ic, _('Show ') + b.label, partial(self.change_item, b, True)) + m.addAction(ic, _('Hide ') + b.label, partial(self.change_item, b, False)) + + def change_item(self, button, show=True): + if button.isChecked() and not show: + button.click() + elif not button.isChecked() and show: + button.click() + + def change_item_by_name(self, name, show=True): + self.change_item(self.button_names[name], show) + + def hide_all(self): + for name in self.button_names: + self.change_item_by_name(name, show=False) \ No newline at end of file diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index 92ce19fe31..8a73e5f431 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -581,7 +581,7 @@ class LayoutMixin: # {{{ self.bd_splitter.addWidget(self.book_details) self.bd_splitter.setCollapsible(self.bd_splitter.other_index, False) self.centralwidget.layout().addWidget(self.bd_splitter) - button_order = ('sb', 'tb', 'bd', 'gv', 'cb', 'qv') + self.button_order = button_order = ('sb', 'tb', 'bd', 'gv', 'cb', 'qv') # }}} else: # wide {{{ self.bd_splitter = Splitter('book_details_splitter', @@ -596,7 +596,7 @@ class LayoutMixin: # {{{ self.bd_splitter.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)) self.centralwidget.layout().addWidget(self.bd_splitter) - button_order = ('sb', 'tb', 'cb', 'gv', 'qv', 'bd') + self.button_order = button_order = ('sb', 'tb', 'cb', 'gv', 'qv', 'bd') # }}} # This must use the base method to find the plugin because it hasn't