本文整理汇总了Python中PySide.QtGui.QTextEdit.document方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.document方法的具体用法?Python QTextEdit.document怎么用?Python QTextEdit.document使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTextEdit
的用法示例。
在下文中一共展示了QTextEdit.document方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QAbstractTextDocumentLayoutTest
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import document [as 别名]
class QAbstractTextDocumentLayoutTest(UsesQApplication):
objectType = QTextFormat.UserObject + 1
def foo(self):
fmt = QTextCharFormat()
fmt.setObjectType(QAbstractTextDocumentLayoutTest.objectType)
cursor = self.textEdit.textCursor()
cursor.insertText(py3k.unichr(0xFFFC), fmt)
self.textEdit.setTextCursor(cursor)
self.textEdit.close()
def testIt(self):
self.textEdit = QTextEdit()
self.textEdit.show()
interface = Foo()
self.textEdit.document().documentLayout().registerHandler(QAbstractTextDocumentLayoutTest.objectType, interface)
QTimer.singleShot(0, self.foo)
self.app.exec_()
self.assertTrue(Foo.called)
示例2: testRefcount
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import document [as 别名]
def testRefcount(self):
textedit = QTextEdit()
textedit.setReadOnly(True)
doc = textedit.document()
cursor = QTextCursor(doc)
cursor.insertText("PySide Rocks")
ud = TestUserData({"Life": 42})
self.assertEqual(sys.getrefcount(ud), 2)
cursor.block().setUserData(ud)
self.assertEqual(sys.getrefcount(ud), 3)
ud2 = cursor.block().userData()
self.assertEqual(sys.getrefcount(ud), 4)
self.udata = weakref.ref(ud, None)
del ud, ud2
self.assertEqual(sys.getrefcount(self.udata()), 2)
示例3: tesIterator
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import document [as 别名]
def tesIterator(self):
edit = QTextEdit()
cursor = edit.textCursor()
fmt = QTextCharFormat()
frags = []
for i in range(10):
fmt.setFontPointSize(i+10)
frags.append("block%d"%i)
cursor.insertText(frags[i], fmt)
doc = edit.document()
block = doc.begin()
index = 0
for i in block:
self.assertEqual(i.fragment().text(), frags[index])
index += 1
示例4: MainWindow
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import document [as 别名]
class MainWindow(QMainWindow):
windows = []
def __init__(self):
super(MainWindow, self).__init__()
# Store ourself.
self.windows.append(self)
# State!
self.current_file = None
# Editor!
self.editor = QTextEdit()
self.setCentralWidget(self.editor)
# Style the editor
style.apply_stylesheet(self.editor, 'editor.qss')
# Menus and Stuff!
self.init_actions()
self.init_menus()
self.init_toolbars()
self.init_statusbar()
# Settings!
self.init_settings()
# Icons!
self.reload_icons()
style.style_reloaded.connect(self.reload_icons)
# Fancy!
style.enable_aero(self)
self.update_title()
# Now, for some plugins.
plugins.run_signal('new_window', self)
##### Action Icons! #######################################################
def reload_icons(self):
self.setWindowIcon(style.icon('application'))
a = self.actions
for key in a.keys():
a[key].setIcon(style.icon(key.lower()))
##### Actions! ############################################################
def init_actions(self):
self.actions = a = {}
##### File Menu #######################################################
a['document-new'] = QAction("&New", self, shortcut=QKeySequence.New,
statusTip="Create a new file.",
triggered=self.action_new)
a['document-open'] = QAction("&Open", self, shortcut=QKeySequence.Open,
statusTip="Open an existing file.",
triggered=self.action_open)
a['document-save'] = QAction("&Save", self, shortcut=QKeySequence.Save,
statusTip="Save the document to disk.",
triggered=self.action_save)
a['application-exit'] = QAction("E&xit", self,
statusTip="Exit the application.",
triggered=self.close)
##### Edit Menu #######################################################
a['edit-cut'] = QAction("Cu&t", self, shortcut=QKeySequence.Cut,
triggered=self.editor.cut)
a['edit-copy'] = QAction("&Copy", self, shortcut=QKeySequence.Copy,
triggered=self.editor.copy)
a['edit-paste'] = QAction("&Paste", self, shortcut=QKeySequence.Paste,
triggered=self.editor.paste)
a['edit-cut'].setEnabled(False)
a['edit-copy'].setEnabled(False)
self.editor.copyAvailable.connect(a['edit-cut'].setEnabled)
self.editor.copyAvailable.connect(a['edit-copy'].setEnabled)
##### Tool Menu #######################################################
# This is the fun part.
a['addon-manager'] = QAction("&Add-ons", self, shortcut="Ctrl+Shift+A",
statusTip="Display the Add-ons manager.",
triggered=addons.show)
a['view-refresh'] = QAction("&Reload Style", self,
shortcut="Ctrl+Shift+R",
statusTip="Reload the style.",
triggered=style.reload)
#.........这里部分代码省略.........
示例5: qNotebook
# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import document [as 别名]
class qNotebook(QVBoxLayout):
def __init__(self):
QVBoxLayout.__init__(self)
self._teditor = QTextEdit()
self._teditor.setMinimumWidth(500)
self._teditor.setStyleSheet("font: 12pt \"Courier\";")
button_layout = QHBoxLayout()
self.addLayout(button_layout)
self.clear_but = qmy_button(button_layout, self.clear_all, "clear")
self.copy_but = qmy_button(button_layout, self._teditor.copy, "copy")
qmy_button(button_layout, self._teditor.selectAll, "select all")
qmy_button(button_layout, self._teditor.undo, "undo")
qmy_button(button_layout, self._teditor.redo, "redo")
search_button = qButtonWithArgumentsClass("search", self.search_for_text, {"search_text": ""})
button_layout.addWidget(search_button)
qmy_button(button_layout, self.save_as_html, "save notebook")
self.addWidget(self._teditor)
self._teditor.document().setUndoRedoEnabled(True)
self.image_counter = 0
self.image_dict = {}
self.image_data_dict = {}
def append_text(self, text):
self._teditor.append(str(text))
def search_for_text(self, search_text = " "):
self._teditor.find(search_text)
def clear_all(self):
self._teditor.clear()
self.image_dict = {}
self.image_counter = 0
# newdoc = QTextDocument()
# self._teditor.setDocument(newdoc)
def append_image(self, fig=None):
#This assumes that an image is there waiting to be saved from matplotlib
self.imgdata = StringIO.StringIO()
if fig is None:
pyplot.savefig(self.imgdata, transparent = False, format = img_format)
else:
fig.savefig(self.imgdata, transparent = False, format = img_format)
self.abuffer = QBuffer()
self.abuffer.open(QBuffer.ReadWrite)
self.abuffer.write(self.imgdata.getvalue())
self.abuffer.close()
self.abuffer.open(QBuffer.ReadOnly)
iReader = QImageReader(self.abuffer, img_format )
the_image = iReader.read()
# the_image = the_image0.scaledToWidth(figure_width)
# save the image in a file
imageFileName = "image" + str(self.image_counter) + "." + img_format
self.image_data_dict[imageFileName] = self.imgdata
self.image_counter +=1
imageFormat = QTextImageFormat()
imageFormat.setName(imageFileName)
imageFormat.setWidth(image_width)
self.image_dict[imageFileName] = the_image
#insert the image in the text document
text_doc = self._teditor.document()
text_doc.addResource(QTextDocument.ImageResource, QUrl(imageFileName), the_image)
cursor = self._teditor.textCursor()
cursor.movePosition(QTextCursor.End)
cursor.insertImage(imageFormat)
def add_image_data_resource(self, imgdata, imageFileName):
self.abuffer = QBuffer()
self.abuffer.open(QBuffer.ReadWrite)
self.abuffer.write(imgdata.getvalue())
self.abuffer.close()
self.abuffer.open(QBuffer.ReadOnly)
iReader = QImageReader(self.abuffer, img_format )
the_image = iReader.read()
# the_image = the_image0.scaledToWidth(figure_width)
# save the image in a file
# imageFileName = "image" + str(self.image_counter) + "." + img_format
self.image_data_dict[imageFileName] = imgdata
# self.image_counter +=1
imageFormat = QTextImageFormat()
imageFormat.setName(imageFileName)
imageFormat.setWidth(image_width)
self.image_dict[imageFileName] = the_image
#insert the image in the text document
text_doc = self._teditor.document()
text_doc.addResource(QTextDocument.ImageResource, QUrl(imageFileName), the_image)
def append_html_table_from_array(self, a, header_rows=0, precision = 3, caption = None, cmap = None):
nrows = len(a)
ncols = len(a[0])
#.........这里部分代码省略.........