diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index e14366af21..a0e8fafd0f 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -531,9 +531,9 @@ numeric_collation = False # number here. The default is ten libraries. many_libraries = 10 -#: Highlight the count of books when using a Virtual Library -# The count of books next to the Virtual Library button is highlighted in -# yellow when using a Virtual Library. By setting this to False, you can turn -# that off. -highlight_virtual_library_book_count = True +#: Highlight the virtual library name when using a Virtual Library +# The virtual library name next to the Virtual Library button is highlighted in +# yellow when using a Virtual Library. You can choose the color used for the +# highlight with this tweak. Set it to 'transparent' to disable highlighting. +highlight_virtual_library = 'yellow' diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index f1b68de0d7..347b6862a0 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -67,6 +67,7 @@ class LibraryUsageStats(object): # {{{ self.stats[lpath] = 0 self.stats[lpath] += 1 self.write_stats() + return self.pretty(lpath) def locations(self, db): lpath = self.canonicalize_path(db.library_path) @@ -159,7 +160,6 @@ class ChooseLibraryAction(InterfaceAction): restore_view_state = pyqtSignal(object) def genesis(self): - self.base_text = _('%d books') self.count_changed(0) self.action_choose = self.menuless_qaction @@ -248,7 +248,15 @@ class ChooseLibraryAction(InterfaceAction): return self.stats.pretty(path) def library_changed(self, db): - self.stats.library_used(db) + lname = self.stats.library_used(db) + tooltip = self.action_spec[2] + '\n\n' + _('{0} [{1} books]').format(lname, db.count()) + if len(lname) > 16: + lname = lname[:16] + u'…' + a = self.qaction + a.setText(lname) + a.setToolTip(tooltip) + a.setStatusTip(tooltip) + a.setWhatsThis(tooltip) self.build_menus() state = self.view_state_map.get(self.stats.canonicalize_path( db.library_path), None) @@ -506,13 +514,7 @@ class ChooseLibraryAction(InterfaceAction): self.switch_requested(self.qs_locations[idx]) def count_changed(self, new_count): - text = self.base_text%new_count - a = self.qaction - a.setText(text) - tooltip = self.action_spec[2] + '\n\n' + text - a.setToolTip(tooltip) - a.setStatusTip(tooltip) - a.setWhatsThis(tooltip) + pass def choose_library(self, *args): if not self.change_library_allowed(): diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index ace176bba2..581f0cb868 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -161,9 +161,11 @@ class StatusBar(QStatusBar): # {{{ def __init__(self, parent=None): QStatusBar.__init__(self, parent) + self.base_msg = '%s %s' % (__appname__, get_version()) + self.version = get_version() self.device_string = '' self.update_label = UpdateLabel('') - self.total = self.current = self.selected = 0 + self.total = self.current = self.selected = self.library_total = 0 self.addPermanentWidget(self.update_label) self.update_label.setVisible(False) self._font = QFont() @@ -182,7 +184,8 @@ class StatusBar(QStatusBar): # {{{ self.device_string = _('Connected ') + devname self.set_label() - def update_state(self, total, current, selected): + def update_state(self, library_total, total, current, selected): + self.library_total = library_total self.total, self.current, self.selected = total, current, selected self.set_label() @@ -194,7 +197,7 @@ class StatusBar(QStatusBar): # {{{ traceback.print_exc() def _set_label(self): - msg = '%s %s %s' % (__appname__, _('version'), get_version()) + msg = self.base_msg if self.device_string: msg += ' ..::.. ' + self.device_string else: @@ -206,6 +209,8 @@ class StatusBar(QStatusBar): # {{{ base = _('%d books') % self.total if self.selected > 0: base = _('%(num)s, %(sel)d selected') % dict(num=base, sel=self.selected) + if self.library_total != self.total: + base = _('{0}, {1} total').format(base, self.library_total) self.defmsg.setText('%s [%s]' % (msg, base)) self.clearMessage() @@ -340,8 +345,8 @@ class LayoutMixin(object): # {{{ def update_status_bar(self, *args): v = self.current_view() selected = len(v.selectionModel().selectedRows()) - total, current = v.model().counts() - self.status_bar.update_state(total, current, selected) + library_total, total, current = v.model().counts() + self.status_bar.update_state(library_total, total, current, selected) # }}} diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 6b793cecf4..324031aff0 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -29,7 +29,7 @@ from calibre.gui2.library import DEFAULT_SORT from calibre.utils.localization import calibre_langcode_to_name from calibre.library.coloring import color_row_key -Counts = namedtuple('Counts', 'total current') +Counts = namedtuple('Counts', 'library_total total current') def human_readable(size, precision=1): """ Convert a size in bytes into megabytes """ @@ -285,11 +285,10 @@ class BooksModel(QAbstractTableModel): # {{{ self.count_changed_signal.emit(self.db.count()) def counts(self): + library_total = total = self.db.count() if self.db.data.search_restriction_applied(): total = self.db.data.get_search_restriction_book_count() - else: - total = self.db.count() - return Counts(total, self.count()) + return Counts(library_total, total, self.count()) def row_indices(self, index): ''' Return list indices of all cells in index.row()''' @@ -1210,7 +1209,7 @@ class DeviceBooksModel(BooksModel): # {{{ self.book_in_library = None def counts(self): - return Counts(len(self.db), len(self.map)) + return Counts(len(self.db), len(self.db), len(self.map)) def count_changed(self, *args): self.count_changed_signal.emit(len(self.db)) diff --git a/src/calibre/gui2/search_restriction_mixin.py b/src/calibre/gui2/search_restriction_mixin.py index f01fb3e3dc..b986a2a78e 100644 --- a/src/calibre/gui2/search_restriction_mixin.py +++ b/src/calibre/gui2/search_restriction_mixin.py @@ -1,8 +1,10 @@ -''' -Created on 10 Jun 2010 +#!/usr/bin/env python +# vim:fileencoding=utf-8 +from __future__ import (unicode_literals, division, absolute_import, + print_function) -@author: charles -''' +__license__ = 'GPL v3' +__copyright__ = '2013, Kovid Goyal ' from functools import partial @@ -578,17 +580,16 @@ class SearchRestrictionMixin(object): db = self.library_view.model().db if self.current_view() == self.library_view and db is not None and \ db.data.search_restriction_applied(): - rows = self.current_view().row_count() - rbc = max(rows, db.data.get_search_restriction_book_count()) - t = _("({0} of {1})").format(rows, rbc) - if tweaks['highlight_virtual_library_book_count']: - self.search_count.setStyleSheet( - 'QLabel { border-radius: 8px; background-color: yellow; }') + restrictions = [x for x in (db.data.get_base_restriction_name(), + db.data.get_search_restriction_name()) if x] + t = ' :: '.join(restrictions) + if len(t) > 20: + t = t[:19] + u'…' + self.search_count.setStyleSheet( + 'QLabel { border-radius: 6px; background-color: %s }' % + tweaks['highlight_virtual_library']) else: # No restriction or not library view - if not self.search.in_a_search(): - t = _("(all books)") - else: - t = _("({0} of all)").format(self.current_view().row_count()) + t = '' self.search_count.setStyleSheet( 'QLabel { background-color: transparent; }') self.search_count.setText(t)