mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 10:44:09 -04:00
Column coloring/icons: Treat entries with no date as infinite days ago. ALso fix a regression that broke using the template editor
This commit is contained in:
commit
041a56204c
@ -197,8 +197,7 @@ class TemplateHighlighter(QSyntaxHighlighter):
|
|||||||
|
|
||||||
class TemplateDialog(QDialog, Ui_TemplateDialog):
|
class TemplateDialog(QDialog, Ui_TemplateDialog):
|
||||||
|
|
||||||
def __init__(self, parent, text, mi=None, fm=None, color_field=None,
|
def __init__(self, parent, text, mi=None, fm=None, color_field=None):
|
||||||
rule_kind='color'):
|
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
Ui_TemplateDialog.__init__(self)
|
Ui_TemplateDialog.__init__(self)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
@ -265,8 +264,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
|
|||||||
self.function.setCurrentIndex(0)
|
self.function.setCurrentIndex(0)
|
||||||
self.function.currentIndexChanged[str].connect(self.function_changed)
|
self.function.currentIndexChanged[str].connect(self.function_changed)
|
||||||
self.textbox_changed()
|
self.textbox_changed()
|
||||||
self.rule = (rule_kind, None, '')
|
self.rule = (None, '')
|
||||||
self.rule_kind = rule_kind
|
|
||||||
|
|
||||||
tt = _('Template language tutorial')
|
tt = _('Template language tutorial')
|
||||||
self.template_tutorial.setText(
|
self.template_tutorial.setText(
|
||||||
@ -325,5 +323,5 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
|
|||||||
_('The template box cannot be empty'), show=True)
|
_('The template box cannot be empty'), show=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
self.rule = (self.rule_kind, unicode(self.colored_field.currentText()), txt)
|
self.rule = (unicode(self.colored_field.currentText()), txt)
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
@ -742,7 +742,7 @@ class EditRules(QWidget): # {{{
|
|||||||
|
|
||||||
def add_advanced(self):
|
def add_advanced(self):
|
||||||
td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, color_field='')
|
td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, color_field='')
|
||||||
self._add_rule(td)
|
self._add_rule(('color', td[0], td[1]))
|
||||||
|
|
||||||
def edit_rule(self, index):
|
def edit_rule(self, index):
|
||||||
try:
|
try:
|
||||||
@ -755,6 +755,8 @@ class EditRules(QWidget): # {{{
|
|||||||
else:
|
else:
|
||||||
d = TemplateDialog(self, rule, mi=self.mi, fm=self.fm, color_field=col)
|
d = TemplateDialog(self, rule, mi=self.mi, fm=self.fm, color_field=col)
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
|
if len(d.rule) == 2: # Convert template dialog rules to a triple
|
||||||
|
d.rule = ('color', d.rule[0], d.rule[1])
|
||||||
kind, col, r = d.rule
|
kind, col, r = d.rule
|
||||||
if kind and r is not None and col:
|
if kind and r is not None and col:
|
||||||
self.model.replace_rule(index, kind, col, r)
|
self.model.replace_rule(index, kind, col, r)
|
||||||
|
@ -134,8 +134,8 @@ class Rule(object): # {{{
|
|||||||
|
|
||||||
def date_condition(self, col, action, val):
|
def date_condition(self, col, action, val):
|
||||||
if action == 'count_days':
|
if action == 'count_days':
|
||||||
return (("cmp(add(%s, 1), days_between(today(), format_date(raw_field('%s'), 'yyyy-MM-dd')), '', '1', '1')")
|
return (("test(field('%s'), cmp(%s, days_between(today(), format_date(raw_field('%s'), 'yyyy-MM-dd')), '', '1', '1'), '')")
|
||||||
%(val, col))
|
%(col, str(int(val)+1), col))
|
||||||
lt, eq, gt = {
|
lt, eq, gt = {
|
||||||
'eq': ('', '1', ''),
|
'eq': ('', '1', ''),
|
||||||
'lt': ('1', '', ''),
|
'lt': ('1', '', ''),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user