Provide an API for action chains and view manager to show and hide calibre panels. I did it as an Action because these are easy for the plugins to use. In fact, Action Chains requires no work.

This commit is contained in:
Charles Haley 2023-07-09 13:36:38 +01:00
parent aed7358824
commit 278387a7d6
3 changed files with 63 additions and 3 deletions

View File

@ -1077,6 +1077,13 @@ class ActionSavedSearches(InterfaceActionBase):
description = _('Show a menu of saved searches') 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): class ActionBooklistContextMenu(InterfaceActionBase):
name = 'Booklist context menu' name = 'Booklist context menu'
author = 'Charles Haley' author = 'Charles Haley'
@ -1125,7 +1132,8 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
ActionPluginUpdater, ActionPickRandom, ActionEditToC, ActionSortBy, ActionPluginUpdater, ActionPickRandom, ActionEditToC, ActionSortBy,
ActionMarkBooks, ActionEmbed, ActionTemplateTester, ActionTagMapper, ActionAuthorMapper, ActionMarkBooks, ActionEmbed, ActionTemplateTester, ActionTagMapper, ActionAuthorMapper,
ActionVirtualLibrary, ActionBrowseAnnotations, ActionTemplateFunctions, ActionAutoscrollBooks, ActionVirtualLibrary, ActionBrowseAnnotations, ActionTemplateFunctions, ActionAutoscrollBooks,
ActionFullTextSearch, ActionManageCategories, ActionBooklistContextMenu, ActionSavedSearches] ActionFullTextSearch, ActionManageCategories, ActionBooklistContextMenu, ActionSavedSearches,
ActionLayoutActions]
# }}} # }}}

View File

@ -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)

View File

@ -581,7 +581,7 @@ class LayoutMixin: # {{{
self.bd_splitter.addWidget(self.book_details) self.bd_splitter.addWidget(self.book_details)
self.bd_splitter.setCollapsible(self.bd_splitter.other_index, False) self.bd_splitter.setCollapsible(self.bd_splitter.other_index, False)
self.centralwidget.layout().addWidget(self.bd_splitter) 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 {{{ else: # wide {{{
self.bd_splitter = Splitter('book_details_splitter', self.bd_splitter = Splitter('book_details_splitter',
@ -596,7 +596,7 @@ class LayoutMixin: # {{{
self.bd_splitter.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Expanding, self.bd_splitter.setSizePolicy(QSizePolicy(QSizePolicy.Policy.Expanding,
QSizePolicy.Policy.Expanding)) QSizePolicy.Policy.Expanding))
self.centralwidget.layout().addWidget(self.bd_splitter) 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 # This must use the base method to find the plugin because it hasn't