Tag browser: Move the configuration of the sub-category grouping from tweaks to the Preferences dialog

This commit is contained in:
Kovid Goyal 2011-01-02 11:31:56 -07:00
parent d99b2e97fb
commit 40b5755934
5 changed files with 58 additions and 25 deletions

View File

@ -55,16 +55,9 @@ author_sort_copy_method = 'invert'
# categories_use_field_for_author_name = 'author_sort'
categories_use_field_for_author_name = 'author'
# Control how the tags pane displays categories containing many items. If the
# number of items is larger than categories_collapse_more_than, a sub-category
# will be added. If sorting by name, then the subcategories can be organized by
# first letter (categories_collapse_model = 'first letter') or into equal-sized
# groups (categories_collapse_model = 'partition'). If sorting by average rating
# or by popularity, then 'partition' is always used. The addition of
# subcategories can be disabled by setting categories_collapse_model='disable'.
# When using partition, the format of the subcategory label is controlled by a
# template: categories_collapsed_name_template if sorting by name,
# categories_collapsed_rating_template if sorting by average rating, and
# When partitioning the tags browser, the format of the subcategory label is
# controlled by a template: categories_collapsed_name_template if sorting by
# name, categories_collapsed_rating_template if sorting by average rating, and
# categories_collapsed_popularity_template if sorting by popularity. There are
# two variables available to the template: first and last. The variable 'first'
# is the initial item in the subcategory, and the variable 'last' is the final
@ -76,12 +69,6 @@ categories_use_field_for_author_name = 'author'
# avg_rating: the averate rating of all the books referencing this item
# sort: the sort value. For authors, this is the author_sort for that author
# category: the category (e.g., authors, series) that the item is in.
# Possible values:
# category_collapse_model: 'disable', 'first letter', 'partition'
# categories_collapse_more_than: a number greater than or equal to 0
# the templates: any valid template using only 'first' and 'last'
categories_collapse_model = 'first letter'
categories_collapse_more_than = 50
categories_collapsed_name_template = '{first.sort:shorten(4,'',0)} - {last.sort:shorten(4,'',0)}'
categories_collapsed_rating_template = '{first.avg_rating:4.2f:ifempty(0)} - {last.avg_rating:4.2f:ifempty(0)}'
categories_collapsed_popularity_template = '{first.count:d} - {last.count:d}'

View File

@ -53,6 +53,8 @@ gprefs.defaults['toolbar_icon_size'] = 'medium'
gprefs.defaults['toolbar_text'] = 'auto'
gprefs.defaults['show_child_bar'] = False
gprefs.defaults['font'] = None
gprefs.defaults['tags_browser_partition_method'] = 'first letter'
gprefs.defaults['tags_browser_collapse_at'] = 50
# }}}

View File

@ -57,6 +57,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
(_('Never'), 'never')]
r('toolbar_text', gprefs, choices=choices)
choices = [(_('Disabled'), 'disabled'), (_('By first letter'), 'first letter'),
(_('Partitioned'), 'partition')]
r('tags_browser_partition_method', gprefs, choices=choices)
r('tags_browser_collapse_at', gprefs)
self.current_font = None
self.change_font_button.clicked.connect(self.change_font)
@ -113,6 +118,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
def refresh_gui(self, gui):
gui.search.search_as_you_type(config['search_as_you_type'])
self.update_font_display()
gui.tags_view.reread_collapse_parameters()
if __name__ == '__main__':
app = QApplication([])

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>670</width>
<height>385</height>
<height>420</height>
</rect>
</property>
<property name="windowTitle">
@ -141,7 +141,37 @@
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<item row="7" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Tags browser: partitioning method:</string>
</property>
<property name="buddy">
<cstring>opt_tags_browser_partition_method</cstring>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="opt_tags_browser_partition_method"/>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Tags browser - collapse when more items than:</string>
</property>
<property name="buddy">
<cstring>opt_tags_browser_collapse_at</cstring>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QSpinBox" name="opt_tags_browser_collapse_at">
<property name="maximum">
<number>1000000</number>
</property>
</widget>
</item>
<item row="15" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>&amp;Toolbar</string>
@ -183,7 +213,7 @@
</layout>
</widget>
</item>
<item row="8" column="0">
<item row="16" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_2">
@ -204,14 +234,14 @@
</item>
</layout>
</item>
<item row="8" column="1">
<item row="16" column="1">
<widget class="QPushButton" name="change_font_button">
<property name="text">
<string>Change &amp;font (needs restart)</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="2">
<item row="17" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>

View File

@ -17,7 +17,7 @@ from PyQt4.Qt import Qt, QTreeView, QApplication, pyqtSignal, QFont, QSize, \
QShortcut, QKeySequence, SIGNAL
from calibre.ebooks.metadata import title_sort
from calibre.gui2 import config, NONE
from calibre.gui2 import config, NONE, gprefs
from calibre.library.field_metadata import TagsIcons, category_icon_map
from calibre.utils.config import tweaks
from calibre.utils.icu import sort_key, upper, lower, strcmp
@ -94,10 +94,10 @@ class TagsView(QTreeView): # {{{
self.setDropIndicatorShown(True)
self.setAutoExpandDelay(500)
self.pane_is_visible = False
if tweaks['categories_collapse_more_than'] == 0:
if gprefs['tags_browser_collapse_at'] == 0:
self.collapse_model = 'disable'
else:
self.collapse_model = tweaks['categories_collapse_model']
self.collapse_model = gprefs['tags_browser_partition_method']
def set_pane_is_visible(self, to_what):
pv = self.pane_is_visible
@ -105,6 +105,13 @@ class TagsView(QTreeView): # {{{
if to_what and not pv:
self.recount()
def reread_collapse_parameters(self):
if gprefs['tags_browser_collapse_at'] == 0:
self.collapse_model = 'disable'
else:
self.collapse_model = gprefs['tags_browser_partition_method']
self.set_new_model(self._model.get_filter_categories_by())
def set_database(self, db, tag_match, sort_by):
self.hidden_categories = config['tag_browser_hidden_categories']
self._model = TagsModel(db, parent=self,
@ -204,6 +211,7 @@ class TagsView(QTreeView): # {{{
self.collapse_model = category
if changed:
self.set_new_model(self._model.get_filter_categories_by())
gprefs['tags_browser_partition_method'] = category
elif action == 'defaults':
self.hidden_categories.clear()
config.set('tag_browser_hidden_categories', self.hidden_categories)
@ -709,7 +717,7 @@ class TagsModel(QAbstractItemModel): # {{{
if data is None:
return False
row_index = -1
collapse = tweaks['categories_collapse_more_than']
collapse = gprefs['tags_browser_collapse_at']
collapse_model = self.collapse_model
if collapse == 0:
collapse_model = 'disable'