Replace book counts

Replace the book counts in the choose library button and next to the
virtual library button with the names of the current library and virtual
library. The count information is now displayed in the status bar at
the bottom.
This commit is contained in:
Kovid Goyal 2013-05-29 22:14:56 +05:30
parent 978be5e9ec
commit 384e2048f9
5 changed files with 45 additions and 38 deletions

View File

@ -531,9 +531,9 @@ numeric_collation = False
# number here. The default is ten libraries. # number here. The default is ten libraries.
many_libraries = 10 many_libraries = 10
#: Highlight the count of books when using a Virtual Library #: Highlight the virtual library name when using a Virtual Library
# The count of books next to the Virtual Library button is highlighted in # The virtual library name next to the Virtual Library button is highlighted in
# yellow when using a Virtual Library. By setting this to False, you can turn # yellow when using a Virtual Library. You can choose the color used for the
# that off. # highlight with this tweak. Set it to 'transparent' to disable highlighting.
highlight_virtual_library_book_count = True highlight_virtual_library = 'yellow'

View File

@ -67,6 +67,7 @@ class LibraryUsageStats(object): # {{{
self.stats[lpath] = 0 self.stats[lpath] = 0
self.stats[lpath] += 1 self.stats[lpath] += 1
self.write_stats() self.write_stats()
return self.pretty(lpath)
def locations(self, db): def locations(self, db):
lpath = self.canonicalize_path(db.library_path) lpath = self.canonicalize_path(db.library_path)
@ -159,7 +160,6 @@ class ChooseLibraryAction(InterfaceAction):
restore_view_state = pyqtSignal(object) restore_view_state = pyqtSignal(object)
def genesis(self): def genesis(self):
self.base_text = _('%d books')
self.count_changed(0) self.count_changed(0)
self.action_choose = self.menuless_qaction self.action_choose = self.menuless_qaction
@ -248,7 +248,15 @@ class ChooseLibraryAction(InterfaceAction):
return self.stats.pretty(path) return self.stats.pretty(path)
def library_changed(self, db): 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() self.build_menus()
state = self.view_state_map.get(self.stats.canonicalize_path( state = self.view_state_map.get(self.stats.canonicalize_path(
db.library_path), None) db.library_path), None)
@ -506,13 +514,7 @@ class ChooseLibraryAction(InterfaceAction):
self.switch_requested(self.qs_locations[idx]) self.switch_requested(self.qs_locations[idx])
def count_changed(self, new_count): def count_changed(self, new_count):
text = self.base_text%new_count pass
a = self.qaction
a.setText(text)
tooltip = self.action_spec[2] + '\n\n' + text
a.setToolTip(tooltip)
a.setStatusTip(tooltip)
a.setWhatsThis(tooltip)
def choose_library(self, *args): def choose_library(self, *args):
if not self.change_library_allowed(): if not self.change_library_allowed():

View File

@ -161,9 +161,11 @@ class StatusBar(QStatusBar): # {{{
def __init__(self, parent=None): def __init__(self, parent=None):
QStatusBar.__init__(self, parent) QStatusBar.__init__(self, parent)
self.base_msg = '%s %s' % (__appname__, get_version())
self.version = get_version()
self.device_string = '' self.device_string = ''
self.update_label = UpdateLabel('') 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.addPermanentWidget(self.update_label)
self.update_label.setVisible(False) self.update_label.setVisible(False)
self._font = QFont() self._font = QFont()
@ -182,7 +184,8 @@ class StatusBar(QStatusBar): # {{{
self.device_string = _('Connected ') + devname self.device_string = _('Connected ') + devname
self.set_label() 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.total, self.current, self.selected = total, current, selected
self.set_label() self.set_label()
@ -194,7 +197,7 @@ class StatusBar(QStatusBar): # {{{
traceback.print_exc() traceback.print_exc()
def _set_label(self): def _set_label(self):
msg = '%s %s %s' % (__appname__, _('version'), get_version()) msg = self.base_msg
if self.device_string: if self.device_string:
msg += ' ..::.. ' + self.device_string msg += ' ..::.. ' + self.device_string
else: else:
@ -206,6 +209,8 @@ class StatusBar(QStatusBar): # {{{
base = _('%d books') % self.total base = _('%d books') % self.total
if self.selected > 0: if self.selected > 0:
base = _('%(num)s, %(sel)d selected') % dict(num=base, sel=self.selected) 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.defmsg.setText('%s [%s]' % (msg, base))
self.clearMessage() self.clearMessage()
@ -340,8 +345,8 @@ class LayoutMixin(object): # {{{
def update_status_bar(self, *args): def update_status_bar(self, *args):
v = self.current_view() v = self.current_view()
selected = len(v.selectionModel().selectedRows()) selected = len(v.selectionModel().selectedRows())
total, current = v.model().counts() library_total, total, current = v.model().counts()
self.status_bar.update_state(total, current, selected) self.status_bar.update_state(library_total, total, current, selected)
# }}} # }}}

