本文整理汇总了Python中spyderlib.qt.QtGui.QCheckBox.setCheckState方法的典型用法代码示例。如果您正苦于以下问题:Python QCheckBox.setCheckState方法的具体用法?Python QCheckBox.setCheckState怎么用?Python QCheckBox.setCheckState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtGui.QCheckBox
的用法示例。
在下文中一共展示了QCheckBox.setCheckState方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FindReplace
# 需要导入模块: from spyderlib.qt.QtGui import QCheckBox [as 别名]
# 或者: from spyderlib.qt.QtGui.QCheckBox import setCheckState [as 别名]
#.........这里部分代码省略.........
self.editor.highlight_found_results(text, words=words,
regexp=regexp)
def clear_matches(self):
"""Clear all highlighted matches"""
if self.is_code_editor:
self.editor.clear_found_results()
def find(self, changed=True, forward=True,
rehighlight=True, start_highlight_timer=False):
"""Call the find function"""
text = self.search_text.currentText()
if len(text) == 0:
self.search_text.lineEdit().setStyleSheet("")
return None
else:
case = self.case_button.isChecked()
words = self.words_button.isChecked()
regexp = self.re_button.isChecked()
found = self.editor.find_text(text, changed, forward, case=case,
words=words, regexp=regexp)
self.search_text.lineEdit().setStyleSheet(self.STYLE[found])
if self.is_code_editor and found:
if rehighlight or not self.editor.found_results:
self.highlight_timer.stop()
if start_highlight_timer:
self.highlight_timer.start()
else:
self.highlight_matches()
else:
self.clear_matches()
return found
@Slot()
def replace_find(self):
"""Replace and find"""
if (self.editor is not None):
replace_text = to_text_string(self.replace_text.currentText())
search_text = to_text_string(self.search_text.currentText())
pattern = search_text if self.re_button.isChecked() else None
case = self.case_button.isChecked()
first = True
cursor = None
while True:
if first:
# First found
seltxt = to_text_string(self.editor.get_selected_text())
cmptxt1 = search_text if case else search_text.lower()
cmptxt2 = seltxt if case else seltxt.lower()
if self.editor.has_selected_text() and cmptxt1 == cmptxt2:
# Text was already found, do nothing
pass
else:
if not self.find(changed=False, forward=True,
rehighlight=False):
break
first = False
wrapped = False
position = self.editor.get_position('cursor')
position0 = position
cursor = self.editor.textCursor()
cursor.beginEditBlock()
else:
position1 = self.editor.get_position('cursor')
if is_position_inf(position1,
position0 + len(replace_text) -
len(search_text) + 1):
# Identify wrapping even when the replace string
# includes part of the search string
wrapped = True
if wrapped:
if position1 == position or \
is_position_sup(position1, position):
# Avoid infinite loop: replace string includes
# part of the search string
break
if position1 == position0:
# Avoid infinite loop: single found occurrence
break
position0 = position1
if pattern is None:
cursor.removeSelectedText()
cursor.insertText(replace_text)
else:
seltxt = to_text_string(cursor.selectedText())
cursor.removeSelectedText()
cursor.insertText(re.sub(pattern, replace_text, seltxt))
if self.find_next():
found_cursor = self.editor.textCursor()
cursor.setPosition(found_cursor.selectionStart(),
QTextCursor.MoveAnchor)
cursor.setPosition(found_cursor.selectionEnd(),
QTextCursor.KeepAnchor)
else:
break
if not self.all_check.isChecked():
break
self.all_check.setCheckState(Qt.Unchecked)
if cursor is not None:
cursor.endEditBlock()
示例2: FindReplace
# 需要导入模块: from spyderlib.qt.QtGui import QCheckBox [as 别名]
# 或者: from spyderlib.qt.QtGui.QCheckBox import setCheckState [as 别名]
#.........这里部分代码省略.........
self.is_code_editor = isinstance(editor, CodeEditor)
self.highlight_button.setVisible(self.is_code_editor)
if refresh:
self.refresh()
if self.isHidden() and editor is not None:
self.clear_matches()
def find_next(self):
"""Find next occurence"""
state = self.find(changed=False, forward=True, rehighlight=False)
self.editor.setFocus()
self.search_text.add_current_text()
return state
def find_previous(self):
"""Find previous occurence"""
state = self.find(changed=False, forward=False, rehighlight=False)
self.editor.setFocus()
return state
def text_has_been_edited(self, text):
"""Find text has been edited (this slot won't be triggered when
setting the search pattern combo box text programmatically"""
self.find(changed=True, forward=True, start_highlight_timer=True)
def highlight_matches(self):
"""Highlight found results"""
if self.is_code_editor and self.highlight_button.isChecked():
text = self.search_text.currentText()
words = self.words_button.isChecked()
regexp = self.re_button.isChecked()
self.editor.highlight_found_results(text, words=words, regexp=regexp)
def clear_matches(self):
"""Clear all highlighted matches"""
if self.is_code_editor:
self.editor.clear_found_results()
def find(self, changed=True, forward=True, rehighlight=True, start_highlight_timer=False):
"""Call the find function"""
text = self.search_text.currentText()
if len(text) == 0:
self.search_text.lineEdit().setStyleSheet("")
return None
else:
case = self.case_button.isChecked()
words = self.words_button.isChecked()
regexp = self.re_button.isChecked()
found = self.editor.find_text(text, changed, forward, case=case, words=words, regexp=regexp)
self.search_text.lineEdit().setStyleSheet(self.STYLE[found])
if found:
if rehighlight or not self.editor.found_results:
self.highlight_timer.stop()
if start_highlight_timer:
self.highlight_timer.start()
else:
self.highlight_matches()
else:
self.clear_matches()
return found
def replace_find(self):
"""Replace and find"""
if self.editor is not None:
replace_text = self.replace_text.currentText()
search_text = self.search_text.currentText()
pattern = search_text if self.re_button.isChecked() else None
first = True
while True:
if first:
# First found
if self.editor.has_selected_text() and self.editor.get_selected_text() == unicode(search_text):
# Text was already found, do nothing
pass
else:
if not self.find(changed=False, forward=True, rehighlight=False):
break
first = False
wrapped = False
position = self.editor.get_position("cursor")
position0 = position
else:
position1 = self.editor.get_position("cursor")
if wrapped:
if position1 == position or self.editor.is_position_sup(position1, position):
# Avoid infinite loop: replace string includes
# part of the search string
break
if position1 == position0:
# Avoid infinite loop: single found occurence
break
if self.editor.is_position_inf(position1, position0):
wrapped = True
position0 = position1
self.editor.replace(replace_text, pattern=pattern)
if not self.find_next():
break
if not self.all_check.isChecked():
break
self.all_check.setCheckState(Qt.Unchecked)