mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Yet another improvement on the color wizard.
Make 'None' compare to zero in the formatter function 'cmp'.
This commit is contained in:
parent
1682265621
commit
cdeb8ade3d
@ -46,8 +46,8 @@ class TemplateLineEditor(QLineEdit):
|
|||||||
menu.exec_(event.globalPos())
|
menu.exec_(event.globalPos())
|
||||||
|
|
||||||
def clear_field(self):
|
def clear_field(self):
|
||||||
self.setText('')
|
|
||||||
self.txt = None
|
self.txt = None
|
||||||
|
self.setText('')
|
||||||
self.setReadOnly(False)
|
self.setReadOnly(False)
|
||||||
self.setStyleSheet('TemplateLineEditor { color: black }')
|
self.setStyleSheet('TemplateLineEditor { color: black }')
|
||||||
|
|
||||||
@ -95,6 +95,39 @@ class TemplateLineEditor(QLineEdit):
|
|||||||
|
|
||||||
class TagWizard(QDialog):
|
class TagWizard(QDialog):
|
||||||
|
|
||||||
|
text_template = " strcmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')"
|
||||||
|
text_empty_template = " test(field('{f}'), '{fv}', '{tv}')"
|
||||||
|
text_re_template = " contains(field('{f}'), '{v}', '{tv}', '{fv}')"
|
||||||
|
|
||||||
|
templates = {
|
||||||
|
'text.mult' : " str_in_list(field('{f}'), '{mult}', '{v}', '{tv}', '{fv}')",
|
||||||
|
'text.mult.re' : " in_list(field('{f}'), '{mult}', '^{v}$', '{tv}', '{fv}')",
|
||||||
|
'text.mult.empty' : " test(field('{f}'), '{fv}', '{tv}')",
|
||||||
|
'text' : text_template,
|
||||||
|
'text.re' : text_re_template,
|
||||||
|
'text.empty' : text_empty_template,
|
||||||
|
'rating' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')",
|
||||||
|
'rating.empty' : text_empty_template,
|
||||||
|
'int' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')",
|
||||||
|
'int.empty' : text_empty_template,
|
||||||
|
'float' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')",
|
||||||
|
'float.empty' : text_empty_template,
|
||||||
|
'bool' : " strcmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')",
|
||||||
|
'bool.empty' : text_empty_template,
|
||||||
|
'series' : text_template,
|
||||||
|
'series.re' : text_re_template,
|
||||||
|
'series.empty' : text_empty_template,
|
||||||
|
'composite' : text_template,
|
||||||
|
'composite.re' : text_re_template,
|
||||||
|
'composite.empty' : text_empty_template,
|
||||||
|
'enumeration' : text_template,
|
||||||
|
'enumeration.re' : text_re_template,
|
||||||
|
'enumeration.empty' : text_empty_template,
|
||||||
|
'comments' : text_template,
|
||||||
|
'comments.re' : text_re_template,
|
||||||
|
'comments.empty' : text_empty_template,
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, parent, db, txt, mi):
|
def __init__(self, parent, db, txt, mi):
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
self.setWindowTitle(_('Coloring Wizard'))
|
self.setWindowTitle(_('Coloring Wizard'))
|
||||||
@ -106,11 +139,19 @@ class TagWizard(QDialog):
|
|||||||
self.completion_values = defaultdict(dict)
|
self.completion_values = defaultdict(dict)
|
||||||
for k in db.all_field_keys():
|
for k in db.all_field_keys():
|
||||||
m = db.metadata_for_field(k)
|
m = db.metadata_for_field(k)
|
||||||
if m['datatype'] in ('text', 'enumeration', 'series') and \
|
if k.endswith('_index') or (
|
||||||
m['is_category'] and k not in ('identifiers'):
|
m['kind'] == 'field' and m['name'] and
|
||||||
|
k not in ('ondevice', 'path', 'size', 'sort') and
|
||||||
|
m['datatype'] not in ('datetime')):
|
||||||
self.columns.append(k)
|
self.columns.append(k)
|
||||||
|
self.completion_values[k]['dt'] = m['datatype']
|
||||||
if m['is_custom']:
|
if m['is_custom']:
|
||||||
self.completion_values[k]['v'] = db.all_custom(m['label'])
|
if m['datatype'] in ('int', 'float'):
|
||||||
|
self.completion_values[k]['v'] = []
|
||||||
|
elif m['datatype'] == 'bool':
|
||||||
|
self.completion_values[k]['v'] = [_('Yes'), _('No')]
|
||||||
|
else:
|
||||||
|
self.completion_values[k]['v'] = db.all_custom(m['label'])
|
||||||
elif k == 'tags':
|
elif k == 'tags':
|
||||||
self.completion_values[k]['v'] = db.all_tags()
|
self.completion_values[k]['v'] = db.all_tags()
|
||||||
elif k == 'formats':
|
elif k == 'formats':
|
||||||
@ -127,12 +168,15 @@ class TagWizard(QDialog):
|
|||||||
replace('|', ',') for v in f()]
|
replace('|', ',') for v in f()]
|
||||||
else:
|
else:
|
||||||
self.completion_values[k]['v'] = [v[1] for v in f()]
|
self.completion_values[k]['v'] = [v[1] for v in f()]
|
||||||
|
else:
|
||||||
|
self.completion_values[k]['v'] = []
|
||||||
|
|
||||||
if k in self.completion_values:
|
if k in self.completion_values:
|
||||||
if k == 'authors':
|
if k == 'authors':
|
||||||
self.completion_values[k]['m'] = None
|
mult = '&'
|
||||||
else:
|
else:
|
||||||
self.completion_values[k]['m'] = m['is_multiple']
|
mult = ',' if m['is_multiple'] == '|' else m['is_multiple']
|
||||||
|
self.completion_values[k]['m'] = mult
|
||||||
|
|
||||||
self.columns.sort(key=sort_key)
|
self.columns.sort(key=sort_key)
|
||||||
self.columns.insert(0, '')
|
self.columns.insert(0, '')
|
||||||
@ -140,12 +184,12 @@ class TagWizard(QDialog):
|
|||||||
l = QGridLayout()
|
l = QGridLayout()
|
||||||
self.setLayout(l)
|
self.setLayout(l)
|
||||||
l.setColumnStretch(2, 10)
|
l.setColumnStretch(2, 10)
|
||||||
l.setColumnMinimumWidth(3, 300)
|
l.setColumnMinimumWidth(5, 300)
|
||||||
|
|
||||||
h = QLabel(_('And'))
|
h = QLabel(_('And'))
|
||||||
h.setToolTip('<p>' +
|
h.setToolTip('<p>' +
|
||||||
_('Set this box to indicate that the two conditions must both '
|
_('Set this box to indicate that the two conditions must both '
|
||||||
'be true to return the "color if value found". For example, you '
|
'be true to use the color. For example, you '
|
||||||
'can check if two tags are present, if the book has a tag '
|
'can check if two tags are present, if the book has a tag '
|
||||||
'and a #read custom column is checked, or if a book has '
|
'and a #read custom column is checked, or if a book has '
|
||||||
'some tag and has a particular format.'))
|
'some tag and has a particular format.'))
|
||||||
@ -155,107 +199,106 @@ class TagWizard(QDialog):
|
|||||||
h.setAlignment(Qt.AlignCenter)
|
h.setAlignment(Qt.AlignCenter)
|
||||||
l.addWidget(h, 0, 1, 1, 1)
|
l.addWidget(h, 0, 1, 1, 1)
|
||||||
|
|
||||||
h = QLabel(_('Not'))
|
h = QLabel(_('is'))
|
||||||
h.setToolTip('<p>' +
|
|
||||||
_('Set this box to indicate that the value must <b>not</b> match '
|
|
||||||
'to return the "color if value found". For example, you '
|
|
||||||
'can check if a tag does not exist by entering that tag '
|
|
||||||
'and checking this box. You can check if tags are empty by '
|
|
||||||
'checking this box, entering .* (period asterisk) for the text, '
|
|
||||||
'then checking the RE box. The .* regular expression matches '
|
|
||||||
'anything, so if this box is checked, it matches nothing. '
|
|
||||||
'This box is particularly useful when using the AND box.'))
|
|
||||||
h.setAlignment(Qt.AlignCenter)
|
h.setAlignment(Qt.AlignCenter)
|
||||||
l.addWidget(h, 0, 2, 1, 1)
|
l.addWidget(h, 0, 2, 1, 1)
|
||||||
|
|
||||||
h = QLabel(_('Values (see the popup help for more information)'))
|
h = QLabel(_('not'))
|
||||||
|
h.setToolTip('<p>' +
|
||||||
|
_('Check this box to indicate that the value must <b>not</b> match '
|
||||||
|
'to use the color. For example, you can check if a tag does '
|
||||||
|
'not exist by entering that tag and checking this box.') + '</p>')
|
||||||
|
h.setAlignment(Qt.AlignCenter)
|
||||||
|
l.addWidget(h, 0, 3, 1, 1)
|
||||||
|
|
||||||
|
c = QLabel(_('empty'))
|
||||||
|
c.setToolTip('<p>' +
|
||||||
|
_('Check this box to check if the column is empty') + '</p>')
|
||||||
|
l.addWidget(c, 0, 4, 1, 1)
|
||||||
|
|
||||||
|
h = QLabel(_('Values'))
|
||||||
h.setAlignment(Qt.AlignCenter)
|
h.setAlignment(Qt.AlignCenter)
|
||||||
h.setToolTip('<p>' +
|
h.setToolTip('<p>' +
|
||||||
_('You can enter more than one value per box, separated by commas. '
|
_('You can enter more than one value per box, separated by commas. '
|
||||||
'The comparison ignores letter case. Special note: you can '
|
'The comparison ignores letter case. Special note: authors are '
|
||||||
'enter at most one author.<br>'
|
'separated by ampersands (&).<br>'
|
||||||
'A value can be a regular expression. Check the box to turn '
|
'A value can be a regular expression. Check the box to turn '
|
||||||
'them on. When using regular expressions, note that the wizard '
|
'them on. When using regular expressions, note that the wizard '
|
||||||
'puts anchors (^ and $) around the expression, so you '
|
'puts anchors (^ and $) around the expression, so you '
|
||||||
'must ensure your expression matches from the beginning '
|
'must ensure your expression matches from the beginning '
|
||||||
'to the end of the column you are checking.<br>'
|
'to the end of the column/value you are checking.<br>'
|
||||||
'Regular expression examples:') + '<ul>' +
|
'Regular expression examples:') + '<ul>' +
|
||||||
_('<li><code><b>.*</b></code> matches anything in the column. No '
|
_('<li><code><b>.*</b></code> matches anything in the column.</li>'
|
||||||
'empty values are checked, so you don\'t need to worry about '
|
|
||||||
'empty strings</li>'
|
|
||||||
'<li><code><b>A.*</b></code> matches anything beginning with A</li>'
|
'<li><code><b>A.*</b></code> matches anything beginning with A</li>'
|
||||||
'<li><code><b>.*mystery.*</b></code> matches anything containing '
|
'<li><code><b>.*mystery.*</b></code> matches anything containing '
|
||||||
'the word "mystery"</li>') + '</ul></p>')
|
'the word "mystery"</li>') + '</ul></p>')
|
||||||
l.addWidget(h , 0, 3, 1, 1)
|
l.addWidget(h , 0, 5, 1, 1)
|
||||||
|
|
||||||
c = QLabel(_('is RE'))
|
c = QLabel(_('is RE'))
|
||||||
c.setToolTip('<p>' +
|
c.setToolTip('<p>' +
|
||||||
_('Check this box if the values box contains regular expressions') + '</p>')
|
_('Check this box if the values box contains regular expressions') + '</p>')
|
||||||
l.addWidget(c, 0, 4, 1, 1)
|
|
||||||
|
|
||||||
c = QLabel(_('Color if value found'))
|
|
||||||
c.setToolTip('<p>' +
|
|
||||||
_('At least one of the two color boxes must have a value. Leave '
|
|
||||||
'one color box empty if you want the template to use the next '
|
|
||||||
'line in this wizard. If both boxes are filled in, the rest of '
|
|
||||||
'the lines in this wizard will be ignored.') + '</p>')
|
|
||||||
l.addWidget(c, 0, 5, 1, 1)
|
|
||||||
c = QLabel(_('Color if value not found'))
|
|
||||||
c.setToolTip('<p>' +
|
|
||||||
_('This box is usually filled in only on the last test. If it is '
|
|
||||||
'filled in before the last test, then the color for value found box '
|
|
||||||
'must be empty or all the rest of the tests will be ignored.') + '</p>')
|
|
||||||
l.addWidget(c, 0, 6, 1, 1)
|
l.addWidget(c, 0, 6, 1, 1)
|
||||||
|
|
||||||
self.andboxes = []
|
c = QLabel(_('color'))
|
||||||
self.notboxes = []
|
c.setAlignment(Qt.AlignCenter)
|
||||||
self.tagboxes = []
|
c.setToolTip('<p>' +
|
||||||
self.colorboxes = []
|
_('Use this color if the column matches the tests.') + '</p>')
|
||||||
self.nfcolorboxes = []
|
l.addWidget(c, 0, 7, 1, 1)
|
||||||
self.reboxes = []
|
|
||||||
self.colboxes = []
|
self.andboxes = []
|
||||||
|
self.notboxes = []
|
||||||
|
self.tagboxes = []
|
||||||
|
self.colorboxes = []
|
||||||
|
self.reboxes = []
|
||||||
|
self.colboxes = []
|
||||||
|
self.emptyboxes = []
|
||||||
|
|
||||||
self.colors = [unicode(s) for s in list(QColor.colorNames())]
|
self.colors = [unicode(s) for s in list(QColor.colorNames())]
|
||||||
self.colors.insert(0, '')
|
self.colors.insert(0, '')
|
||||||
|
|
||||||
|
def create_widget(klass, box, layout, row, col, items,
|
||||||
|
align=Qt.AlignCenter, rowspan=False):
|
||||||
|
w = klass(self)
|
||||||
|
if box is not None:
|
||||||
|
box.append(w)
|
||||||
|
if rowspan:
|
||||||
|
layout.addWidget(w, row, col, 2, 1, alignment=Qt.Alignment(align))
|
||||||
|
else:
|
||||||
|
layout.addWidget(w, row, col, 1, 1, alignment=Qt.Alignment(align))
|
||||||
|
if items:
|
||||||
|
w.addItems(items)
|
||||||
|
return w
|
||||||
|
|
||||||
maxlines = 10
|
maxlines = 10
|
||||||
for i in range(1, maxlines+1):
|
for i in range(1, maxlines+1):
|
||||||
ab = QCheckBox(self)
|
w = create_widget(QCheckBox, self.andboxes, l, i, 0, None, rowspan=True)
|
||||||
self.andboxes.append(ab)
|
w.stateChanged.connect(partial(self.and_box_changed, line=i-1))
|
||||||
if i != maxlines:
|
if i == maxlines:
|
||||||
# let the last box float in space
|
# last box is invisible
|
||||||
l.addWidget(ab, i, 0, 2, 1)
|
w.setVisible(False)
|
||||||
ab.stateChanged.connect(partial(self.and_box_changed, line=i-1))
|
|
||||||
else:
|
|
||||||
ab.setVisible(False)
|
|
||||||
|
|
||||||
w = QComboBox(self)
|
w = create_widget(QComboBox, self.colboxes, l, i, 1, self.columns)
|
||||||
w.addItems(self.columns)
|
w.currentIndexChanged[str].connect(partial(self.column_changed, line=i-1))
|
||||||
l.addWidget(w, i, 1, 1, 1)
|
|
||||||
self.colboxes.append(w)
|
|
||||||
|
|
||||||
nb = QCheckBox(self)
|
w = QLabel(self)
|
||||||
self.notboxes.append(nb)
|
w.setText(_('is'))
|
||||||
l.addWidget(nb, i, 2, 1, 1)
|
l.addWidget(w, i, 2, 1, 1)
|
||||||
|
|
||||||
tb = MultiCompleteLineEdit(self)
|
create_widget(QCheckBox, self.notboxes, l, i, 3, None)
|
||||||
tb.set_separator(', ')
|
|
||||||
self.tagboxes.append(tb)
|
|
||||||
l.addWidget(tb, i, 3, 1, 1)
|
|
||||||
w.currentIndexChanged[str].connect(partial(self.column_changed, valbox=tb))
|
|
||||||
|
|
||||||
w = QCheckBox(self)
|
w = create_widget(QCheckBox, self.emptyboxes, l, i, 4, None)
|
||||||
self.reboxes.append(w)
|
w.stateChanged.connect(partial(self.empty_box_changed, line=i-1))
|
||||||
l.addWidget(w, i, 4, 1, 1)
|
|
||||||
|
|
||||||
w = QComboBox(self)
|
create_widget(MultiCompleteLineEdit, self.tagboxes, l, i, 5, None, align=0)
|
||||||
w.addItems(self.colors)
|
create_widget(QCheckBox, self.reboxes, l, i, 6, None)
|
||||||
self.colorboxes.append(w)
|
create_widget(QComboBox, self.colorboxes, l, i, 7, self.colors)
|
||||||
l.addWidget(w, i, 5, 1, 1)
|
|
||||||
|
|
||||||
w = QComboBox(self)
|
w = create_widget(QLabel, None, l, maxlines+1, 5, None)
|
||||||
w.addItems(self.colors)
|
w.setText(_('If none of the tests match, set the color to'))
|
||||||
self.nfcolorboxes.append(w)
|
self.elsebox = create_widget(QComboBox, None, l, maxlines+1, 7, self.colors)
|
||||||
l.addWidget(w, i, 6, 1, 1)
|
self.elsebox.setToolTip('<p>' +
|
||||||
|
_('If this box contains a color, it will be used if none '
|
||||||
|
'of the above rules match.') + '</p>')
|
||||||
|
|
||||||
if txt:
|
if txt:
|
||||||
lines = txt.split('\n')[3:]
|
lines = txt.split('\n')[3:]
|
||||||
@ -263,25 +306,27 @@ class TagWizard(QDialog):
|
|||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith('#'):
|
if line.startswith('#'):
|
||||||
vals = line[1:].split(':|:')
|
vals = line[1:].split(':|:')
|
||||||
|
if len(vals) == 1 and line.startswith('#else:'):
|
||||||
|
try:
|
||||||
|
self.elsebox.setCurrentIndex(self.elsebox.findText(line[6:]))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
continue
|
||||||
if len(vals) == 2:
|
if len(vals) == 2:
|
||||||
t, c = vals
|
t, c = vals
|
||||||
nc = ''
|
|
||||||
re = False
|
|
||||||
f = 'tags'
|
f = 'tags'
|
||||||
a = False
|
a = n = e = re = False
|
||||||
n = False
|
|
||||||
else:
|
else:
|
||||||
t,c,f,nc,re,a,n = vals
|
t,c,f,re,a,n,e = vals
|
||||||
try:
|
try:
|
||||||
self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f))
|
self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f))
|
||||||
self.colorboxes[i].setCurrentIndex(
|
self.colorboxes[i].setCurrentIndex(
|
||||||
self.colorboxes[i].findText(c))
|
self.colorboxes[i].findText(c))
|
||||||
self.nfcolorboxes[i].setCurrentIndex(
|
|
||||||
self.nfcolorboxes[i].findText(nc))
|
|
||||||
self.tagboxes[i].setText(t)
|
self.tagboxes[i].setText(t)
|
||||||
self.reboxes[i].setChecked(re == '2')
|
self.reboxes[i].setChecked(re == '2')
|
||||||
self.andboxes[i].setChecked(a == '2')
|
self.andboxes[i].setChecked(a == '2')
|
||||||
self.notboxes[i].setChecked(n == '2')
|
self.notboxes[i].setChecked(n == '2')
|
||||||
|
self.emptyboxes[i].setChecked(e == '2')
|
||||||
i += 1
|
i += 1
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -290,13 +335,17 @@ class TagWizard(QDialog):
|
|||||||
l.addWidget(w, 99, 1, 1, 1)
|
l.addWidget(w, 99, 1, 1, 1)
|
||||||
w = self.test_box = QLineEdit(self)
|
w = self.test_box = QLineEdit(self)
|
||||||
w.setReadOnly(True)
|
w.setReadOnly(True)
|
||||||
l.addWidget(w, 99, 3, 1, 1)
|
l.addWidget(w, 99, 2, 1, 5)
|
||||||
w = QPushButton(_('Test'))
|
w = QPushButton(_('Test'))
|
||||||
l.addWidget(w, 99, 5, 1, 1)
|
w.setToolTip('<p>' +
|
||||||
|
_('Press this button to see what color this template will '
|
||||||
|
'produce for the book that was selected when you '
|
||||||
|
'entered the preferences dialog.'))
|
||||||
|
l.addWidget(w, 99, 7, 1, 1)
|
||||||
w.clicked.connect(self.preview)
|
w.clicked.connect(self.preview)
|
||||||
|
|
||||||
bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self)
|
bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self)
|
||||||
l.addWidget(bb, 100, 3, 1, 2)
|
l.addWidget(bb, 100, 5, 1, 3)
|
||||||
bb.accepted.connect(self.accepted)
|
bb.accepted.connect(self.accepted)
|
||||||
bb.rejected.connect(self.reject)
|
bb.rejected.connect(self.reject)
|
||||||
self.template = ''
|
self.template = ''
|
||||||
@ -308,14 +357,22 @@ class TagWizard(QDialog):
|
|||||||
_('EXCEPTION'), self.mi)
|
_('EXCEPTION'), self.mi)
|
||||||
self.test_box.setText(t)
|
self.test_box.setText(t)
|
||||||
|
|
||||||
def column_changed(self, s, valbox=None):
|
def column_changed(self, s, line=None):
|
||||||
k = unicode(s)
|
k = unicode(s)
|
||||||
if k in self.completion_values:
|
if k in self.completion_values:
|
||||||
|
valbox = self.tagboxes[line]
|
||||||
valbox.update_items_cache(self.completion_values[k]['v'])
|
valbox.update_items_cache(self.completion_values[k]['v'])
|
||||||
if self.completion_values[k]['m']:
|
if self.completion_values[k]['m']:
|
||||||
valbox.set_separator(', ')
|
valbox.set_separator(', ')
|
||||||
else:
|
else:
|
||||||
valbox.set_separator(None)
|
valbox.set_separator(None)
|
||||||
|
|
||||||
|
dt = self.completion_values[k]['dt']
|
||||||
|
if dt in ('int', 'float', 'rating', 'bool'):
|
||||||
|
self.reboxes[line].setChecked(0)
|
||||||
|
self.reboxes[line].setEnabled(False)
|
||||||
|
else:
|
||||||
|
self.reboxes[line].setEnabled(True)
|
||||||
else:
|
else:
|
||||||
valbox.update_items_cache([])
|
valbox.update_items_cache([])
|
||||||
valbox.set_separator(None)
|
valbox.set_separator(None)
|
||||||
@ -324,59 +381,44 @@ class TagWizard(QDialog):
|
|||||||
res = ("program:\n#tag wizard -- do not directly edit\n"
|
res = ("program:\n#tag wizard -- do not directly edit\n"
|
||||||
" first_non_empty(\n")
|
" first_non_empty(\n")
|
||||||
lines = []
|
lines = []
|
||||||
was_and = False
|
was_and = had_line = False
|
||||||
had_line = False
|
|
||||||
|
|
||||||
line = 0
|
line = 0
|
||||||
for tb, cb, fb, nfcb, reb, ab, nb in zip(
|
for tb, cb, fb, reb, ab, nb, eb in zip(
|
||||||
self.tagboxes, self.colorboxes, self.colboxes,
|
self.tagboxes, self.colorboxes, self.colboxes,
|
||||||
self.nfcolorboxes, self.reboxes, self.andboxes, self.notboxes):
|
self.reboxes, self.andboxes, self.notboxes, self.emptyboxes):
|
||||||
f = unicode(fb.currentText())
|
f = unicode(fb.currentText())
|
||||||
if not f:
|
if not f:
|
||||||
continue
|
continue
|
||||||
m = self.completion_values[f]['m']
|
m = self.completion_values[f]['m']
|
||||||
|
dt = self.completion_values[f]['dt']
|
||||||
c = unicode(cb.currentText()).strip()
|
c = unicode(cb.currentText()).strip()
|
||||||
nfc = unicode(nfcb.currentText()).strip()
|
|
||||||
re = reb.checkState()
|
re = reb.checkState()
|
||||||
a = ab.checkState()
|
a = ab.checkState()
|
||||||
n = nb.checkState()
|
n = nb.checkState()
|
||||||
|
e = eb.checkState()
|
||||||
line += 1
|
line += 1
|
||||||
|
|
||||||
if n == 2:
|
tval = '' if n == 2 else '1'
|
||||||
tval = ''
|
fval = '1' if n == 2 else ''
|
||||||
fval = '1'
|
|
||||||
else:
|
|
||||||
tval = '1'
|
|
||||||
fval = ''
|
|
||||||
|
|
||||||
if m:
|
if m:
|
||||||
tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()]
|
tags = [t.strip() for t in unicode(tb.text()).split(m) if t.strip()]
|
||||||
if re == 2:
|
if re == 2:
|
||||||
tags = '$|^'.join(tags)
|
tags = '$|^'.join(tags)
|
||||||
else:
|
else:
|
||||||
tags = ','.join(tags)
|
tags = m.join(tags)
|
||||||
|
if m == '&':
|
||||||
|
tags = tags.replace(',', '|')
|
||||||
else:
|
else:
|
||||||
tags = unicode(tb.text()).strip()
|
tags = unicode(tb.text()).strip()
|
||||||
if f == 'authors':
|
|
||||||
tags.replace(',', '|')
|
|
||||||
|
|
||||||
if (tags or f) and not (tags and f and (a == 2 or c)):
|
if (tags or f) and not ((tags or e) and f and (a == 2 or c)):
|
||||||
error_dialog(self, _('Invalid line'),
|
error_dialog(self, _('Invalid line'),
|
||||||
_('Line number {0} is not valid').format(line),
|
_('Line number {0} is not valid').format(line),
|
||||||
show=True, show_copy_button=False)
|
show=True, show_copy_button=False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if c not in self.colors:
|
|
||||||
error_dialog(self, _('Invalid color'),
|
|
||||||
_('The color {0} is not valid').format(c),
|
|
||||||
show=True, show_copy_button=False)
|
|
||||||
return False
|
|
||||||
if nfc not in self.colors:
|
|
||||||
error_dialog(self, _('Invalid color'),
|
|
||||||
_('The color {0} is not valid').format(nfc),
|
|
||||||
show=True, show_copy_button=False)
|
|
||||||
return False
|
|
||||||
|
|
||||||
if not was_and:
|
if not was_and:
|
||||||
if had_line:
|
if had_line:
|
||||||
lines[-1] += ','
|
lines[-1] += ','
|
||||||
@ -385,57 +427,58 @@ class TagWizard(QDialog):
|
|||||||
else:
|
else:
|
||||||
lines[-1] += ','
|
lines[-1] += ','
|
||||||
|
|
||||||
if re == 2:
|
key = dt + ('.mult' if m else '') + ('.empty' if e else '') + ('.re' if re else '')
|
||||||
if m:
|
template = self.templates[key]
|
||||||
lines.append(" in_list(field('{1}'), ',', '^{0}$', '{2}', '{3}')".\
|
lines.append(template.format(v=tags, f=f, tv=tval, fv=fval, mult=m))
|
||||||
format(tags, f, tval, fval))
|
|
||||||
else:
|
|
||||||
lines.append(" contains(field('{1}'), '{0}', '{2}', '{3}')".\
|
|
||||||
format(tags, f, tval, fval))
|
|
||||||
else:
|
|
||||||
if m:
|
|
||||||
lines.append(" str_in_list(field('{1}'), ',', '{0}', '{2}', '{3}')".\
|
|
||||||
format(tags, f, tval, fval))
|
|
||||||
else:
|
|
||||||
lines.append(" strcmp(field('{1}'), '{0}', '{3}', '{2}', '{3}')".\
|
|
||||||
format(tags, f, tval, fval))
|
|
||||||
if a == 2:
|
if a == 2:
|
||||||
was_and = True
|
was_and = True
|
||||||
else:
|
else:
|
||||||
was_and = False
|
was_and = False
|
||||||
lines.append(" ), '{0}', '{1}')".format(c, nfc))
|
lines.append(" ), '{0}', '')".format(c))
|
||||||
|
|
||||||
res += '\n'.join(lines)
|
res += '\n'.join(lines)
|
||||||
|
else_txt = unicode(self.elsebox.currentText())
|
||||||
|
if else_txt:
|
||||||
|
res += ",\n '" + else_txt + "'"
|
||||||
res += ')\n'
|
res += ')\n'
|
||||||
self.template = res
|
self.template = res
|
||||||
res = ''
|
res = ''
|
||||||
for tb, cb, fb, nfcb, reb, ab, nb in zip(
|
for tb, cb, fb, reb, ab, nb, eb in zip(
|
||||||
self.tagboxes, self.colorboxes, self.colboxes,
|
self.tagboxes, self.colorboxes, self.colboxes,
|
||||||
self.nfcolorboxes, self.reboxes, self.andboxes, self.notboxes):
|
self.reboxes, self.andboxes, self.notboxes, self.emptyboxes):
|
||||||
t = unicode(tb.text()).strip()
|
t = unicode(tb.text()).strip()
|
||||||
if t.endswith(','):
|
if t.endswith(','):
|
||||||
t = t[:-1]
|
t = t[:-1]
|
||||||
c = unicode(cb.currentText()).strip()
|
c = unicode(cb.currentText()).strip()
|
||||||
f = unicode(fb.currentText())
|
f = unicode(fb.currentText())
|
||||||
nfc = unicode(nfcb.currentText()).strip()
|
|
||||||
re = unicode(reb.checkState())
|
re = unicode(reb.checkState())
|
||||||
a = unicode(ab.checkState())
|
a = unicode(ab.checkState())
|
||||||
n = unicode(nb.checkState())
|
n = unicode(nb.checkState())
|
||||||
if f and t and (a == '2' or c):
|
e = unicode(eb.checkState())
|
||||||
res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + \
|
if f and (t or e) and (a == '2' or c):
|
||||||
nfc + ':|:' + re + ':|:' + a + ':|:' + n + '\n'
|
res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + re + ':|:' + \
|
||||||
|
a + ':|:' + n + ':|:' + e + '\n'
|
||||||
|
res += '#else:' + else_txt + '\n'
|
||||||
self.template += res
|
self.template += res
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def empty_box_changed(self, state, line=None):
|
||||||
|
if state == 2:
|
||||||
|
self.tagboxes[line].setText('')
|
||||||
|
self.tagboxes[line].setEnabled(False)
|
||||||
|
self.reboxes[line].setChecked(0)
|
||||||
|
self.reboxes[line].setEnabled(False)
|
||||||
|
else:
|
||||||
|
self.reboxes[line].setEnabled(True)
|
||||||
|
self.tagboxes[line].setEnabled(True)
|
||||||
|
|
||||||
def and_box_changed(self, state, line=None):
|
def and_box_changed(self, state, line=None):
|
||||||
if state == 2:
|
if state == 2:
|
||||||
self.colorboxes[line].setCurrentIndex(0)
|
self.colorboxes[line].setCurrentIndex(0)
|
||||||
self.colorboxes[line].setEnabled(False)
|
self.colorboxes[line].setEnabled(False)
|
||||||
self.nfcolorboxes[line].setCurrentIndex(0)
|
|
||||||
self.nfcolorboxes[line].setEnabled(False)
|
|
||||||
else:
|
else:
|
||||||
self.colorboxes[line].setEnabled(True)
|
self.colorboxes[line].setEnabled(True)
|
||||||
self.nfcolorboxes[line].setEnabled(True)
|
|
||||||
|
|
||||||
def accepted(self):
|
def accepted(self):
|
||||||
if self.generate_program():
|
if self.generate_program():
|
||||||
|
@ -106,8 +106,8 @@ class BuiltinCmp(BuiltinFormatterFunction):
|
|||||||
'numbers. Returns lt if x < y. Returns eq if x == y. Otherwise returns gt.')
|
'numbers. Returns lt if x < y. Returns eq if x == y. Otherwise returns gt.')
|
||||||
|
|
||||||
def evaluate(self, formatter, kwargs, mi, locals, x, y, lt, eq, gt):
|
def evaluate(self, formatter, kwargs, mi, locals, x, y, lt, eq, gt):
|
||||||
x = float(x if x else 0)
|
x = float(x if x and x != 'None' else 0)
|
||||||
y = float(y if y else 0)
|
y = float(y if y and y != 'None' else 0)
|
||||||
if x < y:
|
if x < y:
|
||||||
return lt
|
return lt
|
||||||
if x == y:
|
if x == y:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user