当前位置: 首页>>代码示例>>Python>>正文


Python QTextEdit.setPlainText方法代码示例

本文整理汇总了Python中PySide.QtGui.QTextEdit.setPlainText方法的典型用法代码示例。如果您正苦于以下问题:Python QTextEdit.setPlainText方法的具体用法?Python QTextEdit.setPlainText怎么用?Python QTextEdit.setPlainText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtGui.QTextEdit的用法示例。


在下文中一共展示了QTextEdit.setPlainText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MainWindow

# 需要导入模块: from PySide.QtGui import QTextEdit [as 别名]
# 或者: from PySide.QtGui.QTextEdit import setPlainText [as 别名]

#.........这里部分代码省略.........
        edit.addAction(a['edit-copy'])
        edit.addAction(a['edit-paste'])

        tools = self.addToolBar("Tools")
        tools.setObjectName('toolsbar')
        tools.addAction(a['addon-manager'])
        tools.addAction(a['view-refresh'])

    ##### Statusbars! #########################################################

    def init_statusbar(self):
        self.statusBar().showMessage("Ready.")

    ##### Settings! ###########################################################

    def init_settings(self):
        self.restoreGeometry(profile.get("geometry"))
        self.restoreState(profile.get("state"))

    def save_settings(self):
        profile.set("geometry", self.saveGeometry())
        profile.set("state", self.saveState())

    ##### Actual Actions! #####################################################

    def update_title(self):
        if self.current_file:
            title = os.path.basename(self.current_file)
        else:
            title = "Untitled"
        self.setWindowTitle("%s - %s" % (title,
                QApplication.instance().applicationName()))

    def action_new(self):
        if self.try_save():
            self.editor.clear()
            self.current_file = None
            self.update_title()

    def action_open(self):
        if self.try_save():
            fn = QFileDialog.getOpenFileName(self)[0]
            if not fn:
                return

            self.do_open(fn)

    def do_open(self, fn):
        with open(fn, 'r') as f:
            content = f.read()

        self.editor.setPlainText(content)
        self.current_file = fn
        self.update_title()

    def action_save(self):
        if not self.editor.document().isModified():
            return

        if not self.current_file:
            self.current_file = QFileDialog.getSaveFileName(self)[0]
            self.update_title()

        if not self.current_file:
            return

        with open(self.current_file, 'w') as f:
            f.write(self.editor.toPlainText())
        self.editor.document().setModified(False)

    ##### Adventure! ##########################################################

    def try_save(self):
        if self.editor.document().isModified():
            ret = QMessageBox.warning(self, "Blah Blah Blah",
                    "That's an awfully nice modified document you've got there"
                    ". It'd be a shame if anything... happened to it. Catch "
                    "my drift?",
                    QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel
                    )
            if ret == QMessageBox.Save:
                self.action_save()

            elif ret == QMessageBox.Cancel:
                return False

        return True

    def closeEvent(self, event):
        if self.try_save():
            self.save_settings()

            if self in self.windows:
                self.windows.remove(self)

            plugins.run_signal('close_window', self)

            event.accept()
        else:
            event.ignore()
开发者ID:apt-shansen,项目名称:siding,代码行数:104,代码来源:main_window.py


注:本文中的PySide.QtGui.QTextEdit.setPlainText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。