mirror of
				https://github.com/kovidgoyal/calibre.git
				synced 2025-11-03 19:17:02 -05:00 
			
		
		
		
	Added an else box to the tag color wizard. Also added more extensive tooltips.
This commit is contained in:
		
							parent
							
								
									393cfe78cd
								
							
						
					
					
						commit
						52da86dbb6
					
				@ -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('<p>' +
 | 
			
		||||
             _('You can enter more than one tag per box, separated by commas. '
 | 
			
		||||
               'The comparison ignores letter case.<br>'
 | 
			
		||||
               '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.<br>'
 | 
			
		||||
               'Regular expression examples:') + '<ul>' +
 | 
			
		||||
             _('<li><code><b>.*</b></code> matches any tag. No empty tags are '
 | 
			
		||||
               'checked, so you don\'t need to worry about empty strings</li>'
 | 
			
		||||
               '<li><code><b>A.*</b></code> matches any tag beginning with A</li>'
 | 
			
		||||
               '<li><code><b>.*mystery.*</b></code> matches any tag containing '
 | 
			
		||||
               'the word "mystery"</li>') + '</ul></p>')
 | 
			
		||||
        l.addWidget(h , 0, 0, 1, 1)
 | 
			
		||||
        c = QLabel(_('Color if tag 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, 1, 1, 1)
 | 
			
		||||
        c = QLabel(_('Color if tag 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 tag found box '
 | 
			
		||||
               'must be empty or all the rest of the tests will be ignored.') + '</p>')
 | 
			
		||||
        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()
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user