From 2198787a15f4840651d35a9ec9608dfb33c6dc57 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 5 Sep 2022 08:26:30 +0530 Subject: [PATCH] Tag mapper: When specifying the replacement tag allow completion from the tags in the currently open library --- src/calibre/gui2/complete2.py | 2 +- src/calibre/gui2/tag_mapper.py | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/complete2.py b/src/calibre/gui2/complete2.py index c16557707f..b0026a0c88 100644 --- a/src/calibre/gui2/complete2.py +++ b/src/calibre/gui2/complete2.py @@ -513,7 +513,7 @@ class EditWithComplete(EnComboBox): # }}} def text(self): - return str(self.lineEdit().text()) + return self.lineEdit().text() def selectAll(self): self.lineEdit().selectAll() diff --git a/src/calibre/gui2/tag_mapper.py b/src/calibre/gui2/tag_mapper.py index d3b1530bec..c14c84d5c7 100644 --- a/src/calibre/gui2/tag_mapper.py +++ b/src/calibre/gui2/tag_mapper.py @@ -2,17 +2,18 @@ # License: GPLv3 Copyright: 2015, Kovid Goyal -from collections import OrderedDict import textwrap - +from collections import OrderedDict from qt.core import ( - QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLabel, QListWidget, QIcon, QDialog, - QSize, QComboBox, QLineEdit, QListWidgetItem, QStyledItemDelegate, QAbstractItemView, - QStaticText, Qt, QStyle, QToolButton, QInputDialog, QMenu, pyqtSignal, QPalette, QItemSelectionModel, QDialogButtonBox + QAbstractItemView, QComboBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon, + QInputDialog, QItemSelectionModel, QLabel, QLineEdit, QListWidget, + QListWidgetItem, QMenu, QPalette, QPushButton, QSize, QStaticText, QStyle, + QStyledItemDelegate, Qt, QToolButton, QVBoxLayout, QWidget, pyqtSignal ) -from calibre.ebooks.metadata.tag_mapper import map_tags, compile_pat -from calibre.gui2 import error_dialog, Application, question_dialog +from calibre.ebooks.metadata.tag_mapper import compile_pat, map_tags +from calibre.gui2 import Application, error_dialog, question_dialog +from calibre.gui2.complete2 import EditWithComplete from calibre.gui2.ui import get_gui from calibre.gui2.widgets2 import Dialog from calibre.utils.config import JSONConfig @@ -37,6 +38,16 @@ class QueryEdit(QLineEdit): menu.exec(ev.globalPos()) +class SingleTagEdit(EditWithComplete): + + def __init__(self, parent): + super().__init__(parent) + self.set_separator(None) + gui = get_gui() + if gui: + self.update_items_cache(gui.current_db.new_api.all_field_names('tags')) + + class RuleEdit(QWidget): ACTION_MAP = OrderedDict(( @@ -106,7 +117,7 @@ class RuleEdit(QWidget): l.addLayout(h) self.la3 = la = QLabel(self.REPLACE_TEXT + '\xa0') h.addWidget(la) - self.replace = r = QLineEdit(self) + self.replace = r = SingleTagEdit(self) h.addWidget(r) self.regex_help = la = QLabel('

' + self.REGEXP_HELP_TEXT % localize_user_manual_link( 'https://manual.calibre-ebook.com/regexp.html'))