mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
665105d96c
@ -9,7 +9,7 @@ from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel,
|
|||||||
QDialogButtonBox, QColor, QComboBox, QIcon)
|
QDialogButtonBox, QColor, QComboBox, QIcon)
|
||||||
|
|
||||||
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
||||||
from calibre.gui2.complete import MultiCompleteComboBox
|
from calibre.gui2.complete import MultiCompleteLineEdit
|
||||||
from calibre.gui2 import error_dialog
|
from calibre.gui2 import error_dialog
|
||||||
|
|
||||||
class TemplateLineEditor(QLineEdit):
|
class TemplateLineEditor(QLineEdit):
|
||||||
@ -64,14 +64,15 @@ class TagWizard(QDialog):
|
|||||||
l = QGridLayout()
|
l = QGridLayout()
|
||||||
self.setLayout(l)
|
self.setLayout(l)
|
||||||
l.setColumnStretch(0, 1)
|
l.setColumnStretch(0, 1)
|
||||||
l.addWidget(QLabel(_('Tag Value')), 0, 0, 1, 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)
|
l.addWidget(QLabel(_('Color')), 0, 1, 1, 1)
|
||||||
self.tagboxes = []
|
self.tagboxes = []
|
||||||
self.colorboxes = []
|
self.colorboxes = []
|
||||||
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, '')
|
||||||
for i in range(0, 10):
|
for i in range(0, 10):
|
||||||
tb = MultiCompleteComboBox(self)
|
tb = MultiCompleteLineEdit(self)
|
||||||
tb.set_separator(', ')
|
tb.set_separator(', ')
|
||||||
tb.update_items_cache(self.tags)
|
tb.update_items_cache(self.tags)
|
||||||
self.tagboxes.append(tb)
|
self.tagboxes.append(tb)
|
||||||
@ -102,10 +103,11 @@ class TagWizard(QDialog):
|
|||||||
|
|
||||||
def accepted(self):
|
def accepted(self):
|
||||||
res = ("program:\n#tag wizard -- do not directly edit\n"
|
res = ("program:\n#tag wizard -- do not directly edit\n"
|
||||||
" t = field('tags');\n first_non_empty(\n")
|
" t = field('tags');\n first_non_empty(\n")
|
||||||
lines = []
|
lines = []
|
||||||
for tb, cb in zip(self.tagboxes, self.colorboxes):
|
for tb, cb in zip(self.tagboxes, self.colorboxes):
|
||||||
tags = [t.strip() for t in unicode(tb.currentText()).split(',') if t.strip()]
|
tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()]
|
||||||
|
tags = '$|^'.join(tags)
|
||||||
c = unicode(cb.currentText()).strip()
|
c = unicode(cb.currentText()).strip()
|
||||||
if not tags or not c:
|
if not tags or not c:
|
||||||
continue
|
continue
|
||||||
@ -114,14 +116,13 @@ class TagWizard(QDialog):
|
|||||||
_('The color {0} is not valid').format(c),
|
_('The color {0} is not valid').format(c),
|
||||||
show=True, show_copy_button=False)
|
show=True, show_copy_button=False)
|
||||||
return False
|
return False
|
||||||
for t in tags:
|
lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(tags, c))
|
||||||
lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(t, c))
|
|
||||||
res += ',\n'.join(lines)
|
res += ',\n'.join(lines)
|
||||||
res += ')\n'
|
res += ')\n'
|
||||||
self.template = res
|
self.template = res
|
||||||
res = ''
|
res = ''
|
||||||
for tb, cb in zip(self.tagboxes, self.colorboxes):
|
for tb, cb in zip(self.tagboxes, self.colorboxes):
|
||||||
t = unicode(tb.currentText()).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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user