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


Python QPushButton.toggle方法代码示例

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


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

示例1: TimelineWidget

# 需要导入模块: from python_qt_binding.QtGui import QPushButton [as 别名]
# 或者: from python_qt_binding.QtGui.QPushButton import toggle [as 别名]
class TimelineWidget(QWidget):
    class TimelineView(QGraphicsView):
        def __init__(self, parent):
            super(TimelineWidget.TimelineView, self).__init__()
            self.parent = parent

        def mouseReleaseEvent(self, event):
            self.parent.mouse_release(event)

    update = pyqtSignal()
    def __init__(self, parent):
        super(TimelineWidget, self).__init__()
        self.parent = parent

        self._layout = QHBoxLayout()

        #self._view = QGraphicsView()
        self._view = TimelineWidget.TimelineView(self)

        self._scene = QGraphicsScene()
        self._colors = [QColor('green'), QColor('yellow'), QColor('red')]

        self._messages = [None for x in range(20)]
        self._mq = [1 for x in range(20)] 

        self._view.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self._view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self._view.setScene(self._scene)
        self._layout.addWidget(self._view, 1)

        self.pause_button = QPushButton('Pause')
        self.pause_button.setCheckable(True)
        self.pause_button.clicked.connect(self.pause)
        self._layout.addWidget(self.pause_button)

        self.setLayout(self._layout)

        self.update.connect(self.redraw)

    def redraw(self):
        self._scene.clear()
        self._scene
        for i, m in enumerate(self._mq):
            w = float(self._view.viewport().width())/len(self._mq)
            h = self._view.viewport().height()
            rect = self._scene.addRect(w*i, 0, w, h, QColor('black'), self._colors[m])

    def mouse_release(self, event):
        i = int(floor(event.x()/(float(self._view.viewport().width())/len(self._mq))))

        msg = self._messages[i]
        if msg:
            self.parent.pause(msg)
            if not self.pause_button.isChecked():
                self.pause_button.toggle()

    def resizeEvent(self, event):
        self.redraw()

    def get_worst(self, msg):
        lvl = 0
        for status in msg.status:
            if status.level > lvl:
                lvl = status.level

        return lvl

    def add_message(self, msg):
        self._messages = self._messages[1:]
        self._messages.append(msg)

        self._mq = self._mq[1:]
        try:
            lvl = msg.level
        except AttributeError:
            lvl = self.get_worst(msg)

        if lvl > 2:
            lvl = 2

        self._mq.append(lvl)

        self.update.emit()

    def pause(self, state):
        if state:
            self.parent.pause(self._messages[-1])
        else:
            self.parent.unpause()
开发者ID:zklapow,项目名称:robot_monitor,代码行数:91,代码来源:robot_monitor.py


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