本文整理匯總了Python中calibre.gui2.tweak_book.editor.smarts.NullSmarts.verify_for_spellcheck方法的典型用法代碼示例。如果您正苦於以下問題:Python NullSmarts.verify_for_spellcheck方法的具體用法?Python NullSmarts.verify_for_spellcheck怎麽用?Python NullSmarts.verify_for_spellcheck使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類calibre.gui2.tweak_book.editor.smarts.NullSmarts
的用法示例。
在下文中一共展示了NullSmarts.verify_for_spellcheck方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TextEdit
# 需要導入模塊: from calibre.gui2.tweak_book.editor.smarts import NullSmarts [as 別名]
# 或者: from calibre.gui2.tweak_book.editor.smarts.NullSmarts import verify_for_spellcheck [as 別名]
#.........這裏部分代碼省略.........
start, end = textpos + start, textpos + end
c.clearSelection()
c.setPosition(start)
c.setPosition(end, c.KeepAnchor)
self.setTextCursor(c)
# Center search result on screen
self.centerCursor()
if save_match is not None:
self.saved_matches[save_match] = (pat, m)
return True
def find_spell_word(self, original_words, lang, from_cursor=True, center_on_cursor=True):
c = self.textCursor()
c.setPosition(c.position())
if not from_cursor:
c.movePosition(c.Start)
c.movePosition(c.End, c.KeepAnchor)
def find_first_word(haystack):
match_pos, match_word = -1, None
for w in original_words:
idx = index_of(w, haystack, lang=lang)
if idx > -1 and (match_pos == -1 or match_pos > idx):
match_pos, match_word = idx, w
return match_pos, match_word
while True:
text = unicode(c.selectedText()).rstrip('\0')
idx, word = find_first_word(text)
if idx == -1:
return False
c.setPosition(c.anchor() + idx)
c.setPosition(c.position() + string_length(word), c.KeepAnchor)
if self.smarts.verify_for_spellcheck(c, self.highlighter):
self.setTextCursor(c)
if center_on_cursor:
self.centerCursor()
return True
c.setPosition(c.position())
c.movePosition(c.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)
block = c.block()
while block.isValid():
for r in block.layout().additionalFormats():
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)
self.setTextCursor(c)
return True
block = block.next()
return False
def replace(self, pat, template, saved_match='gui'):
c = self.textCursor()
raw = unicode(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')
m = pat.fullmatch(raw)
if m is None:
# This can happen if either the user changed the selected text or
# the search expression uses lookahead/lookbehind operators. See if
示例2: TextEdit
# 需要導入模塊: from calibre.gui2.tweak_book.editor.smarts import NullSmarts [as 別名]
# 或者: from calibre.gui2.tweak_book.editor.smarts.NullSmarts import verify_for_spellcheck [as 別名]
#.........這裏部分代碼省略.........
start, end = textpos + start, textpos + end
c.clearSelection()
c.setPosition(start)
c.setPosition(end, c.KeepAnchor)
self.setTextCursor(c)
# Center search result on screen
self.centerCursor()
if save_match is not None:
self.saved_matches[save_match] = (pat, m)
return True
def find_spell_word(self, original_words, lang, from_cursor=True, center_on_cursor=True):
c = self.textCursor()
c.setPosition(c.position())
if not from_cursor:
c.movePosition(c.Start)
c.movePosition(c.End, c.KeepAnchor)
def find_first_word(haystack):
match_pos, match_word = -1, None
for w in original_words:
idx = index_of(w, haystack, lang=lang)
if idx > -1 and (match_pos == -1 or match_pos > idx):
match_pos, match_word = idx, w
return match_pos, match_word
while True:
text = unicode(c.selectedText()).rstrip("\0")
idx, word = find_first_word(text)
if idx == -1:
return False
c.setPosition(c.anchor() + idx)
c.setPosition(c.position() + string_length(word), c.KeepAnchor)
if self.smarts.verify_for_spellcheck(c, self.highlighter):
self.setTextCursor(c)
if center_on_cursor:
self.centerCursor()
return True
c.setPosition(c.position())
c.movePosition(c.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)
block = c.block()
while block.isValid():
for r in block.layout().additionalFormats():
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)
self.setTextCursor(c)
return True
block = block.next()
return False
def replace(self, pat, template, saved_match="gui"):
c = self.textCursor()
raw = unicode(c.selectedText()).replace(PARAGRAPH_SEPARATOR, "\n").rstrip("\0")
m = pat.fullmatch(raw)
if m is None:
# This can happen if either the user changed the selected text or
# the search expression uses lookahead/lookbehind operators. See if
示例3: TextEdit
# 需要導入模塊: from calibre.gui2.tweak_book.editor.smarts import NullSmarts [as 別名]
# 或者: from calibre.gui2.tweak_book.editor.smarts.NullSmarts import verify_for_spellcheck [as 別名]
#.........這裏部分代碼省略.........
return False
if reverse:
start, end = end, start
c.clearSelection()
c.setPosition(start)
c.setPosition(end, c.KeepAnchor)
self.setTextCursor(c)
# Center search result on screen
self.centerCursor()
return True
def find_spell_word(self, original_words, lang, from_cursor=True, center_on_cursor=True):
c = self.textCursor()
c.setPosition(c.position())
if not from_cursor:
c.movePosition(c.Start)
c.movePosition(c.End, c.KeepAnchor)
def find_first_word(haystack):
match_pos, match_word = -1, None
for w in original_words:
idx = index_of(w, haystack, lang=lang)
if idx > -1 and (match_pos == -1 or match_pos > idx):
match_pos, match_word = idx, w
return match_pos, match_word
while True:
text = unicode_type(c.selectedText()).rstrip('\0')
idx, word = find_first_word(text)
if idx == -1:
return False
c.setPosition(c.anchor() + idx)
c.setPosition(c.position() + string_length(word), c.KeepAnchor)
if self.smarts.verify_for_spellcheck(c, self.highlighter):
self.highlighter.join() # Ensure highlighting is finished
locale = self.spellcheck_locale_for_cursor(c)
if not lang or not locale or (locale and lang == locale.langcode):
self.setTextCursor(c)
if center_on_cursor:
self.centerCursor()
return True
c.setPosition(c.position())
c.movePosition(c.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)
block = c.block()
while block.isValid():
for r in block.layout().additionalFormats():
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)
self.setTextCursor(c)
return True
block = block.next()
return False
def replace(self, pat, template, saved_match='gui'):
c = self.textCursor()
raw = unicode_type(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')
m = pat.fullmatch(raw)