diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 2a451e5eda..11ae30620a 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -589,7 +589,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ def do_insert_hr(self, *args): with self.editing_cursor() as c: - c.movePosition(QTextCursor.MoveOperation.EndOfBlock, c.MoveAnchor) + c.movePosition(QTextCursor.MoveOperation.EndOfBlock, QTextCursor.MoveMode.MoveAnchor) c.insertHtml('
') def do_insert_link(self, *args): @@ -617,7 +617,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ start, end = min(pos, anchor), max(pos, anchor) for i in range(start, end): cur = self.textCursor() - cur.setPosition(i), cur.setPosition(i + 1, c.KeepAnchor) + cur.setPosition(i), cur.setPosition(i + 1, QTextCursor.MoveMode.KeepAnchor) cur.mergeCharFormat(fmt) c.setPosition(c.position()) c.setCharFormat(oldfmt) diff --git a/src/calibre/gui2/tweak_book/completion/popup.py b/src/calibre/gui2/tweak_book/completion/popup.py index e09ef0b08d..047f3a9ad7 100644 --- a/src/calibre/gui2/tweak_book/completion/popup.py +++ b/src/calibre/gui2/tweak_book/completion/popup.py @@ -9,7 +9,7 @@ import textwrap from math import ceil from PyQt5.Qt import ( - QWidget, Qt, QStaticText, QTextOption, QSize, QPainter, QTimer, QPalette, QEvent) + QWidget, Qt, QStaticText, QTextOption, QSize, QPainter, QTimer, QPalette, QEvent, QTextCursor) from calibre import prints, prepare_string_for_xml from calibre.gui2 import error_dialog @@ -259,7 +259,7 @@ class CompletionPopup(ChoosePopupWidget): c.insertText(text) chars = string_length(text) c.setPosition(c.position() - chars) - c.setPosition(c.position() + chars, c.KeepAnchor) + c.setPosition(c.position() + chars, QTextCursor.MoveMode.KeepAnchor) def abort(self): ChoosePopupWidget.abort(self) @@ -268,7 +268,7 @@ class CompletionPopup(ChoosePopupWidget): def mark_completion(self, editor, query): self.current_completion = c = editor.textCursor() chars = string_length(query or '') - c.setPosition(c.position() - chars), c.setPosition(c.position() + chars, c.KeepAnchor) + c.setPosition(c.position() - chars), c.setPosition(c.position() + chars, QTextCursor.MoveMode.KeepAnchor) self.hide() def handle_result(self, result): diff --git a/src/calibre/gui2/tweak_book/diff/highlight.py b/src/calibre/gui2/tweak_book/diff/highlight.py index c533a3869e..f569094106 100644 --- a/src/calibre/gui2/tweak_book/diff/highlight.py +++ b/src/calibre/gui2/tweak_book/diff/highlight.py @@ -46,7 +46,7 @@ class QtHighlighter(QTextDocument): afs = () for af in afs: start = dest_block.position() + af.start - c.setPosition(start), c.setPosition(start + af.length, c.KeepAnchor) + c.setPosition(start), c.setPosition(start + af.length, QTextCursor.MoveMode.KeepAnchor) c.setCharFormat(af.format) cursor.insertBlock() cursor.setCharFormat(NULL_FMT) diff --git a/src/calibre/gui2/tweak_book/diff/view.py b/src/calibre/gui2/tweak_book/diff/view.py index b8ab1b9f14..206f8e2960 100644 --- a/src/calibre/gui2/tweak_book/diff/view.py +++ b/src/calibre/gui2/tweak_book/diff/view.py @@ -240,11 +240,11 @@ class TextBrowser(PlainTextEdit): # {{{ if num in headers: self.search_header_pos = start + length else: - c.setPosition(c.position() + length, c.KeepAnchor) + c.setPosition(c.position() + length, QTextCursor.MoveMode.KeepAnchor) self.search_header_pos = 0 if reverse: pos, anchor = c.position(), c.anchor() - c.setPosition(pos), c.setPosition(anchor, c.KeepAnchor) + c.setPosition(pos), c.setPosition(anchor, QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(c) self.centerCursor() self.scrolled.emit() @@ -643,7 +643,7 @@ class DiffSplit(QSplitter): # {{{ for _ in range(delta): c.insertBlock() else: - c.movePosition(QTextCursor.MoveOperation.NextBlock, c.KeepAnchor, -delta) + c.movePosition(QTextCursor.MoveOperation.NextBlock, QTextCursor.MoveMode.KeepAnchor, -delta) c.removeSelectedText() c.endEditBlock() v.images[top] = (img, w, lines) diff --git a/src/calibre/gui2/tweak_book/editor/smarts/css.py b/src/calibre/gui2/tweak_book/editor/smarts/css.py index cbaf93d3e7..bf2ba3df71 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/css.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/css.py @@ -77,7 +77,7 @@ class Smarts(NullSmarts): def get_completion_data(self, editor, ev=None): c = editor.textCursor() - c.movePosition(QTextCursor.MoveOperation.StartOfLine, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.StartOfLine, QTextCursor.MoveMode.KeepAnchor) text = c.selectedText() m = self.complete_attr_pat.search(text) if m is None: diff --git a/src/calibre/gui2/tweak_book/editor/smarts/html.py b/src/calibre/gui2/tweak_book/editor/smarts/html.py index a35e09c577..6ca371b4cd 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/html.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/html.py @@ -213,7 +213,7 @@ def find_closing_tag(tag, max_tags=sys.maxsize): def select_tag(cursor, tag): cursor.setPosition(tag.start_block.position() + tag.start_offset) - cursor.setPosition(tag.end_block.position() + tag.end_offset + 1, cursor.KeepAnchor) + cursor.setPosition(tag.end_block.position() + tag.end_offset + 1, QTextCursor.MoveMode.KeepAnchor) return unicode_type(cursor.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0') @@ -293,7 +293,7 @@ def set_style_property(tag, property_name, value, editor): return error_dialog(editor, _('Invalid markup'), _( 'The current block tag has an existing unclosed style attribute. Run the Fix HTML' ' tool first.'), show=True) - c.setPosition(end_block.position() + end_offset, c.KeepAnchor) + c.setPosition(end_block.position() + end_offset, QTextCursor.MoveMode.KeepAnchor) d = parseStyle(editor.selected_text_from_cursor(c)[1:-1]) d.setProperty(property_name, value) c.insertText('"%s"' % css(d)) @@ -321,14 +321,14 @@ class Smarts(NullSmarts): def add_tag(tag): a = QTextEdit.ExtraSelection() a.cursor, a.format = editor.textCursor(), editor.match_paren_format - a.cursor.setPosition(tag.start_block.position()), a.cursor.movePosition(a.QTextCursor.MoveOperation.EndOfBlock, a.cursor.KeepAnchor) + a.cursor.setPosition(tag.start_block.position()), a.cursor.movePosition(QTextCursor.MoveOperation.EndOfBlock, QTextCursor.MoveMode.KeepAnchor) text = unicode_type(a.cursor.selectedText()) start_pos = utf16_length(text[:tag.start_offset]) - a.cursor.setPosition(tag.end_block.position()), a.cursor.movePosition(a.QTextCursor.MoveOperation.EndOfBlock, a.cursor.KeepAnchor) + a.cursor.setPosition(tag.end_block.position()), a.cursor.movePosition(QTextCursor.MoveOperation.EndOfBlock, QTextCursor.MoveMode.KeepAnchor) text = unicode_type(a.cursor.selectedText()) end_pos = utf16_length(text[:tag.end_offset + 1]) a.cursor.setPosition(tag.start_block.position() + start_pos) - a.cursor.setPosition(tag.end_block.position() + end_pos, a.cursor.KeepAnchor) + a.cursor.setPosition(tag.end_block.position() + end_pos, QTextCursor.MoveMode.KeepAnchor) ans.append(a) c = editor.textCursor() @@ -360,7 +360,7 @@ class Smarts(NullSmarts): return False c = editor.textCursor() c.setPosition(start.start_block.position() + start.end_offset + 1) - c.setPosition(end.start_block.position() + end.start_offset, c.KeepAnchor) + c.setPosition(end.start_block.position() + end.start_offset, QTextCursor.MoveMode.KeepAnchor) editor.setTextCursor(c) return True @@ -373,7 +373,7 @@ class Smarts(NullSmarts): def erase_tag(tag): c.setPosition(tag.start_block.position() + tag.start_offset) - c.setPosition(tag.end_block.position() + tag.end_offset + 1, c.KeepAnchor) + c.setPosition(tag.end_block.position() + tag.end_offset + 1, QTextCursor.MoveMode.KeepAnchor) c.removeSelectedText() if self.last_matched_closing_tag: @@ -416,7 +416,7 @@ class Smarts(NullSmarts): ensure_not_within_tag_definition(cursor, forward=False) right = cursor.position() - cursor.setPosition(left), cursor.setPosition(right, cursor.KeepAnchor) + cursor.setPosition(left), cursor.setPosition(right, QTextCursor.MoveMode.KeepAnchor) if update: editor.setTextCursor(cursor) return editor.selected_text_from_cursor(cursor) @@ -581,7 +581,7 @@ class Smarts(NullSmarts): if ctag is None: return None c.setPosition(tag.end_block.position() + tag.end_offset + 1) - c.setPosition(ctag.start_block.position() + ctag.start_offset, c.KeepAnchor) + c.setPosition(ctag.start_block.position() + ctag.start_offset, QTextCursor.MoveMode.KeepAnchor) return c def set_text_alignment(self, editor, value): @@ -683,14 +683,14 @@ class Smarts(NullSmarts): def replace_possible_entity(self, editor): c = editor.textCursor() c.insertText(';') - c.setPosition(c.position() - min(c.positionInBlock(), 10), c.KeepAnchor) + c.setPosition(c.position() - min(c.positionInBlock(), 10), QTextCursor.MoveMode.KeepAnchor) text = editor.selected_text_from_cursor(c) m = entity_pat.search(text) if m is not None: ent = m.group() repl = xml_entity_to_unicode(m) if repl != ent: - c.setPosition(c.position() + m.start(), c.KeepAnchor) + c.setPosition(c.position() + m.start(), QTextCursor.MoveMode.KeepAnchor) c.insertText(repl) editor.setTextCursor(c) @@ -728,7 +728,7 @@ class Smarts(NullSmarts): return tagname = boundary.name.lower() startpos = oblock.position() + boundary.offset - c.setPosition(c.position()), c.setPosition(startpos, c.KeepAnchor) + c.setPosition(c.position()), c.setPosition(startpos, QTextCursor.MoveMode.KeepAnchor) text = c.selectedText() m = self.complete_attr_pat.search(text) if m is None: @@ -797,7 +797,7 @@ class Smarts(NullSmarts): c.setPosition(start) for b in boundaries: if in_text: - c.setPosition(start + b.offset, c.KeepAnchor) + c.setPosition(start + b.offset, QTextCursor.MoveMode.KeepAnchor) if c.hasSelection(): append(c.selectedText(), c.anchor()) in_text = not b.is_start @@ -805,7 +805,7 @@ class Smarts(NullSmarts): if in_text: # Add remaining text in block c.setPosition(block.position() + boundaries[-1].offset + 1) - c.movePosition(QTextCursor.MoveOperation.EndOfBlock, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.EndOfBlock, QTextCursor.MoveMode.KeepAnchor) if c.hasSelection(): append(c.selectedText() + '\n', c.anchor()) block = block.next() diff --git a/src/calibre/gui2/tweak_book/editor/smarts/utils.py b/src/calibre/gui2/tweak_book/editor/smarts/utils.py index 4a136abb8c..bdea4ec7e5 100644 --- a/src/calibre/gui2/tweak_book/editor/smarts/utils.py +++ b/src/calibre/gui2/tweak_book/editor/smarts/utils.py @@ -11,7 +11,7 @@ from PyQt5.Qt import Qt, QTextCursor def get_text_around_cursor(editor, before=True): cursor = editor.textCursor() cursor.clearSelection() - cursor.movePosition((QTextCursor.MoveOperation.StartOfBlock if before else QTextCursor.MoveOperation.EndOfBlock), cursor.KeepAnchor) + cursor.movePosition((QTextCursor.MoveOperation.StartOfBlock if before else QTextCursor.MoveOperation.EndOfBlock), QTextCursor.MoveMode.KeepAnchor) text = editor.selected_text_from_cursor(cursor) return cursor, text @@ -60,7 +60,7 @@ def smart_home(editor, ev): if no_modifiers(ev, Qt.KeyboardModifier.ControlModifier) and not is_cursor_on_wrapped_line(editor): cursor, text = get_text_before_cursor(editor) cursor = editor.textCursor() - mode = cursor.KeepAnchor if test_modifiers(ev, Qt.KeyboardModifier.ShiftModifier) else cursor.MoveAnchor + mode = QTextCursor.MoveMode.KeepAnchor if test_modifiers(ev, Qt.KeyboardModifier.ShiftModifier) else QTextCursor.MoveMode.MoveAnchor cursor.movePosition(QTextCursor.MoveOperation.StartOfBlock, mode) if text.strip() and text.lstrip() != text: # Move to the start of text diff --git a/src/calibre/gui2/tweak_book/editor/snippets.py b/src/calibre/gui2/tweak_book/editor/snippets.py index 3a9105984c..f84ab8ca19 100644 --- a/src/calibre/gui2/tweak_book/editor/snippets.py +++ b/src/calibre/gui2/tweak_book/editor/snippets.py @@ -13,7 +13,7 @@ from operator import attrgetter, itemgetter from PyQt5.Qt import ( Qt, QObject, QSize, QVBoxLayout, QStackedLayout, QWidget, QLineEdit, QListView, QToolButton, QIcon, QHBoxLayout, QPushButton, QListWidget, QListWidgetItem, - QGridLayout, QPlainTextEdit, QLabel, QFrame, QDialog, QDialogButtonBox) + QGridLayout, QPlainTextEdit, QLabel, QFrame, QDialog, QDialogButtonBox, QTextCursor) from calibre.constants import ismacos from calibre.gui2 import error_dialog @@ -226,7 +226,7 @@ class EditorTabStop(object): if editor is None or self.is_deleted: return '' c = editor.textCursor() - c.setPosition(self.left), c.setPosition(self.right, c.KeepAnchor) + c.setPosition(self.left), c.setPosition(self.right, QTextCursor.MoveMode.KeepAnchor) return editor.selected_text_from_cursor(c) @text.setter @@ -236,14 +236,14 @@ class EditorTabStop(object): return c = editor.textCursor() c.joinPreviousEditBlock() if self.join_previous_edit else c.beginEditBlock() - c.setPosition(self.left), c.setPosition(self.right, c.KeepAnchor) + c.setPosition(self.left), c.setPosition(self.right, QTextCursor.MoveMode.KeepAnchor) c.insertText(text) c.endEditBlock() def set_editor_cursor(self, editor): if not self.is_deleted: c = editor.textCursor() - c.setPosition(self.left), c.setPosition(self.right, c.KeepAnchor) + c.setPosition(self.left), c.setPosition(self.right, QTextCursor.MoveMode.KeepAnchor) editor.setTextCursor(c) def contained_in(self, left, right): @@ -349,7 +349,7 @@ def expand_template(editor, trigger, template): right = c.position() left = right - string_length(trigger) text, tab_stops = parse_template(template) - c.setPosition(left), c.setPosition(right, c.KeepAnchor), c.insertText(text) + c.setPosition(left), c.setPosition(right, QTextCursor.MoveMode.KeepAnchor), c.insertText(text) editor_tab_stops = [EditorTabStop(left, ts, editor) for ts in itervalues(tab_stops)] tl = Template(editor_tab_stops) diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 5f74d04bcd..65c9a1c181 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -310,7 +310,7 @@ class TextEdit(PlainTextEdit): c.movePosition(QTextCursor.MoveOperation.Start) c.movePosition(QTextCursor.MoveOperation.NextBlock, n=lnum - 1) c.movePosition(QTextCursor.MoveOperation.StartOfLine) - c.movePosition(QTextCursor.MoveOperation.EndOfLine, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.EndOfLine, QTextCursor.MoveMode.KeepAnchor) text = unicode_type(c.selectedText()).rstrip('\0') if col is None: c.movePosition(QTextCursor.MoveOperation.StartOfLine) @@ -369,7 +369,7 @@ class TextEdit(PlainTextEdit): pos = m_start if reverse else m_end if wrap: pos = m_end if reverse else m_start - c.setPosition(pos, c.KeepAnchor) + c.setPosition(pos, QTextCursor.MoveMode.KeepAnchor) raw = unicode_type(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0') m = pat.search(raw) if m is None: @@ -391,7 +391,7 @@ class TextEdit(PlainTextEdit): c.clearSelection() c.setPosition(start) - c.setPosition(end, c.KeepAnchor) + c.setPosition(end, QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(c) # Center search result on screen self.centerCursor() @@ -425,7 +425,7 @@ class TextEdit(PlainTextEdit): start_pos = min(c.anchor(), c.position()) c.insertText(raw) end_pos = max(c.anchor(), c.position()) - c.setPosition(start_pos), c.setPosition(end_pos, c.KeepAnchor) + c.setPosition(start_pos), c.setPosition(end_pos, QTextCursor.MoveMode.KeepAnchor) self.update_extra_selections() return count @@ -439,7 +439,7 @@ class TextEdit(PlainTextEdit): ' Are you sure you want to proceed?'), 'edit-book-confirm-sort-css', parent=self, config_set=tprefs): c = self.textCursor() c.beginEditBlock() - c.movePosition(QTextCursor.MoveOperation.Start), c.movePosition(QTextCursor.MoveOperation.End, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.Start), c.movePosition(QTextCursor.MoveOperation.End, QTextCursor.MoveMode.KeepAnchor) text = unicode_type(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0') from calibre.ebooks.oeb.polish.css import sort_sheet text = css_text(sort_sheet(current_container(), text)) @@ -460,7 +460,7 @@ class TextEdit(PlainTextEdit): pos = QTextCursor.MoveOperation.Start if reverse else QTextCursor.MoveOperation.End if wrap and not complete: pos = QTextCursor.MoveOperation.End if reverse else QTextCursor.MoveOperation.Start - c.movePosition(pos, c.KeepAnchor) + c.movePosition(pos, QTextCursor.MoveMode.KeepAnchor) raw = unicode_type(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0') m = pat.search(raw) if m is None: @@ -481,7 +481,7 @@ class TextEdit(PlainTextEdit): start, end = textpos + start, textpos + end c.clearSelection() c.setPosition(start) - c.setPosition(end, c.KeepAnchor) + c.setPosition(end, QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(c) # Center search result on screen self.centerCursor() @@ -499,7 +499,7 @@ class TextEdit(PlainTextEdit): pos = QTextCursor.MoveOperation.Start if reverse else QTextCursor.MoveOperation.End if wrap and not complete: pos = QTextCursor.MoveOperation.End if reverse else QTextCursor.MoveOperation.Start - c.movePosition(pos, c.KeepAnchor) + c.movePosition(pos, QTextCursor.MoveMode.KeepAnchor) if hasattr(self.smarts, 'find_text'): self.highlighter.join() found, start, end = self.smarts.find_text(pat, c, reverse) @@ -517,7 +517,7 @@ class TextEdit(PlainTextEdit): start, end = end, start c.clearSelection() c.setPosition(start) - c.setPosition(end, c.KeepAnchor) + c.setPosition(end, QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(c) # Center search result on screen self.centerCursor() @@ -528,7 +528,7 @@ class TextEdit(PlainTextEdit): c.setPosition(c.position()) if not from_cursor: c.movePosition(QTextCursor.MoveOperation.Start) - c.movePosition(QTextCursor.MoveOperation.End, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.End, QTextCursor.MoveMode.KeepAnchor) def find_first_word(haystack): match_pos, match_word = -1, None @@ -544,7 +544,7 @@ class TextEdit(PlainTextEdit): if idx == -1: return False c.setPosition(c.anchor() + idx) - c.setPosition(c.position() + string_length(word), c.KeepAnchor) + c.setPosition(c.position() + string_length(word), QTextCursor.MoveMode.KeepAnchor) if self.smarts.verify_for_spellcheck(c, self.highlighter): self.highlighter.join() # Ensure highlighting is finished locale = self.spellcheck_locale_for_cursor(c) @@ -554,7 +554,7 @@ class TextEdit(PlainTextEdit): self.centerCursor() return True c.setPosition(c.position()) - c.movePosition(QTextCursor.MoveOperation.End, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.End, QTextCursor.MoveMode.KeepAnchor) return False @@ -568,7 +568,7 @@ class TextEdit(PlainTextEdit): if r.format.property(SPELL_PROPERTY): if not from_cursor or block.position() + r.start + r.length > c.position(): c.setPosition(block.position() + r.start) - c.setPosition(c.position() + r.length, c.KeepAnchor) + c.setPosition(c.position() + r.length, QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(c) return True block = block.next() @@ -712,7 +712,7 @@ class TextEdit(PlainTextEdit): def text_for_range(self, block, r): c = self.textCursor() c.setPosition(block.position() + r.start) - c.setPosition(c.position() + r.length, c.KeepAnchor) + c.setPosition(c.position() + r.length, QTextCursor.MoveMode.KeepAnchor) return unicode_type(c.selectedText()) def spellcheck_locale_for_cursor(self, c): @@ -828,13 +828,13 @@ class TextEdit(PlainTextEdit): left, right = self.get_range_inside_tag() c = self.textCursor() c.setPosition(left) - c.setPosition(right, c.KeepAnchor) + c.setPosition(right, QTextCursor.MoveMode.KeepAnchor) prev_text = unicode_type(c.selectedText()).rstrip('\0') c.insertText(prefix + prev_text + suffix) if prev_text: right = c.position() c.setPosition(left) - c.setPosition(right, c.KeepAnchor) + c.setPosition(right, QTextCursor.MoveMode.KeepAnchor) else: c.setPosition(c.position() - len(suffix)) self.setTextCursor(c) @@ -850,7 +850,7 @@ class TextEdit(PlainTextEdit): if self.syntax == 'html': left, right = self.get_range_inside_tag() c.setPosition(left) - c.setPosition(right, c.KeepAnchor) + c.setPosition(right, QTextCursor.MoveMode.KeepAnchor) href = prepare_string_for_xml(href, True) if fullpage: template = '''\ @@ -866,10 +866,10 @@ version="1.1" width="100%%" height="100%%" viewBox="0 0 {w} {h}" preserveAspectR c.insertText(text) if self.syntax == 'html' and not fullpage: c.setPosition(left + 10) - c.setPosition(c.position() + len(alt), c.KeepAnchor) + c.setPosition(c.position() + len(alt), QTextCursor.MoveMode.KeepAnchor) else: c.setPosition(left) - c.setPosition(left + len(text), c.KeepAnchor) + c.setPosition(left + len(text), QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(c) def insert_hyperlink(self, target, text, template=None): @@ -934,7 +934,7 @@ version="1.1" width="100%%" height="100%%" viewBox="0 0 {w} {h}" preserveAspectR if has_selection: text = unicode_type(c.selectedText()).rstrip('\0') else: - c.setPosition(c.position() - min(c.positionInBlock(), 6), c.KeepAnchor) + c.setPosition(c.position() - min(c.positionInBlock(), 6), QTextCursor.MoveMode.KeepAnchor) text = unicode_type(c.selectedText()).rstrip('\0') m = re.search(r'[a-fA-F0-9]{2,6}$', text) if m is None: @@ -947,7 +947,7 @@ version="1.1" width="100%%" height="100%%" viewBox="0 0 {w} {h}" preserveAspectR if num > 0x10ffff or num < 1: return False end_pos = max(c.anchor(), c.position()) - c.setPosition(end_pos - len(text)), c.setPosition(end_pos, c.KeepAnchor) + c.setPosition(end_pos - len(text)), c.setPosition(end_pos, QTextCursor.MoveMode.KeepAnchor) c.insertText(safe_chr(num)) return True @@ -955,7 +955,7 @@ version="1.1" width="100%%" height="100%%" viewBox="0 0 {w} {h}" preserveAspectR c = self.textCursor() c.clearSelection() c.setPosition(0) - c.movePosition(QTextCursor.MoveOperation.End, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.End, QTextCursor.MoveMode.KeepAnchor) self.setTextCursor(c) def rename_block_tag(self, new_name): diff --git a/src/calibre/gui2/tweak_book/editor/widget.py b/src/calibre/gui2/tweak_book/editor/widget.py index eb80ac890f..7a4c2c8205 100644 --- a/src/calibre/gui2/tweak_book/editor/widget.py +++ b/src/calibre/gui2/tweak_book/editor/widget.py @@ -181,7 +181,7 @@ class Editor(QMainWindow): anchor, position = val.get('cursor', (None, None)) if anchor is not None and position is not None: c = self.editor.textCursor() - c.setPosition(anchor), c.setPosition(position, c.KeepAnchor) + c.setPosition(anchor), c.setPosition(position, QTextCursor.MoveMode.KeepAnchor) self.editor.setTextCursor(c) def current_tag(self, for_position_sync=True): @@ -476,7 +476,7 @@ class Editor(QMainWindow): col = c.positionInBlock() if not c.atStart(): c.clearSelection() - c.movePosition(QTextCursor.MoveOperation.PreviousCharacter, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.PreviousCharacter, QTextCursor.MoveMode.KeepAnchor) char = unicode_type(c.selectedText()).rstrip('\0') return (c.blockNumber() + 1, col, char) diff --git a/src/calibre/gui2/tweak_book/reports.py b/src/calibre/gui2/tweak_book/reports.py index 3e40f02a3a..5f87a6c8fe 100644 --- a/src/calibre/gui2/tweak_book/reports.py +++ b/src/calibre/gui2/tweak_book/reports.py @@ -20,7 +20,7 @@ from PyQt5.Qt import ( QListWidgetItem, QLineEdit, QStackedWidget, QSplitter, QByteArray, QPixmap, QStyledItemDelegate, QModelIndex, QRect, QStyle, QPalette, QTimer, QMenu, QAbstractItemModel, QTreeView, QFont, QRadioButton, QHBoxLayout, - QFontDatabase, QComboBox, QUrl, QAbstractItemView, QDialogButtonBox) + QFontDatabase, QComboBox, QUrl, QAbstractItemView, QDialogButtonBox, QTextCursor) from calibre import human_readable, fit_image from calibre.constants import DEBUG @@ -337,7 +337,7 @@ def jump_to_location(loc): if not block.isValid(): return c = editor.textCursor() - c.setPosition(block.position(), c.MoveAnchor) + c.setPosition(block.position(), QTextCursor.MoveMode.MoveAnchor) editor.setTextCursor(c) if loc.text_on_line is not None: editor.find(regex.compile(regex.escape(loc.text_on_line))) diff --git a/src/calibre/gui2/widgets2.py b/src/calibre/gui2/widgets2.py index a52caf8dd9..a5c3fce652 100644 --- a/src/calibre/gui2/widgets2.py +++ b/src/calibre/gui2/widgets2.py @@ -559,7 +559,7 @@ def to_plain_text(self): c = self.textCursor() c.clearSelection() c.movePosition(QTextCursor.MoveOperation.Start) - c.movePosition(QTextCursor.MoveOperation.End, c.KeepAnchor) + c.movePosition(QTextCursor.MoveOperation.End, QTextCursor.MoveMode.KeepAnchor) ans = c.selectedText().replace(PARAGRAPH_SEPARATOR, '\n') # QTextCursor pads the return value of selectedText with null bytes if # non BMP characters such as 0x1f431 are present.