Fixes #1951673 [Clicking on field Search Mode resets previous field](https://bugs.launchpad.net/calibre/+bug/1951673)
This commit is contained in:
Kovid Goyal 2021-11-20 17:46:16 +05:30
commit 304ada7f44
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 71 additions and 69 deletions

View File

@ -886,38 +886,23 @@ as that of the first selected book.</string>
</layout>
</item>
<item row="4" column="0">
<widget class="QLabel" name="xlabel_21">
<widget class="QLabel" name="xlabel_24">
<property name="text">
<string>Search &amp;field:</string>
<string>Search &amp;mode:</string>
</property>
<property name="buddy">
<cstring>search_field</cstring>
<cstring>search_mode</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="search_field">
<property name="toolTip">
<string>The name of the field that you want to search</string>
</property>
</widget>
</item>
<item row="4" column="2">
<layout class="QHBoxLayout" name="HLayout_4">
<item>
<widget class="QLabel" name="xlabel_24">
<property name="text">
<string>Search &amp;mode:</string>
</property>
<property name="buddy">
<cstring>search_mode</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="search_mode">
<property name="toolTip">
<string>Choose whether to use basic text matching or advanced regular expression matching</string>
<string>&lt;p&gt;Choose whether to use basic text matching or advanced
regular expression matching. Changing the mode clears all the fields
in this dialog.&lt;/p&gt;</string>
</property>
</widget>
</item>
@ -937,6 +922,23 @@ as that of the first selected book.</string>
</layout>
</item>
<item row="5" column="0">
<widget class="QLabel" name="xlabel_21">
<property name="text">
<string>Search &amp;field:</string>
</property>
<property name="buddy">
<cstring>search_field</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="search_field">
<property name="toolTip">
<string>The name of the field that you want to search</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="s_r_src_ident_label">
<property name="text">
<string>&amp;Identifier type:</string>
@ -946,7 +948,7 @@ as that of the first selected book.</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QComboBox" name="s_r_src_ident">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -959,7 +961,7 @@ as that of the first selected book.</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="template_label">
<property name="text">
<string>&amp;Template:</string>
@ -969,7 +971,7 @@ as that of the first selected book.</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="HistoryLineEdit" name="s_r_template">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -982,7 +984,7 @@ as that of the first selected book.</string>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="xlabel_2">
<property name="text">
<string>&amp;Search for:</string>
@ -992,7 +994,7 @@ as that of the first selected book.</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="HistoryLineEdit" name="search_for">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -1005,7 +1007,7 @@ as that of the first selected book.</string>
</property>
</widget>
</item>
<item row="6" column="2">
<item row="7" column="2">
<widget class="QCheckBox" name="case_sensitive">
<property name="toolTip">
<string>Check this box if the search string must match exactly upper and lower case. Uncheck it if case is to be ignored</string>
@ -1018,7 +1020,7 @@ as that of the first selected book.</string>
</property>
</widget>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QLabel" name="xlabel_4">
<property name="text">
<string>&amp;Replace with:</string>
@ -1028,14 +1030,14 @@ as that of the first selected book.</string>
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="HistoryLineEdit" name="replace_with">
<property name="toolTip">
<string>The replacement text. The matched search text will be replaced with this string</string>
</property>
</widget>
</item>
<item row="7" column="2">
<item row="8" column="2">
<layout class="QHBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_41">
@ -1070,7 +1072,7 @@ field is processed. In regular expression mode, only the matched text is process
</item>
</layout>
</item>
<item row="8" column="0">
<item row="9" column="0">
<widget class="QLabel" name="destination_field_label">
<property name="text">
<string>&amp;Destination field:</string>
@ -1080,7 +1082,7 @@ field is processed. In regular expression mode, only the matched text is process
</property>
</widget>
</item>
<item row="8" column="1">
<item row="9" column="1">
<widget class="QComboBox" name="destination_field">
<property name="toolTip">
<string>The field that the text will be put into after all replacements.
@ -1088,7 +1090,7 @@ If blank, the source field is used if the field is modifiable</string>
</property>
</widget>
</item>
<item row="8" column="2">
<item row="9" column="2">
<layout class="QHBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="replace_mode_label">
@ -1137,7 +1139,7 @@ not multiple and the destination field is multiple</string>
</item>
</layout>
</item>
<item row="9" column="0">
<item row="10" column="0">
<widget class="QLabel" name="s_r_dst_ident_label">
<property name="text">
<string>Identifier type:</string>
@ -1147,7 +1149,7 @@ not multiple and the destination field is multiple</string>
</property>
</widget>
</item>
<item row="9" column="1">
<item row="10" column="1">
<widget class="QLineEdit" name="s_r_dst_ident">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -1163,7 +1165,7 @@ not multiple and the destination field is multiple</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="2">
<item row="11" column="1" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_21">
<item>
<spacer name="HSpacer_347">
@ -1249,7 +1251,7 @@ not multiple and the destination field is multiple</string>
</item>
</layout>
</item>
<item row="11" column="0" colspan="4">
<item row="12" column="0" colspan="4">
<widget class="QScrollArea" name="scrollArea11">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
@ -1434,8 +1436,8 @@ is completed. This can be slow on large libraries.</string>
<tabstop>query_field</tabstop>
<tabstop>save_button</tabstop>
<tabstop>remove_button</tabstop>
<tabstop>search_field</tabstop>
<tabstop>search_mode</tabstop>
<tabstop>search_field</tabstop>
<tabstop>s_r_src_ident</tabstop>
<tabstop>s_r_template</tabstop>
<tabstop>search_for</tabstop>

