Consolidate all the layout buttons in the status bar into a single button

This commit is contained in:
Kovid Goyal 2017-06-10 14:10:18 +05:30
parent 6106b2f654
commit ae3b5a00c2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 25 additions and 12 deletions

View File

@ -8,11 +8,11 @@ __docformat__ = 'restructuredtext en'
import functools import functools
from PyQt5.Qt import (Qt, QApplication, QStackedWidget, QMenu, QTimer, from PyQt5.Qt import (Qt, QApplication, QStackedWidget, QMenu, QTimer,
QSize, QSizePolicy, QStatusBar, QLabel, QFont, QAction, QTabBar, QSizePolicy, QStatusBar, QLabel, QFont, QAction, QTabBar,
QVBoxLayout, QWidget, QSplitter) QVBoxLayout, QWidget, QSplitter, QToolButton, QIcon)
from calibre.utils.config import prefs from calibre.utils.config import prefs
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key, primary_sort_key
from calibre.constants import (isosx, __appname__, preferred_encoding, from calibre.constants import (isosx, __appname__, preferred_encoding,
get_version) get_version)
from calibre.gui2 import config, is_widescreen, gprefs, error_dialog from calibre.gui2 import config, is_widescreen, gprefs, error_dialog
@ -340,8 +340,7 @@ class SearchBarButton(LayoutButton): # {{{
gprefs['search bar visible'] = bool(self.isChecked()) gprefs['search bar visible'] = bool(self.isChecked())
def restore_state(self): def restore_state(self):
if gprefs.get('search bar visible', True): self.setChecked(gprefs.get('search bar visible', True))
self.toggle()
# }}} # }}}
@ -535,22 +534,40 @@ class LayoutMixin(object): # {{{
self.grid_view_button.toggled.connect(self.toggle_grid_view) self.grid_view_button.toggled.connect(self.toggle_grid_view)
self.search_bar_button.toggled.connect(self.toggle_search_bar) self.search_bar_button.toggled.connect(self.toggle_search_bar)
self.layout_buttons = []
for x in button_order: for x in button_order:
if hasattr(self, x + '_splitter'): if hasattr(self, x + '_splitter'):
button = getattr(self, x + '_splitter').button button = getattr(self, x + '_splitter').button
else: else:
button = self.grid_view_button if x == 'gv' else self.search_bar_button button = self.grid_view_button if x == 'gv' else self.search_bar_button
button.setIconSize(QSize(24, 24)) self.layout_buttons.append(button)
button.setVisible(False)
if isosx and stylename != u'Calibre': if isosx and stylename != u'Calibre':
button.setStyleSheet(''' button.setStyleSheet('''
QToolButton { background: none; border:none; padding: 0px; } QToolButton { background: none; border:none; padding: 0px; }
QToolButton:checked { background: rgba(0, 0, 0, 25%); } QToolButton:checked { background: rgba(0, 0, 0, 25%); }
''') ''')
self.status_bar.addPermanentWidget(button) self.status_bar.addPermanentWidget(button)
self.layout_button = b = QToolButton(self)
b.setAutoRaise(True), b.setCursor(Qt.PointingHandCursor)
b.setPopupMode(b.InstantPopup)
b.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
b.setText(_('Layout')), b.setIcon(QIcon(I('config.png')))
b.setMenu(QMenu()), b.menu().aboutToShow.connect(self.populate_layout_menu)
b.setToolTip(_(
'Show and hide various parts of the calibre main window'))
self.status_bar.addPermanentWidget(b)
self.status_bar.addPermanentWidget(self.jobs_button) self.status_bar.addPermanentWidget(self.jobs_button)
self.setStatusBar(self.status_bar) self.setStatusBar(self.status_bar)
self.status_bar.update_label.linkActivated.connect(self.update_link_clicked) self.status_bar.update_label.linkActivated.connect(self.update_link_clicked)
def populate_layout_menu(self):
m = self.layout_button.menu()
m.clear()
buttons = sorted(self.layout_buttons, key=lambda b:primary_sort_key(b.label))
for b in buttons:
m.addAction(b.icon(), b.text(), b.click)
def finalize_layout(self): def finalize_layout(self):
self.status_bar.initialize(self.system_tray_icon) self.status_bar.initialize(self.system_tray_icon)
self.book_details.show_book_info.connect(self.iactions['Show Book Details'].show_book_info) self.book_details.show_book_info.connect(self.iactions['Show Book Details'].show_book_info)

View File

@ -497,7 +497,6 @@ class SearchBoxMixin(object): # {{{
self.library_view.model().set_highlight_only(config['highlight_search_matches']) self.library_view.model().set_highlight_only(config['highlight_search_matches'])
def focus_search_box(self, *args): def focus_search_box(self, *args):
self.search_bar_button.setChecked(True)
self.search.setFocus(Qt.OtherFocusReason) self.search.setFocus(Qt.OtherFocusReason)
self.search.lineEdit().selectAll() self.search.lineEdit().selectAll()

View File

@ -971,16 +971,13 @@ class LayoutButton(QToolButton):
def set_state_to_show(self, *args): def set_state_to_show(self, *args):
self.setChecked(False) self.setChecked(False)
self.setText(_('Show %(label)s [%(shortcut)s]')%dict(label=self.label, shortcut=self.shortcut) + '\n\n' + self.setText(_('Show {}'.format(self.label) + '\t' + self.shortcut))
_('Right click to configure'))
self.setToolTip(self.text()) self.setToolTip(self.text())
self.setStatusTip(self.text()) self.setStatusTip(self.text())
def set_state_to_hide(self, *args): def set_state_to_hide(self, *args):
self.setChecked(True) self.setChecked(True)
self.setText(_('Hide %(label)s [%(shortcut)s]')%dict( self.setText(_('Hide {}'.format(self.label) + '\t' + self.shortcut))
label=self.label, shortcut=self.shortcut) + '\n\n' +
_('Right click to configure'))
self.setToolTip(self.text()) self.setToolTip(self.text())
self.setStatusTip(self.text()) self.setStatusTip(self.text())