本文整理汇总了Python中spyderlib.qt.QtGui.QTextEdit.toPlainText方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.toPlainText方法的具体用法?Python QTextEdit.toPlainText怎么用?Python QTextEdit.toPlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spyderlib.qt.QtGui.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.toPlainText方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TextEditor
# 需要导入模块: from spyderlib.qt.QtGui import QTextEdit [as 别名]
# 或者: from spyderlib.qt.QtGui.QTextEdit import toPlainText [as 别名]
class TextEditor(QDialog):
"""Array Editor Dialog"""
def __init__(self, text, title='', font=None, parent=None,
readonly=False, size=(400, 300)):
QDialog.__init__(self, parent)
# Destroying the C++ object right after closing the dialog box,
# otherwise it may be garbage-collected in another QThread
# (e.g. the editor's analysis thread in Spyder), thus leading to
# a segmentation fault on UNIX or an application crash on Windows
self.setAttribute(Qt.WA_DeleteOnClose)
self.text = None
self._conv = str if isinstance(text, str) else to_text_string
self.layout = QVBoxLayout()
self.setLayout(self.layout)
# Text edit
self.edit = QTextEdit(parent)
self.connect(self.edit, SIGNAL('textChanged()'), self.text_changed)
self.edit.setReadOnly(readonly)
self.edit.setPlainText(text)
if font is None:
font = get_font('texteditor')
self.edit.setFont(font)
self.layout.addWidget(self.edit)
# Buttons configuration
buttons = QDialogButtonBox.Ok
if not readonly:
buttons = buttons | QDialogButtonBox.Cancel
bbox = QDialogButtonBox(buttons)
self.connect(bbox, SIGNAL("accepted()"), SLOT("accept()"))
self.connect(bbox, SIGNAL("rejected()"), SLOT("reject()"))
self.layout.addWidget(bbox)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
self.setWindowIcon(get_icon('edit.png'))
self.setWindowTitle(_("Text editor") + \
"%s" % (" - "+str(title) if str(title) else ""))
self.resize(size[0], size[1])
def text_changed(self):
"""Text has changed"""
self.text = self._conv(self.edit.toPlainText())
def get_value(self):
"""Return modified text"""
# It is import to avoid accessing Qt C++ object as it has probably
# already been destroyed, due to the Qt.WA_DeleteOnClose attribute
return self.text
示例2: TextEditor
# 需要导入模块: from spyderlib.qt.QtGui import QTextEdit [as 别名]
# 或者: from spyderlib.qt.QtGui.QTextEdit import toPlainText [as 别名]
class TextEditor(QDialog):
"""Array Editor Dialog"""
def __init__(self, text, title='', font=None, parent=None,
readonly=False, size=(400, 300)):
QDialog.__init__(self, parent)
# Destroying the C++ object right after closing the dialog box,
# otherwise it may be garbage-collected in another QThread
# (e.g. the editor's analysis thread in Spyder), thus leading to
# a segmentation fault on UNIX or an application crash on Windows
self.setAttribute(Qt.WA_DeleteOnClose)
self.text = None
# Display text as unicode if it comes as bytes, so users see
# its right representation
if is_binary_string(text):
self.is_binary = True
text = to_text_string(text, 'utf8')
else:
self.is_binary = False
self.layout = QVBoxLayout()
self.setLayout(self.layout)
# Text edit
self.edit = QTextEdit(parent)
self.edit.textChanged.connect(self.text_changed)
self.edit.setReadOnly(readonly)
self.edit.setPlainText(text)
if font is None:
font = get_font()
self.edit.setFont(font)
self.layout.addWidget(self.edit)
# Buttons configuration
buttons = QDialogButtonBox.Ok
if not readonly:
buttons = buttons | QDialogButtonBox.Cancel
bbox = QDialogButtonBox(buttons)
bbox.accepted.connect(self.accept)
bbox.rejected.connect(self.reject)
self.layout.addWidget(bbox)
# Make the dialog act as a window
self.setWindowFlags(Qt.Window)
self.setWindowIcon(ima.icon('edit'))
self.setWindowTitle(_("Text editor") + \
"%s" % (" - "+str(title) if str(title) else ""))
self.resize(size[0], size[1])
def text_changed(self):
"""Text has changed"""
# Save text as bytes, if it was initially bytes
if self.is_binary:
self.text = to_binary_string(self.edit.toPlainText(), 'utf8')
else:
self.text = to_text_string(self.edit.toPlainText())
def get_value(self):
"""Return modified text"""
# It is import to avoid accessing Qt C++ object as it has probably
# already been destroyed, due to the Qt.WA_DeleteOnClose attribute
return self.text