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


Python QPlainTextEdit.appendHtml方法代码示例

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


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

示例1: ConsoleDock

# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendHtml [as 别名]
class ConsoleDock(QDockWidget):
    def __init__(self, parent = None):
        super().__init__(parent)

        self.setObjectName("ConsoleDock")
        self.setWindowTitle(self.tr("Debug Console"))
        widget = QWidget(self)
        layout = QVBoxLayout(widget)
        layout.setContentsMargins(5, 5, 5, 5)
        self.plainTextEdit = QPlainTextEdit()
        self.plainTextEdit.setReadOnly(True)
        self.plainTextEdit.setStyleSheet(QString(
                                "QAbstractScrollArea {"
                                " background-color: black;"
                                " color:green;"
                                "}"
                                ))
        layout.addWidget(self.plainTextEdit)
        
        for output in PluginManager.objects(LoggingInterface):
            self.registerOutput(output)

        PluginManager.instance().objectAdded.connect(self.onObjectAdded)

        self.setWidget(widget)

    def __del__(self):
        pass

    def appendInfo(self, s):
        self.plainTextEdit.appendHtml('<pre>'+s+'</pre>')

    def appendError(self, s):
        self.plainTextEdit.appendHtml("<pre style='color:red'>"+s+"</pre>")


    def onObjectAdded(self, object):
        if type(object) == LoggingInterface:
            self.registerOutput(object)

    def registerOutput(self, output):
        output.info.connect(self.appendInfo)
        output.error.connect(self.appendError)
开发者ID:theall,项目名称:Python-Tiled,代码行数:45,代码来源:consoledock.py

示例2: LogWindow

# 需要导入模块: from PyQt5.QtWidgets import QPlainTextEdit [as 别名]
# 或者: from PyQt5.QtWidgets.QPlainTextEdit import appendHtml [as 别名]

#.........这里部分代码省略.........
        if min_height:
            self.setMinimumHeight(min_height)

        log_group = StyledQGroupBox("Log")
        log_layout_1 = QVBoxLayout()
        log_layout_2 = QHBoxLayout()
        self.log = QPlainTextEdit()
        # QPlainTextEdit better than QTextEdit because it supports
        # maximumBlockCount while still allowing HTML (via appendHtml,
        # not insertHtml).
        self.log.setReadOnly(True)
        self.log.setLineWrapMode(QPlainTextEdit.NoWrap)
        self.log.setMaximumBlockCount(maximum_block_count)
        log_clear_button = QPushButton('Clear log')
        log_clear_button.clicked.connect(self.log.clear)
        log_copy_button = QPushButton('Copy to clipboard')
        log_copy_button.clicked.connect(self.copy_whole_log)
        log_layout_2.addWidget(log_clear_button)
        log_layout_2.addWidget(log_copy_button)
        log_layout_2.addStretch()
        log_layout_1.addWidget(self.log)
        log_layout_1.addLayout(log_layout_2)
        log_group.setLayout(log_layout_1)

        main_widget = QWidget(self)
        self.setCentralWidget(main_widget)
        main_layout = QVBoxLayout(main_widget)
        main_layout.addWidget(log_group)

        self.emit_msg.connect(self.log_internal)

        if logger:
            logger.addHandler(self.get_handler())

    def get_handler(self) -> logging.Handler:
        return self.handler

    def set_may_close(self, may_close: bool) -> None:
        # log.debug("LogWindow: may_close({})".format(may_close))
        self.may_close = may_close
        # return
        if may_close:
            self.setWindowFlags(self.windowFlags() | Qt.WindowCloseButtonHint)
        else:
            self.setWindowFlags(self.windowFlags() & ~Qt.WindowCloseButtonHint)
        self.show()
        # ... or it will be hidden (in a logical not a real way!) by
        # setWindowFlags(), and thus mess up the logic for the whole Qt app
        # exiting (since qt_app.exec_() runs until there are no more windows
        # being shown).

    def copy_whole_log(self) -> None:
        # Ctrl-C will copy the selected parts.
        # log.copy() will copy the selected parts.
        self.log.selectAll()
        self.log.copy()
        self.log.moveCursor(QTextCursor.End)
        self.scroll_to_end_of_log()

    def scroll_to_end_of_log(self) -> None:
        vsb = self.log.verticalScrollBar()
        vsb.setValue(vsb.maximum())
        hsb = self.log.horizontalScrollBar()
        hsb.setValue(0)

    # noinspection PyPep8Naming
    def closeEvent(self, event: QCloseEvent) -> None:
        """Trap exit."""
        if not self.may_close:
            # log.debug("LogWindow: ignore closeEvent")
            event.ignore()
        else:
            # log.debug("LogWindow: accept closeEvent")
            event.accept()

    def log_message(self, html: str) -> None:
        # Jump threads via a signal
        self.emit_msg.emit(html)

    @pyqtSlot(str)
    def log_internal(self, html: str) -> None:
        # self.log.moveCursor(QTextCursor.End)
        # self.log.insertHtml(html)
        self.log.appendHtml(html)
        # self.scroll_to_end_of_log()
        # ... unnecessary; if you're at the end, it scrolls, and if you're at
        # the top, it doesn't bug you.

    @pyqtSlot()
    def exit(self) -> None:
        # log.debug("LogWindow: exit")
        self.may_close = True
        # closed = QMainWindow.close(self)
        # log.debug("closed: {}".format(closed))
        QMainWindow.close(self)

    @pyqtSlot()
    def may_exit(self) -> None:
        # log.debug("LogWindow: may_exit")
        self.set_may_close(True)
开发者ID:RudolfCardinal,项目名称:whisker-python-client,代码行数:104,代码来源:qt.py


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