mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
More stupid PyQt enums
This commit is contained in:
parent
9a9fcb488a
commit
cef55aa72c
@ -589,7 +589,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{
|
||||
|
||||
def do_insert_hr(self, *args):
|
||||
with self.editing_cursor() as c:
|
||||
c.movePosition(c.EndOfBlock, c.MoveAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.EndOfBlock, c.MoveAnchor)
|
||||
c.insertHtml('<hr>')
|
||||
|
||||
def do_insert_link(self, *args):
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
from PyQt5.Qt import (
|
||||
QWidget, QVBoxLayout, QHBoxLayout, QLabel, QComboBox, QLineEdit,
|
||||
QPushButton, QSize, pyqtSignal, QMenu, QDialogButtonBox
|
||||
QPushButton, QSize, pyqtSignal, QMenu, QDialogButtonBox, QTextCursor
|
||||
)
|
||||
|
||||
from calibre.ebooks.css_transform_rules import (
|
||||
@ -211,7 +211,7 @@ class Tester(Dialog): # {{{
|
||||
t.load_text('/* %s */\n' % _('Enter CSS rules below and click the "Test" button'), 'css')
|
||||
la.setBuddy(t)
|
||||
c = t.textCursor()
|
||||
c.movePosition(c.End)
|
||||
c.movePosition(QTextCursor.MoveOperation.End)
|
||||
t.setTextCursor(c)
|
||||
self.h = h = QHBoxLayout()
|
||||
l.addLayout(h)
|
||||
|
@ -522,7 +522,7 @@ class DiffSplit(QSplitter): # {{{
|
||||
def finalize(self):
|
||||
for v in (self.left, self.right):
|
||||
c = v.textCursor()
|
||||
c.movePosition(c.Start)
|
||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
v.setTextCursor(c)
|
||||
self.update()
|
||||
|
||||
@ -536,14 +536,14 @@ class DiffSplit(QSplitter): # {{{
|
||||
self.right.headers.append((self.right.blockCount() - 1, right_name))
|
||||
for v in (self.left, self.right):
|
||||
c = v.textCursor()
|
||||
c.movePosition(c.End)
|
||||
c.movePosition(QTextCursor.MoveOperation.End)
|
||||
(c.insertBlock(), c.insertBlock(), c.insertBlock())
|
||||
|
||||
with BusyCursor():
|
||||
if is_identical:
|
||||
for v in (self.left, self.right):
|
||||
c = v.textCursor()
|
||||
c.movePosition(c.End)
|
||||
c.movePosition(QTextCursor.MoveOperation.End)
|
||||
c.insertText('[%s]\n\n' % _('The files are identical'))
|
||||
elif left_name != right_name and not left_text and not right_text:
|
||||
self.add_text_diff(_('[This file was renamed to %s]') % right_name, _('[This file was renamed from %s]') % left_name, context, None)
|
||||
@ -605,10 +605,10 @@ class DiffSplit(QSplitter): # {{{
|
||||
QApplication.processEvents(QEventLoop.ProcessEventsFlag.ExcludeUserInputEvents | QEventLoop.ProcessEventsFlag.ExcludeSocketNotifiers)
|
||||
for v, img, size in ((self.left, left_img, len(left_data)), (self.right, right_img, len(right_data))):
|
||||
c = v.textCursor()
|
||||
c.movePosition(c.End)
|
||||
c.movePosition(QTextCursor.MoveOperation.End)
|
||||
start = c.block().blockNumber()
|
||||
lines, w = self.get_lines_for_image(img, v)
|
||||
c.movePosition(c.StartOfBlock)
|
||||
c.movePosition(QTextCursor.MoveOperation.StartOfBlock)
|
||||
if size > 0:
|
||||
c.beginEditBlock()
|
||||
c.insertText(_('Size: {0} Resolution: {1}x{2}').format(human_readable(size), img.width(), img.height()))
|
||||
@ -638,12 +638,12 @@ class DiffSplit(QSplitter): # {{{
|
||||
top, bot, kind = v.changes[i]
|
||||
c = QTextCursor(v.document().findBlockByNumber(top+1))
|
||||
c.beginEditBlock()
|
||||
c.movePosition(c.StartOfBlock)
|
||||
c.movePosition(QTextCursor.MoveOperation.StartOfBlock)
|
||||
if delta > 0:
|
||||
for _ in range(delta):
|
||||
c.insertBlock()
|
||||
else:
|
||||
c.movePosition(c.NextBlock, c.KeepAnchor, -delta)
|
||||
c.movePosition(QTextCursor.MoveOperation.NextBlock, c.KeepAnchor, -delta)
|
||||
c.removeSelectedText()
|
||||
c.endEditBlock()
|
||||
v.images[top] = (img, w, lines)
|
||||
@ -678,7 +678,7 @@ class DiffSplit(QSplitter): # {{{
|
||||
if len(left_text) == len(right_text) and left_text == right_text:
|
||||
for v in (self.left, self.right):
|
||||
c = v.textCursor()
|
||||
c.movePosition(c.End)
|
||||
c.movePosition(QTextCursor.MoveOperation.End)
|
||||
c.insertText('[%s]\n\n' % _('The files are identical after beautifying'))
|
||||
return
|
||||
|
||||
@ -690,7 +690,7 @@ class DiffSplit(QSplitter): # {{{
|
||||
left_highlight, right_highlight = get_highlighter(self.left, left_text, syntax), get_highlighter(self.right, right_text, syntax)
|
||||
cl, cr = self.left_cursor, self.right_cursor = self.left.textCursor(), self.right.textCursor()
|
||||
cl.beginEditBlock(), cr.beginEditBlock()
|
||||
cl.movePosition(cl.End), cr.movePosition(cr.End)
|
||||
cl.movePosition(QTextCursor.MoveOperation.End), cr.movePosition(QTextCursor.MoveOperation.End)
|
||||
self.left_insert = partial(self.do_insert, cl, left_highlight, self.left.line_number_map)
|
||||
self.right_insert = partial(self.do_insert, cr, right_highlight, self.right.line_number_map)
|
||||
|
||||
|
@ -7,7 +7,7 @@ __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import re
|
||||
|
||||
from PyQt5.Qt import Qt
|
||||
from PyQt5.Qt import Qt, QTextCursor
|
||||
|
||||
from calibre.gui2.tweak_book import current_container
|
||||
from calibre.gui2.tweak_book.editor.smarts import NullSmarts
|
||||
@ -77,7 +77,7 @@ class Smarts(NullSmarts):
|
||||
|
||||
def get_completion_data(self, editor, ev=None):
|
||||
c = editor.textCursor()
|
||||
c.movePosition(c.StartOfLine, c.KeepAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.StartOfLine, c.KeepAnchor)
|
||||
text = c.selectedText()
|
||||
m = self.complete_attr_pat.search(text)
|
||||
if m is None:
|
||||
|
@ -321,10 +321,10 @@ 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.cursor.EndOfBlock, a.cursor.KeepAnchor)
|
||||
a.cursor.setPosition(tag.start_block.position()), a.cursor.movePosition(a.QTextCursor.MoveOperation.EndOfBlock, a.cursor.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.cursor.EndOfBlock, a.cursor.KeepAnchor)
|
||||
a.cursor.setPosition(tag.end_block.position()), a.cursor.movePosition(a.QTextCursor.MoveOperation.EndOfBlock, a.cursor.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)
|
||||
@ -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(c.EndOfBlock, c.KeepAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.EndOfBlock, c.KeepAnchor)
|
||||
if c.hasSelection():
|
||||
append(c.selectedText() + '\n', c.anchor())
|
||||
block = block.next()
|
||||
|
@ -5,13 +5,13 @@
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from PyQt5.Qt import Qt
|
||||
from PyQt5.Qt import Qt, QTextCursor
|
||||
|
||||
|
||||
def get_text_around_cursor(editor, before=True):
|
||||
cursor = editor.textCursor()
|
||||
cursor.clearSelection()
|
||||
cursor.movePosition((cursor.StartOfBlock if before else cursor.EndOfBlock), cursor.KeepAnchor)
|
||||
cursor.movePosition((QTextCursor.MoveOperation.StartOfBlock if before else QTextCursor.MoveOperation.EndOfBlock), cursor.KeepAnchor)
|
||||
text = editor.selected_text_from_cursor(cursor)
|
||||
return cursor, text
|
||||
|
||||
@ -22,9 +22,9 @@ get_text_after_cursor = lambda editor: get_text_around_cursor(editor, before=Fal
|
||||
|
||||
def is_cursor_on_wrapped_line(editor):
|
||||
cursor = editor.textCursor()
|
||||
cursor.movePosition(cursor.StartOfLine)
|
||||
cursor.movePosition(QTextCursor.MoveOperation.StartOfLine)
|
||||
sol = cursor.position()
|
||||
cursor.movePosition(cursor.StartOfBlock)
|
||||
cursor.movePosition(QTextCursor.MoveOperation.StartOfBlock)
|
||||
return sol != cursor.position()
|
||||
|
||||
|
||||
@ -61,10 +61,10 @@ def smart_home(editor, ev):
|
||||
cursor, text = get_text_before_cursor(editor)
|
||||
cursor = editor.textCursor()
|
||||
mode = cursor.KeepAnchor if test_modifiers(ev, Qt.KeyboardModifier.ShiftModifier) else cursor.MoveAnchor
|
||||
cursor.movePosition(cursor.StartOfBlock, mode)
|
||||
cursor.movePosition(QTextCursor.MoveOperation.StartOfBlock, mode)
|
||||
if text.strip() and text.lstrip() != text:
|
||||
# Move to the start of text
|
||||
cursor.movePosition(cursor.NextWord, mode)
|
||||
cursor.movePosition(QTextCursor.MoveOperation.NextWord, mode)
|
||||
editor.setTextCursor(cursor)
|
||||
return True
|
||||
return False
|
||||
|
@ -136,7 +136,7 @@ class SyntaxHighlighter(object):
|
||||
if not last_block.isValid():
|
||||
last_block = doc.lastBlock()
|
||||
end_cursor = QTextCursor(last_block)
|
||||
end_cursor.movePosition(end_cursor.EndOfBlock)
|
||||
end_cursor.movePosition(QTextCursor.MoveOperation.EndOfBlock)
|
||||
self.requests.append((start_cursor, end_cursor))
|
||||
QTimer.singleShot(0, self.do_one_block)
|
||||
|
||||
@ -158,7 +158,7 @@ class SyntaxHighlighter(object):
|
||||
except AttributeError:
|
||||
self.requests.clear()
|
||||
return
|
||||
ok = start_cursor.movePosition(start_cursor.NextBlock)
|
||||
ok = start_cursor.movePosition(QTextCursor.MoveOperation.NextBlock)
|
||||
if not ok:
|
||||
self.requests.popleft()
|
||||
return
|
||||
|
@ -6,17 +6,15 @@
|
||||
import importlib
|
||||
import os
|
||||
import re
|
||||
import regex
|
||||
import textwrap
|
||||
import unicodedata
|
||||
from polyglot.builtins import unicode_type, map, range, as_unicode
|
||||
|
||||
from PyQt5.Qt import (
|
||||
QColor, QColorDialog, QFont, QFontDatabase, QKeySequence, QPainter, QPalette,
|
||||
QPlainTextEdit, QRect, QSize, Qt, QTextEdit, QTextFormat, QTimer, QToolTip,
|
||||
QWidget, pyqtSignal
|
||||
QPlainTextEdit, QRect, QSize, Qt, QTextCursor, QTextEdit, QTextFormat, QTimer,
|
||||
QToolTip, QWidget, pyqtSignal
|
||||
)
|
||||
|
||||
import regex
|
||||
from calibre import prepare_string_for_xml
|
||||
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES, css_text
|
||||
from calibre.ebooks.oeb.polish.replace import get_recommended_folders
|
||||
@ -42,6 +40,7 @@ from calibre.utils.icu import (
|
||||
)
|
||||
from calibre.utils.img import image_to_data
|
||||
from calibre.utils.titlecase import titlecase
|
||||
from polyglot.builtins import as_unicode, map, range, unicode_type
|
||||
|
||||
|
||||
def get_highlighter(syntax):
|
||||
@ -308,22 +307,22 @@ class TextEdit(PlainTextEdit):
|
||||
lnum = max(1, min(self.blockCount(), lnum))
|
||||
c = self.textCursor()
|
||||
c.clearSelection()
|
||||
c.movePosition(c.Start)
|
||||
c.movePosition(c.NextBlock, n=lnum - 1)
|
||||
c.movePosition(c.StartOfLine)
|
||||
c.movePosition(c.EndOfLine, c.KeepAnchor)
|
||||
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)
|
||||
text = unicode_type(c.selectedText()).rstrip('\0')
|
||||
if col is None:
|
||||
c.movePosition(c.StartOfLine)
|
||||
c.movePosition(QTextCursor.MoveOperation.StartOfLine)
|
||||
lt = text.lstrip()
|
||||
if text and lt and lt != text:
|
||||
c.movePosition(c.NextWord)
|
||||
c.movePosition(QTextCursor.MoveOperation.NextWord)
|
||||
else:
|
||||
c.setPosition(c.block().position() + col)
|
||||
if c.blockNumber() + 1 > lnum:
|
||||
# We have moved past the end of the line
|
||||
c.setPosition(c.block().position())
|
||||
c.movePosition(c.EndOfBlock)
|
||||
c.movePosition(QTextCursor.MoveOperation.EndOfBlock)
|
||||
self.setTextCursor(c)
|
||||
self.ensureCursorVisible()
|
||||
|
||||
@ -440,12 +439,12 @@ 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(c.Start), c.movePosition(c.End, c.KeepAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.Start), c.movePosition(QTextCursor.MoveOperation.End, c.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))
|
||||
c.insertText(text)
|
||||
c.movePosition(c.Start)
|
||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
c.endEditBlock()
|
||||
self.setTextCursor(c)
|
||||
|
||||
@ -457,10 +456,10 @@ class TextEdit(PlainTextEdit):
|
||||
c.clearSelection()
|
||||
if complete:
|
||||
# Search the entire text
|
||||
c.movePosition(c.End if reverse else c.Start)
|
||||
pos = c.Start if reverse else c.End
|
||||
c.movePosition(QTextCursor.MoveOperation.End if reverse else QTextCursor.MoveOperation.Start)
|
||||
pos = QTextCursor.MoveOperation.Start if reverse else QTextCursor.MoveOperation.End
|
||||
if wrap and not complete:
|
||||
pos = c.End if reverse else c.Start
|
||||
pos = QTextCursor.MoveOperation.End if reverse else QTextCursor.MoveOperation.Start
|
||||
c.movePosition(pos, c.KeepAnchor)
|
||||
raw = unicode_type(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')
|
||||
m = pat.search(raw)
|
||||
@ -496,10 +495,10 @@ class TextEdit(PlainTextEdit):
|
||||
c.clearSelection()
|
||||
if complete:
|
||||
# Search the entire text
|
||||
c.movePosition(c.End if reverse else c.Start)
|
||||
pos = c.Start if reverse else c.End
|
||||
c.movePosition(QTextCursor.MoveOperation.End if reverse else QTextCursor.MoveOperation.Start)
|
||||
pos = QTextCursor.MoveOperation.Start if reverse else QTextCursor.MoveOperation.End
|
||||
if wrap and not complete:
|
||||
pos = c.End if reverse else c.Start
|
||||
pos = QTextCursor.MoveOperation.End if reverse else QTextCursor.MoveOperation.Start
|
||||
c.movePosition(pos, c.KeepAnchor)
|
||||
if hasattr(self.smarts, 'find_text'):
|
||||
self.highlighter.join()
|
||||
@ -528,8 +527,8 @@ class TextEdit(PlainTextEdit):
|
||||
c = self.textCursor()
|
||||
c.setPosition(c.position())
|
||||
if not from_cursor:
|
||||
c.movePosition(c.Start)
|
||||
c.movePosition(c.End, c.KeepAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
c.movePosition(QTextCursor.MoveOperation.End, c.KeepAnchor)
|
||||
|
||||
def find_first_word(haystack):
|
||||
match_pos, match_word = -1, None
|
||||
@ -555,14 +554,14 @@ class TextEdit(PlainTextEdit):
|
||||
self.centerCursor()
|
||||
return True
|
||||
c.setPosition(c.position())
|
||||
c.movePosition(c.End, c.KeepAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.End, c.KeepAnchor)
|
||||
|
||||
return False
|
||||
|
||||
def find_next_spell_error(self, from_cursor=True):
|
||||
c = self.textCursor()
|
||||
if not from_cursor:
|
||||
c.movePosition(c.Start)
|
||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
block = c.block()
|
||||
while block.isValid():
|
||||
for r in block.layout().additionalFormats():
|
||||
@ -600,7 +599,7 @@ class TextEdit(PlainTextEdit):
|
||||
def go_to_anchor(self, anchor):
|
||||
if anchor is TOP:
|
||||
c = self.textCursor()
|
||||
c.movePosition(c.Start)
|
||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
self.setTextCursor(c)
|
||||
return True
|
||||
base = r'''%%s\s*=\s*['"]{0,1}%s''' % regex.escape(anchor)
|
||||
@ -726,7 +725,7 @@ class TextEdit(PlainTextEdit):
|
||||
|
||||
def recheck_word(self, word, locale):
|
||||
c = self.textCursor()
|
||||
c.movePosition(c.Start)
|
||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
block = c.block()
|
||||
while block.isValid():
|
||||
for r in block.layout().additionalFormats():
|
||||
@ -956,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(c.End, c.KeepAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.End, c.KeepAnchor)
|
||||
self.setTextCursor(c)
|
||||
|
||||
def rename_block_tag(self, new_name):
|
||||
|
@ -476,7 +476,7 @@ class Editor(QMainWindow):
|
||||
col = c.positionInBlock()
|
||||
if not c.atStart():
|
||||
c.clearSelection()
|
||||
c.movePosition(c.PreviousCharacter, c.KeepAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.PreviousCharacter, c.KeepAnchor)
|
||||
char = unicode_type(c.selectedText()).rstrip('\0')
|
||||
return (c.blockNumber() + 1, col, char)
|
||||
|
||||
|
@ -9,7 +9,7 @@ from PyQt5.Qt import (
|
||||
QComboBox, QDate, QDateTime, QDateTimeEdit, QDialog, QDialogButtonBox, QFont,
|
||||
QFontInfo, QFontMetrics, QIcon, QKeySequence, QLabel, QLayout, QMenu, QMimeData,
|
||||
QPalette, QPixmap, QPoint, QPushButton, QRect, QScrollArea, QSize, QSizePolicy,
|
||||
QStyle, QStyledItemDelegate, Qt, QTabWidget, QTextBrowser, QToolButton,
|
||||
QStyle, QStyledItemDelegate, Qt, QTabWidget, QTextBrowser, QToolButton, QTextCursor,
|
||||
QUndoCommand, QUndoStack, QUrl, QWidget, pyqtSignal
|
||||
)
|
||||
|
||||
@ -558,8 +558,8 @@ def to_plain_text(self):
|
||||
# that
|
||||
c = self.textCursor()
|
||||
c.clearSelection()
|
||||
c.movePosition(c.Start)
|
||||
c.movePosition(c.End, c.KeepAnchor)
|
||||
c.movePosition(QTextCursor.MoveOperation.Start)
|
||||
c.movePosition(QTextCursor.MoveOperation.End, c.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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user