Improve formatting of help in Preferences->Tweaks

Lines are now wrapped by default and blockquotes are formatted uniformly
with four leading spaces.
This commit is contained in:
Kovid Goyal 2018-05-16 10:50:44 +05:30
parent c1ef1a8557
commit 46f19333c9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 55 additions and 33 deletions

View File

@ -18,12 +18,10 @@ defaults.
# 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
# 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.
# 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'
@ -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
# 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
# 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+'
@ -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']

View File

@ -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)