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:
Charles Haley 2011-05-22 15:22:33 +01:00
parent 3c92c4a988
commit 4ddb1e852b
3 changed files with 43 additions and 8 deletions

View File

@ -159,7 +159,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.df_up_button.clicked.connect(self.move_df_up)
self.df_down_button.clicked.connect(self.move_df_down)
self.color_help_text.setWordWrap(True)
self.color_help_text.setText('<p>' +
_('Here you can specify coloring rules for fields shown in the '
'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. '
'For example, you can set the title to always display in '
'green using the template "green" (without the quotes). '
'To show the title in blue if the book has the tag "Science '
'Fiction", red if the book has the tag "Mystery", or black if '
'the book has neither tag, use '
'"{tags:switch(Science Fiction,blue,Mystery,red,)}" '
'To show the title in the color named in the custom column '
'#column, use "{#column}". To show the title in blue if the '
'custom column #column contains the value "foo", in red if the '
'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 '
'two formats, and red if more, use '
"\"program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')\"") +
'two formats, and red if more, use'
"<pre>program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')</pre>") +
'</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 '
'of values", it is possible and often easier to specify the '
'colors in the column definition dialog. There you can '

View File

@ -424,7 +424,12 @@ then the tags will be displayed each on their own line.</string>
</widget>
</item>
<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>
</item>
<item row="1" column="1">
@ -483,6 +488,9 @@ then the tags will be displayed each on their own line.</string>
</item>
<item row="21" column="0" colspan="2">
<widget class="QTextEdit" name="colors_box">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding">
<horstretch>0</horstretch>

View File

@ -327,6 +327,22 @@ class BuiltinSwitch(BuiltinFormatterFunction):
return args[i+1]
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):
name = 're'
arg_count = 3
@ -591,6 +607,7 @@ builtin_first_non_empty = BuiltinFirstNonEmpty()
builtin_field = BuiltinField()
builtin_format_date = BuiltinFormat_date()
builtin_ifempty = BuiltinIfempty()
builtin_in_list = BuiltinInList()
builtin_list_item = BuiltinListitem()
builtin_lookup = BuiltinLookup()
builtin_lowercase = BuiltinLowercase()