View File

@ -49,7 +49,7 @@ class TemplateHighlighter(QSyntaxHighlighter):
def __init__(self, parent=None, builtin_functions=None):
super().__init__(parent)
self.initializeFormats()
self.initialize_formats()
self.initialize_rules(builtin_functions)
self.regenerate_paren_positions()
self.highlighted_paren = False
@ -87,7 +87,7 @@ class TemplateHighlighter(QSyntaxHighlighter):
a(r'\)', "rparen")
self.Rules = tuple(r)
def initializeFormats(self):
def initialize_formats(self):
font_name = gprefs.get('gpm_template_editor_font', None)
size = gprefs['gpm_template_editor_font_size']
if font_name is None:
@ -95,37 +95,37 @@ class TemplateHighlighter(QSyntaxHighlighter):
font.setFixedPitch(True)
font.setPointSize(size)
font_name = font.family()
Config = self.Config = {}
Config["fontfamily"] = font_name
pal = QApplication.instance().palette()
config = self.Config = {}
config["fontfamily"] = font_name
app_palette = QApplication.instance().palette()
for name, color, bold, italic in (
("normal", None, False, False),
("keyword", pal.color(QPalette.ColorRole.Link).name(), True, False),
("builtin", pal.color(QPalette.ColorRole.Link).name(), False, False),
("keyword", app_palette.color(QPalette.ColorRole.Link).name(), True, False),
("builtin", app_palette.color(QPalette.ColorRole.Link).name(), False, False),
("identifier", None, False, True),
("comment", "#007F00", False, True),
("string", "#808000", False, False),
("number", "#924900", False, False),
("lparen", None, True, True),
("rparen", None, True, True)):
Config["%sfontcolor" % name] = color
Config["%sfontbold" % name] = bold
Config["%sfontitalic" % name] = italic
baseFormat = QTextCharFormat()
baseFormat.setFontFamily(Config["fontfamily"])
Config["fontsize"] = size
baseFormat.setFontPointSize(Config["fontsize"])
self.Formats = {}
config["%sfontcolor" % name] = color
config["%sfontbold" % name] = bold
config["%sfontitalic" % name] = italic
base_format = QTextCharFormat()
base_format.setFontFamily(config["fontfamily"])
config["fontsize"] = size
base_format.setFontPointSize(config["fontsize"])
self.Formats = {}
for name in ("normal", "keyword", "builtin", "comment", "identifier",
"string", "number", "lparen", "rparen"):
format_ = QTextCharFormat(baseFormat)
col = Config["%sfontcolor" % name]
if col:
format_.setForeground(QColor(col))
if Config["%sfontbold" % name]:
format_ = QTextCharFormat(base_format)
color = config["%sfontcolor" % name]
if color:
format_.setForeground(QColor(color))
if config["%sfontbold" % name]:
format_.setFontWeight(QFont.Weight.Bold)
format_.setFontItalic(Config["%sfontitalic" % name])
format_.setFontItalic(config["%sfontitalic" % name])
self.Formats[name] = format_
def find_paren(self, bn, pos):
@ -157,17 +157,17 @@ class TemplateHighlighter(QSyntaxHighlighter):
if self.generate_paren_positions:
t = str(text)
i = 0
foundQuote = False
found_quote = False
while i < len(t):
c = t[i]
if c == ':':
# Deal with the funky syntax of template program mode.
# This won't work if there are more than one template
# expression in the document.
if not foundQuote and i+1 < len(t) and t[i+1] == "'":
if not found_quote and i+1 < len(t) and t[i+1] == "'":
i += 2
elif c in ["'", '"']:
foundQuote = True
found_quote = True
i += 1
j = t[i:].find(c)
if j < 0:
@ -186,11 +186,11 @@ class TemplateHighlighter(QSyntaxHighlighter):
QApplication.restoreOverrideCursor()
def check_cursor_pos(self, chr_, block, pos_in_block):
found_pp = -1
paren_pos = -1
for i, pp in enumerate(self.paren_positions):
pp.set_highlight(False)
if pp.block == block and pp.pos == pos_in_block:
found_pp = i
paren_pos = i
if chr_ not in ('(', ')'):
if self.highlighted_paren:
@ -198,12 +198,12 @@ class TemplateHighlighter(QSyntaxHighlighter):
self.highlighted_paren = False
return
if found_pp >= 0:
if paren_pos >= 0:
stack = 0
if chr_ == '(':
list_ = self.paren_positions[found_pp+1:]
list_ = self.paren_positions[paren_pos+1:]
else:
list_ = reversed(self.paren_positions[0:found_pp])
list_ = reversed(self.paren_positions[0:paren_pos])
for pp in list_:
if pp.paren == chr_:
stack += 1
@ -211,7 +211,7 @@ class TemplateHighlighter(QSyntaxHighlighter):
stack -= 1
else:
pp.set_highlight(True)
self.paren_positions[found_pp].set_highlight(True)
self.paren_positions[paren_pos].set_highlight(True)
break
self.highlighted_paren = True
self.rehighlight()
@ -544,7 +544,7 @@ class TemplateDialog(QDialog, Ui_TemplateDialog):
self.textbox.setTabStopDistance(w)
self.source_code.setTabStopDistance(w)
self.textbox.setFont(font)
self.highlighter.initializeFormats()
self.highlighter.initialize_formats()
self.highlighter.rehighlight()
def set_up_font_boxes(self):