From 3c664b75916ab07b76ae928a1539341e21f6ecb0 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Fri, 6 Jul 2012 09:43:58 +0200 Subject: [PATCH] 1) Add a tweak to turn on/off multi-character first-letter partioning in the tag browser 2) Change preferences.tweaks to add a "tweak number" to the tweak name string. This helps tell people which tweak to look at. To keep these valid, we should always add tweaks to the end. --- resources/default_tweaks.py | 10 ++++++++++ src/calibre/gui2/preferences/tweaks.py | 11 ++++++++--- src/calibre/gui2/tag_browser/model.py | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 10ce9b5c2c..cc798a09ba 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -515,3 +515,13 @@ compile_gpm_templates = True # default_tweak_format = 'remember' default_tweak_format = None +#: Enable multi-character first-letters in the tag browser +# Some languages have letters that can be represented by multiple characters. +# For example, Czech has a 'character' "ch" that sorts between "h" and "i". +# If this tweak is True, then the tag browser will take these characters into +# consideration when partitioning by first letter. +# Examples: +# enable_multicharacters_in_tag_browser = True +# enable_multicharacters_in_tag_browser = True +enable_multicharacters_in_tag_browser = True + diff --git a/src/calibre/gui2/preferences/tweaks.py b/src/calibre/gui2/preferences/tweaks.py index ebea8574a7..8169d799e0 100644 --- a/src/calibre/gui2/preferences/tweaks.py +++ b/src/calibre/gui2/preferences/tweaks.py @@ -39,7 +39,7 @@ class Delegate(QStyledItemDelegate): # {{{ class Tweak(object): # {{{ - def __init__(self, name, doc, var_names, defaults, custom): + def __init__(self, name, doc, var_names, defaults, custom, tweak_num): translate = _ self.name = translate(name) self.doc = doc.strip() @@ -53,6 +53,7 @@ class Tweak(object): # {{{ for x in var_names: if x in custom: self.custom_values[x] = custom[x] + self.tweak_num = tweak_num def __str__(self): ans = ['#: ' + self.name] @@ -92,6 +93,10 @@ class Tweak(object): # {{{ def update(self, varmap): self.custom_values.update(varmap) + @property + def name_with_position_number(self): + return "%d: %s"%(self.tweak_num, self.name) + # }}} class Tweaks(QAbstractListModel, SearchQueryParser): # {{{ @@ -113,7 +118,7 @@ class Tweaks(QAbstractListModel, SearchQueryParser): # {{{ except: return NONE if role == Qt.DisplayRole: - return textwrap.fill(tweak.name, 40) + return textwrap.fill(tweak.name_with_position_number, 40) if role == Qt.FontRole and tweak.is_customized: ans = QFont() ans.setBold(True) @@ -182,7 +187,7 @@ class Tweaks(QAbstractListModel, SearchQueryParser): # {{{ pos += 1 if not var_names: raise ValueError('Failed to find any variables for %r'%name) - self.tweaks.append(Tweak(name, doc, var_names, defaults, custom)) + self.tweaks.append(Tweak(name, doc, var_names, defaults, custom, len(self.tweaks)+1)) #print '\n\n', self.tweaks[-1] return pos diff --git a/src/calibre/gui2/tag_browser/model.py b/src/calibre/gui2/tag_browser/model.py index 0bc602622c..59d80373b1 100644 --- a/src/calibre/gui2/tag_browser/model.py +++ b/src/calibre/gui2/tag_browser/model.py @@ -260,7 +260,7 @@ class TagsModel(QAbstractItemModel): # {{{ db.prefs.set('tag_browser_hidden_categories', list(self.hidden_categories)) conts = contractions() - if len(conts) == 0: + if len(conts) == 0 or not tweaks['enable_multicharacters_in_tag_browser']: self.do_contraction = False else: self.do_contraction = True