View File

@ -29,7 +29,7 @@ from calibre.gui2.library import DEFAULT_SORT
from calibre.utils.localization import calibre_langcode_to_name from calibre.utils.localization import calibre_langcode_to_name
from calibre.library.coloring import color_row_key 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): def human_readable(size, precision=1):
""" Convert a size in bytes into megabytes """ """ Convert a size in bytes into megabytes """
@ -285,11 +285,10 @@ class BooksModel(QAbstractTableModel): # {{{
self.count_changed_signal.emit(self.db.count()) self.count_changed_signal.emit(self.db.count())
def counts(self): def counts(self):
library_total = total = self.db.count()
if self.db.data.search_restriction_applied(): if self.db.data.search_restriction_applied():
total = self.db.data.get_search_restriction_book_count() total = self.db.data.get_search_restriction_book_count()
else: return Counts(library_total, total, self.count())
total = self.db.count()
return Counts(total, self.count())
def row_indices(self, index): def row_indices(self, index):
''' Return list indices of all cells in index.row()''' ''' Return list indices of all cells in index.row()'''
@ -1210,7 +1209,7 @@ class DeviceBooksModel(BooksModel): # {{{
self.book_in_library = None self.book_in_library = None
def counts(self): 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): def count_changed(self, *args):
self.count_changed_signal.emit(len(self.db)) self.count_changed_signal.emit(len(self.db))

View File

@ -1,8 +1,10 @@
''' #!/usr/bin/env python
Created on 10 Jun 2010 # vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import,
print_function)
@author: charles __license__ = 'GPL v3'
''' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from functools import partial from functools import partial
@ -578,17 +580,16 @@ class SearchRestrictionMixin(object):
db = self.library_view.model().db db = self.library_view.model().db
if self.current_view() == self.library_view and db is not None and \ if self.current_view() == self.library_view and db is not None and \
db.data.search_restriction_applied(): db.data.search_restriction_applied():
rows = self.current_view().row_count() restrictions = [x for x in (db.data.get_base_restriction_name(),
rbc = max(rows, db.data.get_search_restriction_book_count()) db.data.get_search_restriction_name()) if x]
t = _("({0} of {1})").format(rows, rbc) t = ' :: '.join(restrictions)
if tweaks['highlight_virtual_library_book_count']: if len(t) > 20:
self.search_count.setStyleSheet( t = t[:19] + u''
'QLabel { border-radius: 8px; background-color: yellow; }') self.search_count.setStyleSheet(
'QLabel { border-radius: 6px; background-color: %s }' %
tweaks['highlight_virtual_library'])
else: # No restriction or not library view else: # No restriction or not library view
if not self.search.in_a_search(): t = ''
t = _("(all books)")
else:
t = _("({0} of all)").format(self.current_view().row_count())
self.search_count.setStyleSheet( self.search_count.setStyleSheet(
'QLabel { background-color: transparent; }') 'QLabel { background-color: transparent; }')
self.search_count.setText(t) self.search_count.setText(t)