diff --git a/src/calibre/gui2/tag_mapper.py b/src/calibre/gui2/tag_mapper.py index ea4fa8f35e..7be534e6d3 100644 --- a/src/calibre/gui2/tag_mapper.py +++ b/src/calibre/gui2/tag_mapper.py @@ -39,13 +39,16 @@ class RuleEdit(QWidget): ('not_matches', _('does not match pattern')) )) + MSG = _('Create the rule below, the rule can be used to remove or replace tags') + SUBJECT = _('the tag, if it') + VALUE_ERROR = _('You must provide a value for the tag to match') + def __init__(self, parent=None): QWidget.__init__(self, parent) self.l = l = QVBoxLayout(self) self.h = h = QHBoxLayout() - self.la = la = QLabel(_( - 'Create the rule below, the rule can be used to remove or replace tags')) + self.la = la = QLabel(self.MSG) la.setWordWrap(True) l.addWidget(la) l.addLayout(h) @@ -54,7 +57,7 @@ class RuleEdit(QWidget): for action, text in self.ACTION_MAP.iteritems(): a.addItem(text, action) a.currentIndexChanged.connect(self.update_state) - self.la1 = la = QLabel('\xa0' + _('the tag, if it') + '\xa0') + self.la1 = la = QLabel('\xa0' + self.SUBJECT + '\xa0') h.addWidget(la) self.match_type = q = QComboBox(self) h.addWidget(q) @@ -72,6 +75,7 @@ class RuleEdit(QWidget): self.replace = r = QLineEdit(self) h.addWidget(r) l.addStretch(10) + self.la3.setVisible(False), self.replace.setVisible(False) self.update_state() def sizeHint(self): @@ -112,8 +116,7 @@ class RuleEdit(QWidget): def validate(self): rule = self.rule if not rule['query']: - error_dialog(self, _('Query required'), _( - 'You must provide a value for the tag to match'), show=True) + error_dialog(self, _('Query required'), self.VALUE_ERROR, show=True) return False if 'matches' in rule['match_type']: try: @@ -126,12 +129,16 @@ class RuleEdit(QWidget): class RuleEditDialog(Dialog): + PREFS_NAME = 'edit-tag-mapper-rule' + DIALOG_TITLE = _('Edit rule') + RuleEditClass = RuleEdit + def __init__(self, parent=None): - Dialog.__init__(self, _('Edit rule'), 'edit-tag-mapper-rule', parent=None) + Dialog.__init__(self, self.DIALOG_TITLE, self.PREFS_NAME, parent=None) def setup_ui(self): self.l = l = QVBoxLayout(self) - self.edit_widget = w = RuleEdit(self) + self.edit_widget = w = self.RuleEditClass(self) l.addWidget(w) l.addWidget(self.bb) @@ -185,14 +192,19 @@ class Delegate(QStyledItemDelegate): class Rules(QWidget): + RuleItemClass = RuleItem + RuleEditDialogClass = RuleEditDialog + + MSG = _('You can specify rules to filter/transform tags here. Click the "Add Rule" button' + ' below to get started. The rules will be processed in order for every tag until either a' + ' "remove" or a "keep" rule matches.') + def __init__(self, parent=None): QWidget.__init__(self, parent) self.l = l = QVBoxLayout(self) self.msg_label = la = QLabel( - '
' + _('You can specify rules to filter/transform tags here. Click the "Add Rule" button' - ' below to get started. The rules will be processed in order for every tag until either a' - ' "remove" or a "keep" rule matches.') + '
' + _( + '
' + self.MSG + '
' + _( 'You can change an existing rule by double clicking it') ) la.setWordWrap(True) @@ -233,20 +245,20 @@ class Rules(QWidget): return QSize(800, 600) def add_rule(self): - d = RuleEditDialog(self) + d = self.RuleEditDialogClass(self) if d.exec_() == d.Accepted: - i = RuleItem(d.edit_widget.rule, self.rule_list) + i = self.RuleItemClass(d.edit_widget.rule, self.rule_list) self.rule_list.scrollToItem(i) def edit_rule(self): i = self.rule_list.currentItem() if i is not None: - d = RuleEditDialog(self) + d = self.RuleEditDialogClass(self) d.edit_widget.rule = i.data(Qt.UserRole) if d.exec_() == d.Accepted: rule = d.edit_widget.rule i.setData(DATA_ROLE, rule) - i.setData(RENDER_ROLE, RuleItem.text_from_rule(rule, self.rule_list)) + i.setData(RENDER_ROLE, self.RuleItemClass.text_from_rule(rule, self.rule_list)) def remove_rules(self): for item in self.rule_list.selectedItems(): @@ -282,23 +294,28 @@ class Rules(QWidget): self.rule_list.clear() for rule in rules: if 'action' in rule and 'match_type' in rule and 'query' in rule: - RuleItem(rule, self.rule_list) + self.RuleItemClass(rule, self.rule_list) class Tester(Dialog): + DIALOG_TITLE = _('Test tag mapper rules') + PREFS_NAME = 'test-tag-mapper-rules' + LABEL = _('Enter a comma separated list of &tags to test:') + PLACEHOLDER = _('Enter tags and click the Test button') + EMPTY_RESULT = '