mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
9f7e77c9dc
@ -8,8 +8,8 @@ __docformat__ = 'restructuredtext en'
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox, QIcon,
|
from PyQt4.Qt import (Qt, QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox,
|
||||||
QDialogButtonBox, QColor, QComboBox, QPushButton)
|
QIcon, QDialogButtonBox, QColor, QComboBox, QPushButton)
|
||||||
|
|
||||||
from calibre.ebooks.metadata.book.base import composite_formatter
|
from calibre.ebooks.metadata.book.base import composite_formatter
|
||||||
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
||||||
@ -58,10 +58,10 @@ class TemplateLineEditor(QLineEdit):
|
|||||||
t = TemplateDialog(self, self.text(), self.mi)
|
t = TemplateDialog(self, self.text(), self.mi)
|
||||||
t.setWindowTitle(_('Edit template'))
|
t.setWindowTitle(_('Edit template'))
|
||||||
if t.exec_():
|
if t.exec_():
|
||||||
self.setText(t.textbox.toPlainText())
|
|
||||||
self.txt = None
|
self.txt = None
|
||||||
|
self.setText(t.textbox.toPlainText())
|
||||||
|
|
||||||
def show_wizard_button(self, txt):
|
def enable_wizard_button(self, txt):
|
||||||
if not txt or txt.startswith('program:\n#tag wizard'):
|
if not txt or txt.startswith('program:\n#tag wizard'):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -129,23 +129,51 @@ class TagWizard(QDialog):
|
|||||||
self.completion_values[k]['v'] = [v[1] for v in f()]
|
self.completion_values[k]['v'] = [v[1] for v in f()]
|
||||||
|
|
||||||
if k in self.completion_values:
|
if k in self.completion_values:
|
||||||
self.completion_values[k]['m'] = m['is_multiple']
|
if k == 'authors':
|
||||||
|
self.completion_values[k]['m'] = None
|
||||||
|
else:
|
||||||
|
self.completion_values[k]['m'] = m['is_multiple']
|
||||||
|
|
||||||
self.columns.sort(key=sort_key)
|
self.columns.sort(key=sort_key)
|
||||||
self.columns.insert(0, '')
|
self.columns.insert(0, '')
|
||||||
|
|
||||||
l = QGridLayout()
|
l = QGridLayout()
|
||||||
self.setLayout(l)
|
self.setLayout(l)
|
||||||
l.setColumnStretch(1, 10)
|
l.setColumnStretch(2, 10)
|
||||||
l.setColumnMinimumWidth(1, 300)
|
l.setColumnMinimumWidth(3, 300)
|
||||||
|
|
||||||
h = QLabel(_('Column'))
|
h = QLabel(_('And'))
|
||||||
|
h.setToolTip('<p>' +
|
||||||
|
_('Set this box to indicate that the two conditions must both '
|
||||||
|
'be true to return the "color if value found". For example, you '
|
||||||
|
'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 '
|
||||||
|
'some tag and has a particular format.'))
|
||||||
l.addWidget(h, 0, 0, 1, 1)
|
l.addWidget(h, 0, 0, 1, 1)
|
||||||
|
|
||||||
|
h = QLabel(_('Column'))
|
||||||
|
h.setAlignment(Qt.AlignCenter)
|
||||||
|
l.addWidget(h, 0, 1, 1, 1)
|
||||||
|
|
||||||
|
h = QLabel(_('Not'))
|
||||||
|
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)
|
||||||
|
l.addWidget(h, 0, 2, 1, 1)
|
||||||
|
|
||||||
h = QLabel(_('Values (see the popup help for more information)'))
|
h = QLabel(_('Values (see the popup help for more information)'))
|
||||||
|
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.<br>'
|
'The comparison ignores letter case. Special note: you can '
|
||||||
|
'enter at most one author.<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 '
|
||||||
@ -158,12 +186,12 @@ class TagWizard(QDialog):
|
|||||||
'<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, 1, 1, 1)
|
l.addWidget(h , 0, 3, 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, 2, 1, 1)
|
l.addWidget(c, 0, 4, 1, 1)
|
||||||
|
|
||||||
c = QLabel(_('Color if value found'))
|
c = QLabel(_('Color if value found'))
|
||||||
c.setToolTip('<p>' +
|
c.setToolTip('<p>' +
|
||||||
@ -171,13 +199,16 @@ class TagWizard(QDialog):
|
|||||||
'one color box empty if you want the template to use the next '
|
'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 '
|
'line in this wizard. If both boxes are filled in, the rest of '
|
||||||
'the lines in this wizard will be ignored.') + '</p>')
|
'the lines in this wizard will be ignored.') + '</p>')
|
||||||
l.addWidget(c, 0, 3, 1, 1)
|
l.addWidget(c, 0, 5, 1, 1)
|
||||||
c = QLabel(_('Color if value not found'))
|
c = QLabel(_('Color if value not found'))
|
||||||
c.setToolTip('<p>' +
|
c.setToolTip('<p>' +
|
||||||
_('This box is usually filled in only on the last test. If it is '
|
_('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 '
|
'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>')
|
'must be empty or all the rest of the tests will be ignored.') + '</p>')
|
||||||
l.addWidget(c, 0, 4, 1, 1)
|
l.addWidget(c, 0, 6, 1, 1)
|
||||||
|
|
||||||
|
self.andboxes = []
|
||||||
|
self.notboxes = []
|
||||||
self.tagboxes = []
|
self.tagboxes = []
|
||||||
self.colorboxes = []
|
self.colorboxes = []
|
||||||
self.nfcolorboxes = []
|
self.nfcolorboxes = []
|
||||||
@ -185,31 +216,46 @@ class TagWizard(QDialog):
|
|||||||
self.colboxes = []
|
self.colboxes = []
|
||||||
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):
|
|
||||||
w = QComboBox()
|
maxlines = 10
|
||||||
|
for i in range(1, maxlines+1):
|
||||||
|
ab = QCheckBox(self)
|
||||||
|
self.andboxes.append(ab)
|
||||||
|
if i != maxlines:
|
||||||
|
# let the last box float in space
|
||||||
|
l.addWidget(ab, i, 0, 2, 1)
|
||||||
|
ab.stateChanged.connect(partial(self.and_box_changed, line=i-1))
|
||||||
|
else:
|
||||||
|
ab.setVisible(False)
|
||||||
|
|
||||||
|
w = QComboBox(self)
|
||||||
w.addItems(self.columns)
|
w.addItems(self.columns)
|
||||||
l.addWidget(w, i+1, 0, 1, 1)
|
l.addWidget(w, i, 1, 1, 1)
|
||||||
self.colboxes.append(w)
|
self.colboxes.append(w)
|
||||||
|
|
||||||
|
nb = QCheckBox(self)
|
||||||
|
self.notboxes.append(nb)
|
||||||
|
l.addWidget(nb, i, 2, 1, 1)
|
||||||
|
|
||||||
tb = MultiCompleteLineEdit(self)
|
tb = MultiCompleteLineEdit(self)
|
||||||
tb.set_separator(', ')
|
tb.set_separator(', ')
|
||||||
self.tagboxes.append(tb)
|
self.tagboxes.append(tb)
|
||||||
l.addWidget(tb, i+1, 1, 1, 1)
|
l.addWidget(tb, i, 3, 1, 1)
|
||||||
w.currentIndexChanged[str].connect(partial(self.column_changed, valbox=tb))
|
w.currentIndexChanged[str].connect(partial(self.column_changed, valbox=tb))
|
||||||
|
|
||||||
w = QCheckBox(self)
|
w = QCheckBox(self)
|
||||||
self.reboxes.append(w)
|
self.reboxes.append(w)
|
||||||
l.addWidget(w, i+1, 2, 1, 1)
|
l.addWidget(w, i, 4, 1, 1)
|
||||||
|
|
||||||
w = QComboBox(self)
|
w = QComboBox(self)
|
||||||
w.addItems(self.colors)
|
w.addItems(self.colors)
|
||||||
self.colorboxes.append(w)
|
self.colorboxes.append(w)
|
||||||
l.addWidget(w, i+1, 3, 1, 1)
|
l.addWidget(w, i, 5, 1, 1)
|
||||||
|
|
||||||
w = QComboBox(self)
|
w = QComboBox(self)
|
||||||
w.addItems(self.colors)
|
w.addItems(self.colors)
|
||||||
self.nfcolorboxes.append(w)
|
self.nfcolorboxes.append(w)
|
||||||
l.addWidget(w, i+1, 4, 1, 1)
|
l.addWidget(w, i, 6, 1, 1)
|
||||||
|
|
||||||
if txt:
|
if txt:
|
||||||
lines = txt.split('\n')[3:]
|
lines = txt.split('\n')[3:]
|
||||||
@ -222,25 +268,31 @@ class TagWizard(QDialog):
|
|||||||
nc = ''
|
nc = ''
|
||||||
re = False
|
re = False
|
||||||
f = 'tags'
|
f = 'tags'
|
||||||
|
a = False
|
||||||
|
n = False
|
||||||
else:
|
else:
|
||||||
t,c,f,nc,re = vals
|
t,c,f,nc,re,a,n = vals
|
||||||
try:
|
try:
|
||||||
self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c))
|
self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f))
|
||||||
self.nfcolorboxes[i].setCurrentIndex(self.nfcolorboxes[i].findText(nc))
|
self.colorboxes[i].setCurrentIndex(
|
||||||
|
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.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f))
|
self.andboxes[i].setChecked(a == '2')
|
||||||
|
self.notboxes[i].setChecked(n == '2')
|
||||||
|
i += 1
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
i += 1
|
|
||||||
|
|
||||||
w = QLabel(_('Preview'))
|
w = QLabel(_('Preview'))
|
||||||
l.addWidget(w, 99, 0, 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, 1, 1, 1)
|
|
||||||
w = QPushButton(_('Test'))
|
|
||||||
l.addWidget(w, 99, 3, 1, 1)
|
l.addWidget(w, 99, 3, 1, 1)
|
||||||
|
w = QPushButton(_('Test'))
|
||||||
|
l.addWidget(w, 99, 5, 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)
|
||||||
@ -272,8 +324,13 @@ 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 = []
|
||||||
for tb, cb, fb, nfcb, reb in zip(self.tagboxes, self.colorboxes,
|
was_and = False
|
||||||
self.colboxes, self.nfcolorboxes, self.reboxes):
|
had_line = False
|
||||||
|
|
||||||
|
line = 0
|
||||||
|
for tb, cb, fb, nfcb, reb, ab, nb in zip(
|
||||||
|
self.tagboxes, self.colorboxes, self.colboxes,
|
||||||
|
self.nfcolorboxes, self.reboxes, self.andboxes, self.notboxes):
|
||||||
f = unicode(fb.currentText())
|
f = unicode(fb.currentText())
|
||||||
if not f:
|
if not f:
|
||||||
continue
|
continue
|
||||||
@ -281,6 +338,17 @@ class TagWizard(QDialog):
|
|||||||
c = unicode(cb.currentText()).strip()
|
c = unicode(cb.currentText()).strip()
|
||||||
nfc = unicode(nfcb.currentText()).strip()
|
nfc = unicode(nfcb.currentText()).strip()
|
||||||
re = reb.checkState()
|
re = reb.checkState()
|
||||||
|
a = ab.checkState()
|
||||||
|
n = nb.checkState()
|
||||||
|
line += 1
|
||||||
|
|
||||||
|
if n == 2:
|
||||||
|
tval = ''
|
||||||
|
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(',') if t.strip()]
|
||||||
if re == 2:
|
if re == 2:
|
||||||
@ -289,9 +357,15 @@ class TagWizard(QDialog):
|
|||||||
tags = ','.join(tags)
|
tags = ','.join(tags)
|
||||||
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)):
|
||||||
|
error_dialog(self, _('Invalid line'),
|
||||||
|
_('Line number {0} is not valid').format(line),
|
||||||
|
show=True, show_copy_button=False)
|
||||||
|
return False
|
||||||
|
|
||||||
if not tags or not (c or nfc):
|
|
||||||
continue
|
|
||||||
if c not in self.colors:
|
if c not in self.colors:
|
||||||
error_dialog(self, _('Invalid color'),
|
error_dialog(self, _('Invalid color'),
|
||||||
_('The color {0} is not valid').format(c),
|
_('The color {0} is not valid').format(c),
|
||||||
@ -302,26 +376,42 @@ class TagWizard(QDialog):
|
|||||||
_('The color {0} is not valid').format(nfc),
|
_('The color {0} is not valid').format(nfc),
|
||||||
show=True, show_copy_button=False)
|
show=True, show_copy_button=False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if not was_and:
|
||||||
|
if had_line:
|
||||||
|
lines[-1] += ','
|
||||||
|
had_line = True
|
||||||
|
lines.append(" test(and(")
|
||||||
|
else:
|
||||||
|
lines[-1] += ','
|
||||||
|
|
||||||
if re == 2:
|
if re == 2:
|
||||||
if m:
|
if m:
|
||||||
lines.append(" in_list(field('{3}'), ',', '^{0}$', '{1}', '{2}')".\
|
lines.append(" in_list(field('{1}'), ',', '^{0}$', '{2}', '{3}')".\
|
||||||
format(tags, c, nfc, f))
|
format(tags, f, tval, fval))
|
||||||
else:
|
else:
|
||||||
lines.append(" contains(field('{3}'), '{0}', '{1}', '{2}')".\
|
lines.append(" contains(field('{1}'), '{0}', '{2}', '{3}')".\
|
||||||
format(tags, c, nfc, f))
|
format(tags, f, tval, fval))
|
||||||
else:
|
else:
|
||||||
if m:
|
if m:
|
||||||
lines.append(" str_in_list(field('{3}'), ',', '{0}', '{1}', '{2}')".\
|
lines.append(" str_in_list(field('{1}'), ',', '{0}', '{2}', '{3}')".\
|
||||||
format(tags, c, nfc, f))
|
format(tags, f, tval, fval))
|
||||||
else:
|
else:
|
||||||
lines.append(" strcmp(field('{3}'), '{0}', '{2}', '{1}', '{2}')".\
|
lines.append(" strcmp(field('{1}'), '{0}', '{3}', '{2}', '{3}')".\
|
||||||
format(tags, c, nfc, f))
|
format(tags, f, tval, fval))
|
||||||
res += ',\n'.join(lines)
|
if a == 2:
|
||||||
|
was_and = True
|
||||||
|
else:
|
||||||
|
was_and = False
|
||||||
|
lines.append(" ), '{0}', '{1}')".format(c, nfc))
|
||||||
|
|
||||||
|
res += '\n'.join(lines)
|
||||||
res += ')\n'
|
res += ')\n'
|
||||||
self.template = res
|
self.template = res
|
||||||
res = ''
|
res = ''
|
||||||
for tb, cb, fb, nfcb, reb in zip(self.tagboxes, self.colorboxes,
|
for tb, cb, fb, nfcb, reb, ab, nb in zip(
|
||||||
self.colboxes, self.nfcolorboxes, self.reboxes):
|
self.tagboxes, self.colorboxes, self.colboxes,
|
||||||
|
self.nfcolorboxes, self.reboxes, self.andboxes, self.notboxes):
|
||||||
t = unicode(tb.text()).strip()
|
t = unicode(tb.text()).strip()
|
||||||
if t.endswith(','):
|
if t.endswith(','):
|
||||||
t = t[:-1]
|
t = t[:-1]
|
||||||
@ -329,11 +419,24 @@ class TagWizard(QDialog):
|
|||||||
f = unicode(fb.currentText())
|
f = unicode(fb.currentText())
|
||||||
nfc = unicode(nfcb.currentText()).strip()
|
nfc = unicode(nfcb.currentText()).strip()
|
||||||
re = unicode(reb.checkState())
|
re = unicode(reb.checkState())
|
||||||
if f and t and c:
|
a = unicode(ab.checkState())
|
||||||
res += '#' + t + ':|:' + c + ':|:' + f +':|:' + nfc + ':|:' + re + '\n'
|
n = unicode(nb.checkState())
|
||||||
|
if f and t and (a == '2' or c):
|
||||||
|
res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + \
|
||||||
|
nfc + ':|:' + re + ':|:' + a + ':|:' + n + '\n'
|
||||||
self.template += res
|
self.template += res
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def and_box_changed(self, state, line=None):
|
||||||
|
if state == 2:
|
||||||
|
self.colorboxes[line].setCurrentIndex(0)
|
||||||
|
self.colorboxes[line].setEnabled(False)
|
||||||
|
self.nfcolorboxes[line].setCurrentIndex(0)
|
||||||
|
self.nfcolorboxes[line].setEnabled(False)
|
||||||
|
else:
|
||||||
|
self.colorboxes[line].setEnabled(True)
|
||||||
|
self.nfcolorboxes[line].setEnabled(True)
|
||||||
|
|
||||||
def accepted(self):
|
def accepted(self):
|
||||||
if self.generate_program():
|
if self.generate_program():
|
||||||
self.accept()
|
self.accept()
|
||||||
|
@ -5,12 +5,15 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog,
|
from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog,
|
||||||
QAbstractListModel, Qt, QColor, QIcon)
|
QAbstractListModel, Qt, QColor, QIcon, QToolButton, QComboBox)
|
||||||
|
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList
|
||||||
from calibre.gui2.preferences.look_feel_ui import Ui_Form
|
from calibre.gui2.preferences.look_feel_ui import Ui_Form
|
||||||
from calibre.gui2 import config, gprefs, qt_app
|
from calibre.gui2 import config, gprefs, qt_app
|
||||||
|
from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor
|
||||||
from calibre.utils.localization import (available_translations,
|
from calibre.utils.localization import (available_translations,
|
||||||
get_language, get_lang)
|
get_language, get_lang)
|
||||||
from calibre.utils.config import prefs
|
from calibre.utils.config import prefs
|
||||||
@ -170,10 +173,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
_('If you want to color a field based on contents of columns, '
|
_('If you want to color a field based on contents of columns, '
|
||||||
'then click the button next to an empty line to open the wizard. '
|
'then click the button next to an empty line to open the wizard. '
|
||||||
'It will build a template for you. You can later edit that '
|
'It will build a template for you. You can later edit that '
|
||||||
'template with the same wizard.') +
|
'template with the same wizard. This is by far the easiest '
|
||||||
|
'way to specify a template.') +
|
||||||
'</p><p>' +
|
'</p><p>' +
|
||||||
_('The template must evaluate to one of the color names shown '
|
_('If you manually construct a template, then the template must '
|
||||||
'below. You can use any legal template expression. '
|
'evaluate to a valid color name shown in the color names box.'
|
||||||
|
'You can use any legal template expression. '
|
||||||
'For example, you can set the title to always display in '
|
'For example, you can set the title to always display in '
|
||||||
'green using the template "green" (without the quotes). '
|
'green using the template "green" (without the quotes). '
|
||||||
'To show the title in the color named in the custom column '
|
'To show the title in the color named in the custom column '
|
||||||
@ -199,6 +204,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
'of values", it is often easier to specify the '
|
'of values", it is often easier to specify the '
|
||||||
'colors in the column definition dialog. There you can '
|
'colors in the column definition dialog. There you can '
|
||||||
'provide a color for each value without using a template.')+ '</p>')
|
'provide a color for each value without using a template.')+ '</p>')
|
||||||
|
self.color_help_scrollArea.setVisible(False)
|
||||||
|
self.color_help_button.clicked.connect(self.change_help_text)
|
||||||
|
self.colors_scrollArea.setVisible(False)
|
||||||
|
self.colors_label.setVisible(False)
|
||||||
|
self.colors_button.clicked.connect(self.change_colors_text)
|
||||||
|
|
||||||
choices = db.field_metadata.displayable_field_keys()
|
choices = db.field_metadata.displayable_field_keys()
|
||||||
choices.sort(key=sort_key)
|
choices.sort(key=sort_key)
|
||||||
choices.insert(0, '')
|
choices.insert(0, '')
|
||||||
@ -211,22 +222,58 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
l = self.column_color_layout
|
||||||
for i in range(1, self.column_color_count):
|
for i in range(1, self.column_color_count):
|
||||||
|
ccn = QComboBox(parent=self)
|
||||||
|
setattr(self, 'opt_column_color_name_'+str(i), ccn)
|
||||||
|
l.addWidget(ccn, i, 0, 1, 1)
|
||||||
|
|
||||||
|
wtb = QToolButton(parent=self)
|
||||||
|
setattr(self, 'opt_column_color_wizard_'+str(i), wtb)
|
||||||
|
wtb.setIcon(QIcon(I('wizard.png')))
|
||||||
|
l.addWidget(wtb, i, 1, 1, 1)
|
||||||
|
|
||||||
|
ttb = QToolButton(parent=self)
|
||||||
|
setattr(self, 'opt_column_color_tpledit_'+str(i), ttb)
|
||||||
|
ttb.setIcon(QIcon(I('edit_input.png')))
|
||||||
|
l.addWidget(ttb, i, 2, 1, 1)
|
||||||
|
|
||||||
|
tpl = TemplateLineEditor(parent=self)
|
||||||
|
setattr(self, 'opt_column_color_template_'+str(i), tpl)
|
||||||
|
tpl.textChanged.connect(partial(self.tpl_edit_text_changed, ctrl=i))
|
||||||
|
tpl.set_db(db)
|
||||||
|
tpl.set_mi(mi)
|
||||||
|
l.addWidget(tpl, i, 3, 1, 1)
|
||||||
|
|
||||||
|
wtb.clicked.connect(tpl.tag_wizard)
|
||||||
|
ttb.clicked.connect(tpl.open_editor)
|
||||||
|
|
||||||
r('column_color_name_'+str(i), db.prefs, choices=choices)
|
r('column_color_name_'+str(i), db.prefs, choices=choices)
|
||||||
r('column_color_template_'+str(i), db.prefs)
|
r('column_color_template_'+str(i), db.prefs)
|
||||||
txt = db.prefs.get('column_color_template_'+str(i), None)
|
txt = db.prefs.get('column_color_template_'+str(i), None)
|
||||||
tpl = getattr(self, 'opt_column_color_template_'+str(i))
|
|
||||||
tpl.set_db(db)
|
wtb.setEnabled(tpl.enable_wizard_button(txt))
|
||||||
tpl.set_mi(mi)
|
ttb.setEnabled(not tpl.enable_wizard_button(txt) or not txt)
|
||||||
toolbutton = getattr(self, 'opt_column_color_wizard_'+str(i))
|
|
||||||
if tpl.show_wizard_button(txt):
|
|
||||||
toolbutton.clicked.connect(tpl.tag_wizard)
|
|
||||||
else:
|
|
||||||
toolbutton.clicked.connect(tpl.open_editor)
|
|
||||||
toolbutton.setIcon(QIcon(I('edit_input.png')))
|
|
||||||
all_colors = [unicode(s) for s in list(QColor.colorNames())]
|
all_colors = [unicode(s) for s in list(QColor.colorNames())]
|
||||||
self.colors_box.setText(', '.join(all_colors))
|
self.colors_box.setText(', '.join(all_colors))
|
||||||
|
|
||||||
|
def change_help_text(self):
|
||||||
|
self.color_help_scrollArea.setVisible(not self.color_help_scrollArea.isVisible())
|
||||||
|
|
||||||
|
def change_colors_text(self):
|
||||||
|
self.colors_scrollArea.setVisible(not self.colors_scrollArea.isVisible())
|
||||||
|
self.colors_label.setVisible(not self.colors_label.isVisible())
|
||||||
|
|
||||||
|
def tpl_edit_text_changed(self, ign, ctrl=None):
|
||||||
|
tpl = getattr(self, 'opt_column_color_template_'+str(ctrl))
|
||||||
|
txt = unicode(tpl.text())
|
||||||
|
wtb = getattr(self, 'opt_column_color_wizard_'+str(ctrl))
|
||||||
|
ttb = getattr(self, 'opt_column_color_tpledit_'+str(ctrl))
|
||||||
|
wtb.setEnabled(tpl.enable_wizard_button(txt))
|
||||||
|
ttb.setEnabled(not tpl.enable_wizard_button(txt) or not txt)
|
||||||
|
tpl.setFocus()
|
||||||
|
|
||||||
def initialize(self):
|
def initialize(self):
|
||||||
ConfigWidgetBase.initialize(self)
|
ConfigWidgetBase.initialize(self)
|
||||||
font = gprefs['font']
|
font = gprefs['font']
|
||||||
|
@ -416,114 +416,95 @@ then the tags will be displayed each on their own line.</string>
|
|||||||
<string>Column Coloring</string>
|
<string>Column Coloring</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QGridLayout" name="column_color_layout">
|
<layout class="QGridLayout" name="column_color_layout">
|
||||||
<item row="1" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Column to color</string>
|
<string>Column to color</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="0" column="3">
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QHBoxLayout">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>Color selection template</string>
|
<widget class="QLabel" name="label">
|
||||||
</property>
|
<property name="text">
|
||||||
</widget>
|
<string>Color selection template</string>
|
||||||
</item>
|
</property>
|
||||||
<item row="2" column="0">
|
<property name="sizePolicy">
|
||||||
<widget class="QComboBox" name="opt_column_color_name_1"/>
|
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||||
</item>
|
<horstretch>10</horstretch>
|
||||||
<item row="2" column="1">
|
<verstretch>0</verstretch>
|
||||||
<widget class="TemplateLineEditor" name="opt_column_color_template_1"/>
|
</sizepolicy>
|
||||||
</item>
|
</property>
|
||||||
<item row="2" column="2">
|
</widget>
|
||||||
<widget class="QToolButton" name="opt_column_color_wizard_1">
|
</item>
|
||||||
<property name="icon">
|
<item>
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
<widget class="QLabel" name="label">
|
||||||
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
|
<property name="text">
|
||||||
</property>
|
<string>The template wizard is easiest to use</string>
|
||||||
<property name="toolTip">
|
</property>
|
||||||
<string>Open the tags wizard.</string>
|
</widget>
|
||||||
</property>
|
</item>
|
||||||
</widget>
|
<item>
|
||||||
</item>
|
<widget class="QPushButton" name="color_help_button">
|
||||||
<item row="3" column="0">
|
<property name="text">
|
||||||
<widget class="QComboBox" name="opt_column_color_name_2"/>
|
<string>Show/hide help text</string>
|
||||||
</item>
|
</property>
|
||||||
<item row="3" column="1">
|
</widget>
|
||||||
<widget class="TemplateLineEditor" name="opt_column_color_template_2"/>
|
</item>
|
||||||
</item>
|
<item>
|
||||||
<item row="3" column="2">
|
<widget class="QPushButton" name="colors_button">
|
||||||
<widget class="QToolButton" name="opt_column_color_wizard_2">
|
<property name="text">
|
||||||
<property name="icon">
|
<string>Show/hide colors</string>
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
</property>
|
||||||
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
|
</widget>
|
||||||
</property>
|
</item>
|
||||||
<property name="toolTip">
|
</layout>
|
||||||
<string>Open the tags wizard.</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QComboBox" name="opt_column_color_name_3"/>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="TemplateLineEditor" name="opt_column_color_template_3"/>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="2">
|
|
||||||
<widget class="QToolButton" name="opt_column_color_wizard_3">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
|
||||||
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Open the tags wizard.</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0">
|
|
||||||
<widget class="QComboBox" name="opt_column_color_name_4"/>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="1">
|
|
||||||
<widget class="TemplateLineEditor" name="opt_column_color_template_4"/>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="2">
|
|
||||||
<widget class="QToolButton" name="opt_column_color_wizard_4">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
|
||||||
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Open the tags wizard.</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0">
|
|
||||||
<widget class="QComboBox" name="opt_column_color_name_5"/>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="1">
|
|
||||||
<widget class="TemplateLineEditor" name="opt_column_color_template_5"/>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="2">
|
|
||||||
<widget class="QToolButton" name="opt_column_color_wizard_5">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="../../../../resources/images.qrc">
|
|
||||||
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="toolTip">
|
|
||||||
<string>Open the tags wizard.</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="20" column="0">
|
<item row="20" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="colors_label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Color names</string>
|
<string>Color names</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0" colspan="3">
|
<item row="21" column="0" colspan="8">
|
||||||
<widget class="QScrollArea" name="scrollArea">
|
<widget class="QScrollArea" name="colors_scrollArea">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>300</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="scrollAreaWidgetContents_2">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>687</width>
|
||||||
|
<height>61</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="colors_box">
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="30" column="0" colspan="8">
|
||||||
|
<widget class="QScrollArea" name="color_help_scrollArea">
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>0</width>
|
<width>0</width>
|
||||||
@ -534,7 +515,7 @@ then the tags will be displayed each on their own line.</string>
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment">
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
@ -560,37 +541,24 @@ then the tags will be displayed each on their own line.</string>
|
|||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="21" column="0" colspan="3">
|
<item row="40" column="0">
|
||||||
<widget class="QScrollArea" name="scrollArea_2">
|
<spacer>
|
||||||
<property name="maximumSize">
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy vsizetype="Expanding" hsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>10</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>16777215</width>
|
<width>0</width>
|
||||||
<height>120</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="widgetResizable">
|
</spacer>
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<widget class="QWidget" name="scrollAreaWidgetContents_2">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>687</width>
|
|
||||||
<height>61</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="colors_box">
|
|
||||||
<property name="wordWrap">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user