本文整理汇总了Python中QProgEdit.QTabManager.setInvalid方法的典型用法代码示例。如果您正苦于以下问题:Python QTabManager.setInvalid方法的具体用法?Python QTabManager.setInvalid怎么用?Python QTabManager.setInvalid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QProgEdit.QTabManager
的用法示例。
在下文中一共展示了QTabManager.setInvalid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: qtitem
# 需要导入模块: from QProgEdit import QTabManager [as 别名]
# 或者: from QProgEdit.QTabManager import setInvalid [as 别名]
#.........这里部分代码省略.........
def apply_script_changes(self, *deprecated, **_deprecated):
"""
desc:
Applies changes to the script.
"""
if not self.validate_script():
return
new_script = self._script_widget.text()
old_script = self.to_string()
self.from_string(new_script)
if old_script != new_script:
self.main_window.set_unsaved()
self.edit_widget()
def apply_script_changes_and_switch_view(self, *deprecated, **_deprecated):
"""
desc:
Applies changes to the script if possible. If so, switches to the
controls view.
"""
if self.validate_script():
self.set_view_controls()
def validate_script(self):
"""
desc:
Checks whether the script is syntactically valid. If not, the
offending line is highlighted if QProgEdit suppors setInvalid().
returns:
type: bool
"""
script = self._script_widget.text()
# First create a dummy item to see if the string can be parsed.
try:
self.validator(self.name, self.experiment, script)
return True
except Exception as e:
# If an error occurs, we first parse the first line, then the first
# and second, and so on, until we find the error.
l = script.split(u'\n')
for line_nr, line in enumerate(l):
test_script = u'\n'.join(l[:line_nr])
try:
self.validator(self.name, self.experiment, test_script)
except Exception as e_:
if not isinstance(e_, osexception):
e_ = osexception(e_)
if hasattr(self._script_widget, u'setInvalid'):
self._script_widget.setInvalid(line_nr, e_.markdown())
break
self.console.write(e)
return False
def set_validator(self):
"""
desc:
Sets the validator class, that is, the class that is used to parse