本文整理汇总了Python中calibre.gui2.tweak_book.editor.smarts.NullSmarts.find_text方法的典型用法代码示例。如果您正苦于以下问题:Python NullSmarts.find_text方法的具体用法?Python NullSmarts.find_text怎么用?Python NullSmarts.find_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.gui2.tweak_book.editor.smarts.NullSmarts
的用法示例。
在下文中一共展示了NullSmarts.find_text方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TextEdit
# 需要导入模块: from calibre.gui2.tweak_book.editor.smarts import NullSmarts [as 别名]
# 或者: from calibre.gui2.tweak_book.editor.smarts.NullSmarts import find_text [as 别名]
#.........这里部分代码省略.........
c.movePosition(c.End if reverse else c.Start)
pos = c.Start if reverse else c.End
if wrap and not complete:
pos = c.End if reverse else c.Start
c.movePosition(pos, c.KeepAnchor)
raw = unicode(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')
m = pat.search(raw)
if m is None:
return False
start, end = m.span()
if start == end:
return False
if wrap and not complete:
if reverse:
textpos = c.anchor()
start, end = textpos + end, textpos + start
else:
if reverse:
# Put the cursor at the start of the match
start, end = end, start
else:
textpos = c.anchor()
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_text(self, pat, wrap=False, complete=False):
reverse = pat.flags & regex.REVERSE
c = self.textCursor()
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
if wrap and not complete:
pos = c.End if reverse else c.Start
c.movePosition(pos, c.KeepAnchor)
if hasattr(self.smarts, 'find_text'):
self.highlighter.join()
found, start, end = self.smarts.find_text(pat, c)
if not found:
return False
else:
raw = unicode(c.selectedText()).replace(PARAGRAPH_SEPARATOR, '\n').rstrip('\0')
m = pat.search(raw)
if m is None:
return False
start, end = m.span()
if start == end:
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