From 46f19333c9b2bff744bb188005be9c1b0714b534 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 16 May 2018 10:50:44 +0530 Subject: [PATCH] Improve formatting of help in Preferences->Tweaks Lines are now wrapped by default and blockquotes are formatted uniformly with four leading spaces. --- resources/default_tweaks.py | 61 +++++++++++++------------- src/calibre/gui2/preferences/tweaks.py | 27 ++++++++++-- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 3233797037..c4439e5384 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -15,19 +15,17 @@ defaults. # New series numbers assigned using this tweak are always integer values, except # if a constant non-integer is specified. # Possible values are: -# next - First available integer larger than the largest existing number -# first_free - First available integer larger than 0 -# next_free - First available integer larger than the smallest existing number -# last_free - First available integer smaller than the largest existing number -# Return largest existing + 1 if no free number is found -# const - Assign the number 1 always -# no_change - Do not change the series index -# a number - Assign that number always. The number is not in quotes. Note that -# 0.0 can be used here. +# next - First available integer larger than the largest existing number +# first_free - First available integer larger than 0 +# next_free - First available integer larger than the smallest existing number +# last_free - First available integer smaller than the largest existing number. Return largest existing + 1 if no free number is found +# const - Assign the number 1 always +# no_change - Do not change the series index +# a number - Assign that number always. The number is not in quotes. Note that 0.0 can be used here. # Examples: -# series_index_auto_increment = 'next' -# series_index_auto_increment = 'next_free' -# series_index_auto_increment = 16.5 +# series_index_auto_increment = 'next' +# series_index_auto_increment = 'next_free' +# series_index_auto_increment = 16.5 # # Set the use_series_auto_increment_tweak_when_importing tweak to True to # use the above values when importing/adding books. If this tweak is set to @@ -51,7 +49,7 @@ use_series_auto_increment_tweak_when_importing = False authors_completer_append_separator = False #: Author sort name algorithm -# The algorithm used to copy author to author_sort +# The algorithm used to copy author to author_sort. # Possible values are: # invert: use "fn ln" -> "ln, fn" # copy : copy author to author_sort without modification @@ -132,11 +130,11 @@ tag_browser_category_order = {'*':1} #: Specify columns to sort the booklist by on startup -# Provide a set of columns to be sorted on when calibre starts -# The argument is None if saved sort history is to be used -# otherwise it is a list of column,order pairs. Column is the -# lookup/search name, found using the tooltip for the column -# Order is 0 for ascending, 1 for descending +# Provide a set of columns to be sorted on when calibre starts. +# The argument is None if saved sort history is to be used +# otherwise it is a list of column,order pairs. Column is the +# lookup/search name, found using the tooltip for the column +# Order is 0 for ascending, 1 for descending. # For example, set it to [('authors',0),('title',0)] to sort by # title within authors. sort_columns_at_startup = None @@ -261,7 +259,7 @@ per_language_title_sort_articles = { 'ell' : (r'O\s+', r'I\s+', r'To\s+', r'Ta\s+', r'Tus\s+', r'Tis\s+', r"'Enas\s+", r"'Mia\s+", r"'Ena\s+", r"'Enan\s+", ), # Hungarian - 'hun' : (r'A\s+', 'Az\s+', 'Egy\s+',), + 'hun' : (r'A\s+', r'Az\s+', r'Egy\s+',), } default_language_for_title_sort = None title_sort_articles=r'^(A|The|An)\s+' @@ -310,20 +308,20 @@ auto_connect_to_folder = '' # '{value} {category:|(|)}' # Examples: The first three examples assume that the second tweak # has not been changed. -# 1: I want three series columns to be merged into one set of collections. The -# column lookup names are 'series', '#series_1' and '#series_2'. I want nothing -# in the parenthesis. The value to use in the tweak value would be: +# 1: I want three series columns to be merged into one set of collections. The +# column lookup names are 'series', '#series_1' and '#series_2'. I want nothing +# in the parenthesis. The value to use in the tweak value would be: # sony_collection_renaming_rules={'series':'', '#series_1':'', '#series_2':''} -# 2: I want the word '(Series)' to appear on collections made from series, and -# the word '(Tag)' to appear on collections made from tags. Use: +# 2: I want the word '(Series)' to appear on collections made from series, and +# the word '(Tag)' to appear on collections made from tags. Use: # sony_collection_renaming_rules={'series':'Series', 'tags':'Tag'} -# 3: I want 'series' and '#myseries' to be merged, and for the collection name -# to have '(Series)' appended. The renaming rule is: +# 3: I want 'series' and '#myseries' to be merged, and for the collection name +# to have '(Series)' appended. The renaming rule is: # sony_collection_renaming_rules={'series':'Series', '#myseries':'Series'} -# 4: Same as example 2, but instead of having the category name in parentheses -# and appended to the value, I want it prepended and separated by a colon, such -# as in Series: Darkover. I must change the template used to format the category name -# The resulting two tweaks are: +# 4: Same as example 2, but instead of having the category name in parentheses +# and appended to the value, I want it prepended and separated by a colon, such +# as in Series: Darkover. I must change the template used to format the category name +# The resulting two tweaks are: # sony_collection_renaming_rules={'series':'Series', 'tags':'Tag'} # sony_collection_name_template='{category:||: }{value}' sony_collection_renaming_rules={} @@ -362,10 +360,13 @@ add_new_book_tags_when_importing_books = False # Defaults: # content_server_will_display = ['*'] # content_server_wont_display = [] +# # Examples: +# # To display only the custom fields #mytags and #genre: # content_server_will_display = ['#mytags', '#genre'] # content_server_wont_display = [] +# # To display all fields except #mycomments: # content_server_will_display = ['*'] # content_server_wont_display['#mycomments'] diff --git a/src/calibre/gui2/preferences/tweaks.py b/src/calibre/gui2/preferences/tweaks.py index f4e29aa51f..0704413c3d 100644 --- a/src/calibre/gui2/preferences/tweaks.py +++ b/src/calibre/gui2/preferences/tweaks.py @@ -28,6 +28,27 @@ from PyQt5.Qt import ( ROOT = QModelIndex() +def format_doc(doc): + current_indent = default_indent = None + lines = [''] + for line in doc.splitlines(): + if not line.strip(): + lines.append('') + continue + line = line[1:] + indent = len(line) - len(line.lstrip()) + if indent != current_indent: + lines.append('') + if default_indent is None: + default_indent = indent + current_indent = indent + if indent == default_indent: + lines[-1] += ' ' + line + else: + lines.append(' ' + line.strip()) + return '\n'.join(lines).lstrip() + + class AdaptSQP(SearchQueryParser): def __init__(self, *args, **kwargs): @@ -58,9 +79,10 @@ class Tweak(object): # {{{ self.doc = doc.strip() if self.doc: self.doc = translate(self.doc) + self.doc = ' ' + self.doc self.var_names = var_names if self.var_names: - self.doc = u"%s: %s\n\n%s"%(_('ID'), self.var_names[0], self.doc) + self.doc = u"%s: %s\n\n%s"%(_('ID'), self.var_names[0], format_doc(self.doc)) self.default_values = OrderedDict() for x in var_names: self.default_values[x] = defaults[x] @@ -181,7 +203,7 @@ class Tweaks(QAbstractListModel, AdaptSQP): # {{{ line = lines[pos] if not line.startswith('#'): break - doc.append(line[1:].strip()) + doc.append(line[1:].rstrip()) doc = '\n'.join(doc) while True: try: @@ -394,7 +416,6 @@ class ConfigWidget(ConfigWidgetBase): hb.l = l2 = QVBoxLayout(hb) self.help = h = QPlainTextEdit(self) l2.addWidget(h) - h.setLineWrapMode(QPlainTextEdit.NoWrap) h.setReadOnly(True) g.addWidget(hb, 1, 0, 1, 3)