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


Python QTextBrowser.reload方法代码示例

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


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

示例1: HTMLViewerDialog

# 需要导入模块: from PyQt4.Qt import QTextBrowser [as 别名]
# 或者: from PyQt4.Qt.QTextBrowser import reload [as 别名]
class HTMLViewerDialog(QDialog):
    """This class implements a dialog to view a piece of HTML text."""

    def __init__(self, parent, config_name=None, buttons=[], *args):
        """Creates dialog.
        'config_name' is used to get/set default window size from Config object
        'buttons' can be a list of names or (QPixmapWrapper,name[,tooltip]) tuples to provide
        custom buttons at the bottom of the dialog. When a button is clicked, the dialog
        emits SIGNAL("name").
        A "Close" button is always provided, this simply hides the dialog.
        """
        QDialog.__init__(self, parent, *args)
        self.setModal(False)
        lo = QVBoxLayout(self)
        # create viewer
        self.label = QLabel(self)
        self.label.setMargin(5)
        self.label.setWordWrap(True)
        lo.addWidget(self.label)
        self.label.hide()
        self.viewer = QTextBrowser(self)
        lo.addWidget(self.viewer)
        # self.viewer.setReadOnly(True)
        self.viewer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        QObject.connect(self.viewer, SIGNAL("anchorClicked(const QUrl &)"), self._urlClicked)
        self._source = None
        lo.addSpacing(5)
        # create button bar
        btnfr = QFrame(self)
        btnfr.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed)
        # btnfr.setMargin(5)
        lo.addWidget(btnfr)
        lo.addSpacing(5)
        btnfr_lo = QHBoxLayout(btnfr)
        btnfr_lo.setMargin(5)
        # add user buttons
        self._user_buttons = {}
        for name in buttons:
            if isinstance(name, str):
                btn = QPushButton(name, btnfr)
            elif isinstance(name, (list, tuple)):
                if len(name) < 3:
                    pixmap, name = name
                    tip = None
                else:
                    pixmap, name, tip = name
                btn = QPushButton(pixmap.icon(), name, btnfr)
                if tip:
                    btn.setToolTip(tip)
            self._user_buttons[name] = btn
            btn._clicked = Kittens.utils.curry(self.emit, SIGNAL(name))
            self.connect(btn, SIGNAL("clicked()"), btn._clicked)
            btnfr_lo.addWidget(btn, 1)
        # add a Close button
        btnfr_lo.addStretch(100)
        closebtn = QPushButton(pixmaps.grey_round_cross.icon(), "Close", btnfr)
        self.connect(closebtn, SIGNAL("clicked()"), self.hide)
        btnfr_lo.addWidget(closebtn, 1)
        # resize selves
        self.config_name = config_name or "html-viewer"
        width = Config.getint('%s-width' % self.config_name, 512)
        height = Config.getint('%s-height' % self.config_name, 512)
        self.resize(QSize(width, height))

    def resizeEvent(self, ev):
        QDialog.resizeEvent(self, ev)
        sz = ev.size()
        Config.set('%s-width' % self.config_name, sz.width())
        Config.set('%s-height' % self.config_name, sz.height())

    def setDocument(self, filename, empty=""):
        """Sets the HTML text to be displayed. """
        self._source = QUrl.fromLocalFile(filename)
        if os.path.exists(filename):
            self.viewer.setSource(self._source)
        else:
            self.viewer.setText(empty)

    def _urlClicked(self, url):
        path = str(url.path())
        if path:
            self.emit(SIGNAL("viewPath"), path)
        # to make sure it keeps displaying the same thing
        self.viewer.setSource(self._source)

    def reload(self):
        self.viewer.reload()

    def setLabel(self, label=None):
        if label is None:
            self.label.hide()
        else:
            self.label.setText(label)
            self.label.show()
开发者ID:kernsuite-debian,项目名称:purr,代码行数:96,代码来源:MainWindow.py


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