From 52da86dbb6fa48d61ea852436082b6c7b8607e82 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 13:17:07 +0100 Subject: [PATCH] Added an else box to the tag color wizard. Also added more extensive tooltips. --- .../gui2/dialogs/template_line_editor.py | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index a724b5b072..d466cecc55 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -69,10 +69,38 @@ class TagWizard(QDialog): self.setLayout(l) l.setColumnStretch(0, 1) l.setColumnMinimumWidth(0, 300) - l.addWidget(QLabel(_('Tags (more than one per box permitted)')), 0, 0, 1, 1) - l.addWidget(QLabel(_('Color')), 0, 1, 1, 1) + h = QLabel(_('Tags (see the popup help for more information)')) + h.setToolTip('
' +
+ _('You can enter more than one tag per box, separated by commas. '
+ 'The comparison ignores letter case.
'
+ 'A tag value can be a regular expression. '
+ 'When using regular expressions, note that the wizard '
+ 'puts anchors (^ and $) around the expression, so you '
+ 'must ensure your expression matches from the beginning '
+ 'to the end of the tag.
'
+ 'Regular expression examples:') + '
.*
matches any tag. No empty tags are '
+ 'checked, so you don\'t need to worry about empty stringsA.*
matches any tag beginning with A.*mystery.*
matches any tag containing '
+ 'the word "mystery"' + + _('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.') + '
') + l.addWidget(c, 0, 1, 1, 1) + c = QLabel(_('Color if tag not found')) + c.setToolTip('' + + _('This box is usually filled in only on the last test. If it is ' + 'filled in before the last test, then the color for tag found box ' + 'must be empty or all the rest of the tests will be ignored.') + '
') + l.addWidget(c, 0, 2, 1, 1) self.tagboxes = [] self.colorboxes = [] + self.nfcolorboxes = [] self.colors = [unicode(s) for s in list(QColor.colorNames())] self.colors.insert(0, '') for i in range(0, 10): @@ -85,15 +113,25 @@ class TagWizard(QDialog): cb.addItems(self.colors) self.colorboxes.append(cb) l.addWidget(cb, i+1, 1, 1, 1) + cb = QComboBox(self) + cb.addItems(self.colors) + self.nfcolorboxes.append(cb) + l.addWidget(cb, i+1, 2, 1, 1) if txt: lines = txt.split('\n')[3:] i = 0 for line in lines: if line.startswith('#'): - t,c = line[1:].split(':|:') + vals = line[1:].split(':|:') + if len(vals) == 2: + t, c = vals + nc = '' + else: + t,c,nc = vals try: self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c)) + self.nfcolorboxes[i].setCurrentIndex(self.nfcolorboxes[i].findText(nc)) self.tagboxes[i].setText(t) except: pass @@ -109,28 +147,35 @@ class TagWizard(QDialog): res = ("program:\n#tag wizard -- do not directly edit\n" " t = field('tags');\n first_non_empty(\n") lines = [] - for tb, cb in zip(self.tagboxes, self.colorboxes): + for tb, cb, nfcb in zip(self.tagboxes, self.colorboxes, self.nfcolorboxes): tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()] tags = '$|^'.join(tags) c = unicode(cb.currentText()).strip() - if not tags or not c: + nfc = unicode(nfcb.currentText()).strip() + if not tags or not (c or nfc): continue 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 - lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(tags, c)) + 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 + lines.append(" in_list(t, ',', '^{0}$', '{1}', '{2}')".format(tags, c, nfc)) res += ',\n'.join(lines) res += ')\n' self.template = res res = '' - for tb, cb in zip(self.tagboxes, self.colorboxes): + for tb, cb, nfcb in zip(self.tagboxes, self.colorboxes, self.nfcolorboxes): t = unicode(tb.text()).strip() if t.endswith(','): t = t[:-1] c = unicode(cb.currentText()).strip() + nfc = unicode(nfcb.currentText()).strip() if t and c: - res += '#' + t + ':|:' + c + '\n' + res += '#' + t + ':|:' + c + ':|:' + nfc + '\n' self.template += res self.accept()