mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improvements on coloring: add an in_list formatter function. Add more documentation in the preference screen. Add a scroll bar to the doc in the preferences screen.
This commit is contained in:
parent
3c92c4a988
commit
4ddb1e852b
@ -159,7 +159,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
self.df_up_button.clicked.connect(self.move_df_up)
|
self.df_up_button.clicked.connect(self.move_df_up)
|
||||||
self.df_down_button.clicked.connect(self.move_df_down)
|
self.df_down_button.clicked.connect(self.move_df_down)
|
||||||
|
|
||||||
self.color_help_text.setWordWrap(True)
|
|
||||||
self.color_help_text.setText('<p>' +
|
self.color_help_text.setText('<p>' +
|
||||||
_('Here you can specify coloring rules for fields shown in the '
|
_('Here you can specify coloring rules for fields shown in the '
|
||||||
'library view. Choose the field you wish to color, then '
|
'library view. Choose the field you wish to color, then '
|
||||||
@ -169,14 +168,25 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
'below. You can use any legal template expression. '
|
'below. You can use any legal template expression. '
|
||||||
'For example, you can set the title to always display in '
|
'For example, you can set the title to always display in '
|
||||||
'green using the template "green" (without the quotes). '
|
'green using the template "green" (without the quotes). '
|
||||||
'To show the title in blue if the book has the tag "Science '
|
'To show the title in the color named in the custom column '
|
||||||
'Fiction", red if the book has the tag "Mystery", or black if '
|
'#column, use "{#column}". To show the title in blue if the '
|
||||||
'the book has neither tag, use '
|
'custom column #column contains the value "foo", in red if the '
|
||||||
'"{tags:switch(Science Fiction,blue,Mystery,red,)}" '
|
'column contains the value "bar", otherwise in black, use '
|
||||||
|
'<pre>{#column:switch(foo,blue,bar,red,black)}</pre>'
|
||||||
|
'To show the title in blue if the book has the exact tag '
|
||||||
|
'"Science Fiction", red if the book has the exact tag '
|
||||||
|
'"Mystery", or black if the book has neither tag, use'
|
||||||
|
"<pre>program: \n"
|
||||||
|
" t = field('tags'); \n"
|
||||||
|
" first_non_empty(\n"
|
||||||
|
" in_list(t, ',', '^Science Fiction$', 'blue', ''), \n"
|
||||||
|
" in_list(t, ',', '^Mystery$', 'red', 'black'))</pre>"
|
||||||
'To show the title in green if it has one format, blue if it '
|
'To show the title in green if it has one format, blue if it '
|
||||||
'two formats, and red if more, use'
|
'two formats, and red if more, use'
|
||||||
"\"program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')\"") +
|
"<pre>program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')</pre>") +
|
||||||
'</p><p>' +
|
'</p><p>' +
|
||||||
|
_('You can access a multi-line template editor from the '
|
||||||
|
'context menu (right-click).') + '</p><p>' +
|
||||||
_('Note: if you want to color a "custom column with a fixed set '
|
_('Note: if you want to color a "custom column with a fixed set '
|
||||||
'of values", it is possible and often easier to specify the '
|
'of values", it is possible and often easier to specify the '
|
||||||
'colors in the column definition dialog. There you can '
|
'colors in the column definition dialog. There you can '
|
||||||
|
@ -424,7 +424,12 @@ then the tags will be displayed each on their own line.</string>
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="color_help_text">
|
<widget class="QTextEdit" name="color_help_text">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<sizepolicy vsizetype="Minimum" hsizetype="Expanding">
|
||||||
|
</sizepolicy>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="1" column="1">
|
||||||
@ -483,6 +488,9 @@ then the tags will be displayed each on their own line.</string>
|
|||||||
</item>
|
</item>
|
||||||
<item row="21" column="0" colspan="2">
|
<item row="21" column="0" colspan="2">
|
||||||
<widget class="QTextEdit" name="colors_box">
|
<widget class="QTextEdit" name="colors_box">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy vsizetype="Expanding" hsizetype="Expanding">
|
<sizepolicy vsizetype="Expanding" hsizetype="Expanding">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
|
@ -327,6 +327,22 @@ class BuiltinSwitch(BuiltinFormatterFunction):
|
|||||||
return args[i+1]
|
return args[i+1]
|
||||||
i += 2
|
i += 2
|
||||||
|
|
||||||
|
class BuiltinInList(BuiltinFormatterFunction):
|
||||||
|
name = 'in_list'
|
||||||
|
arg_count = 5
|
||||||
|
doc = _('in_list(val, separator, pattern, found_val, not_found_val) -- '
|
||||||
|
'treat val as a list of items separated by separator, '
|
||||||
|
'comparing the pattern against each value in the list. If the '
|
||||||
|
'pattern matches a value, return found_val, otherwise return '
|
||||||
|
'not_found_val.')
|
||||||
|
|
||||||
|
def evaluate(self, formatter, kwargs, mi, locals, val, sep, pat, fv, nfv):
|
||||||
|
l = [v.strip() for v in val.split(sep) if v.strip()]
|
||||||
|
for v in l:
|
||||||
|
if re.search(pat, v):
|
||||||
|
return fv
|
||||||
|
return nfv
|
||||||
|
|
||||||
class BuiltinRe(BuiltinFormatterFunction):
|
class BuiltinRe(BuiltinFormatterFunction):
|
||||||
name = 're'
|
name = 're'
|
||||||
arg_count = 3
|
arg_count = 3
|
||||||
@ -591,6 +607,7 @@ builtin_first_non_empty = BuiltinFirstNonEmpty()
|
|||||||
builtin_field = BuiltinField()
|
builtin_field = BuiltinField()
|
||||||
builtin_format_date = BuiltinFormat_date()
|
builtin_format_date = BuiltinFormat_date()
|
||||||
builtin_ifempty = BuiltinIfempty()
|
builtin_ifempty = BuiltinIfempty()
|
||||||
|
builtin_in_list = BuiltinInList()
|
||||||
builtin_list_item = BuiltinListitem()
|
builtin_list_item = BuiltinListitem()
|
||||||
builtin_lookup = BuiltinLookup()
|
builtin_lookup = BuiltinLookup()
|
||||||
builtin_lowercase = BuiltinLowercase()
|
builtin_lowercase = BuiltinLowercase()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user