diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 97400c45bd..c96d980505 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -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('

' + _('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 ' + '

{#column:switch(foo,blue,bar,red,black)}
' + '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' + "
program: \n"
+                  "    t = field('tags'); \n"
+                  "    first_non_empty(\n"
+                  "        in_list(t, ',', '^Science Fiction$', 'blue', ''), \n"
+                  "        in_list(t, ',', '^Mystery$', 'red', 'black'))
" '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' + "
program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')
") + '

' + + _('You can access a multi-line template editor from the ' + 'context menu (right-click).') + '

' + _('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 ' diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index aa5afe26dd..1194109c6c 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -424,7 +424,12 @@ then the tags will be displayed each on their own line. - + + + true + + + @@ -483,6 +488,9 @@ then the tags will be displayed each on their own line. + + true + 0 diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 59a750bcc5..c53277f3ce 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -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()