From 0d386793139f150bddefb5802c9d62f0b9b45292 Mon Sep 17 00:00:00 2001 From: Serized Date: Sat, 20 Jan 2018 10:38:06 +0100 Subject: [PATCH] Make Virtual Library tabs lockable (no close button) --- src/calibre/gui2/__init__.py | 1 + src/calibre/gui2/init.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 55ba50a260..2de87d8bc4 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -139,6 +139,7 @@ def create_defs(): defs['cover_grid_show_title'] = False defs['cover_grid_texture'] = None defs['show_vl_tabs'] = False + defs['closable_tabs'] = True defs['show_highlight_toggle_button'] = False defs['add_comments_to_email'] = False defs['cb_preserve_aspect_ratio'] = False diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index 021b0727a0..d85fba93f5 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -396,7 +396,7 @@ class VLTabs(QTabBar): # {{{ self.setDocumentMode(True) self.setDrawBase(False) self.setMovable(True) - self.setTabsClosable(True) + self.setTabsClosable(gprefs['closable_tabs']) self.gui = parent self.ignore_tab_changed = False self.currentChanged.connect(self.tab_changed) @@ -432,6 +432,23 @@ class VLTabs(QTabBar): # {{{ gprefs['show_vl_tabs'] = False self.setVisible(False) + def lock_tab(self): + gprefs['closable_tabs'] = False + self.setTabsClosable(False) + + def unlock_tab(self): + gprefs['closable_tabs'] = True + self.setTabsClosable(True) + try: + self.tabButton(0, self.RightSide).setVisible(False) + except AttributeError: + try: + self.tabButton(0, self.LeftSide).setVisible(False) + except AttributeError: + # On some OS X machines (using native style) the tab button is + # on the left + pass + def tab_changed(self, idx): if self.ignore_tab_changed: return @@ -512,6 +529,10 @@ class VLTabs(QTabBar): # {{{ for x in hidden: s.addAction(x, partial(self.restore, x)) m.addAction(_('Hide virtual library tabs'), self.disable_bar) + if gprefs['closable_tabs']: + m.addAction(_('Lock virtual library tabs'), self.lock_tab) + if not gprefs['closable_tabs']: + m.addAction(_('Unlock virtual library tabs'), self.unlock_tab) i = self.tabAt(ev.pos()) if i > -1: vl = unicode(self.tabData(i) or '')