From 8f928644fec076622d894d23fc84281819003257 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 5 Jan 2024 16:51:59 +0530 Subject: [PATCH] keyboard shortcut to toggle layout (Alt+Shift+L) --- manual/gui.rst | 2 ++ src/calibre/gui2/actions/layout_actions.py | 3 +++ src/calibre/gui2/central.py | 14 ++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/manual/gui.rst b/manual/gui.rst index b1a9156728..2b81acdf51 100644 --- a/manual/gui.rst +++ b/manual/gui.rst @@ -959,3 +959,5 @@ calibre has several keyboard shortcuts to save you time and mouse movement. Thes - Browse annotations (highlights and bookmarks) made in the calibre viewer for all books in the library * - :kbd:`Ctrl+Shift+N` - Browse notes associated with authors/series/tags/etc. + * - :kbd:`Alt+Shift+L` + - Toggle the layout between wide and narrow views diff --git a/src/calibre/gui2/actions/layout_actions.py b/src/calibre/gui2/actions/layout_actions.py index bf1ad962b9..2208c5a452 100644 --- a/src/calibre/gui2/actions/layout_actions.py +++ b/src/calibre/gui2/actions/layout_actions.py @@ -28,6 +28,9 @@ class LayoutActions(InterfaceAction): action_add_menu = True dont_add_to = frozenset({'context-menu-device', 'menubar-device'}) + def toggle_layout(self): + self.gui.layout_container.toggle_layout() + def gui_layout_complete(self): m = self.qaction.menu() m.aboutToShow.connect(self.populate_layout_menu) diff --git a/src/calibre/gui2/central.py b/src/calibre/gui2/central.py index 0f2aaf4e89..210ab34898 100644 --- a/src/calibre/gui2/central.py +++ b/src/calibre/gui2/central.py @@ -327,6 +327,8 @@ class CentralContainer(QWidget): self.wide_is_visible = Visibility() self.narrow_is_visible = Visibility() super().__init__(parent) + self.action_toggle_layout = QAction(self) + self.action_toggle_layout.triggered.connect(self.toggle_layout) self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) if for_develop: self.tag_browser = Placeholder('tag browser', self) @@ -378,6 +380,9 @@ class CentralContainer(QWidget): self.set_widget('book_details', gui.book_details) self.set_widget('tag_browser', gui.tb_widget) self.set_widget('book_list', book_list_widget) + gui.keyboard.register_shortcut( + 'toggle_layout_type', _('Toggle layout between wide and narrow'), default_keys=('Alt+Shift+L',), action=self.action_toggle_layout) + gui.addAction(self.action_toggle_layout) # cover browser is set in CoverFlowMixin # Quickview is set in quickview.py code @@ -547,8 +552,13 @@ class CentralContainer(QWidget): self.update() def toggle_layout(self): - self.layout = Layout.narrow if self.layout is Layout.wide else Layout.wide - self.relayout() + from calibre.gui2.ui import get_gui + gui = get_gui() + if gui: + self.change_layout(gui, self.layout is Layout.narrow) + else: + self.layout = Layout.narrow if self.layout is Layout.wide else Layout.wide + self.relayout() def button_for(self, which): return getattr(self, which + '_button')