diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index 7234c93a3f..b79354a5c9 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -159,6 +159,9 @@ class ConditionEditor(QWidget): # {{{ self.action_box.clear() self.action_box.addItem('', '') col = self.current_col + if not col: + self.init_value_box() + return m = self.fm[col] dt = m['datatype'] if dt in self.action_map: @@ -184,11 +187,11 @@ class ConditionEditor(QWidget): # {{{ self.value_box.setInputMask('') self.value_box.setValidator(None) col = self.current_col - m = self.fm[col] - dt = m['datatype'] action = self.current_action if not col or not action: return + m = self.fm[col] + dt = m['datatype'] tt = '' if col == 'identifiers': tt = _('Enter either an identifier type or an ' diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index 0009b4636a..584cb01e54 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -79,9 +79,12 @@ class Rule(object): # {{{ if dt == 'bool': return self.bool_condition(col, action, val) - if dt in ('int', 'float', 'rating'): + if dt in ('int', 'float'): return self.number_condition(col, action, val) + if dt == 'rating': + return self.rating_condition(col, action, val) + if dt == 'datetime': return self.date_condition(col, action, val) @@ -114,9 +117,16 @@ class Rule(object): # {{{ 'lt': ('1', '', ''), 'gt': ('', '', '1') }[action] - lt, eq, gt = '', '1', '' return "cmp(raw_field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) + def rating_condition(self, col, action, val): + lt, eq, gt = { + 'eq': ('', '1', ''), + 'lt': ('1', '', ''), + 'gt': ('', '', '1') + }[action] + return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) + def date_condition(self, col, action, val): lt, eq, gt = { 'eq': ('', '1', ''),