Пример #1
0
    def __init__(self, maxValue=5, parent=None):
        super(SelectionGauge, self).__init__(parent=parent)
        self.setWindowFlags(QtCore.Qt.Tool)
        self.resize(400,400)

        # Don't allow anything less than 1 for the maxValue
        self.maxValue = max(maxValue, 1)

        self.layout = QtGui.QVBoxLayout(self)
        self.layout.setSpacing(20)

        self.text = QtGui.QLabel()
        self.text.setObjectName("statusText")
        self.text.setAlignment(QtCore.Qt.AlignCenter)
        self.layout.addWidget(self.text)

        self.gauge = GaugeWidget()

        sizePolicy = QtGui.QSizePolicy()
        sizePolicy.setHorizontalPolicy(QtGui.QSizePolicy.Expanding)
        sizePolicy.setVerticalPolicy(QtGui.QSizePolicy.Expanding)

        self.gauge.setSizePolicy(sizePolicy)
        self.layout.addWidget(self.gauge)

        # Qt Stylesheet Reference:
        #   http://qt-project.org/doc/qt-4.7/stylesheet-reference.html
        # Selector Syntax: 
        #   http://doc.qt.digia.com/4.7-snapshot/stylesheet-syntax.html
        self.setStyleSheet("""
            #statusText {
                font-size   : 18px;
                color       : rgb(200,200,220);
            }
        """)

        # Notify us when the scene selection changes
        self._sel_cbk_id = om.MEventMessage.addEventCallback(
                            'SelectionChanged',
                            self.updateGauge)

        # Safely delete the previous callback if this widget gets
        # deleted. Otherwise you will see a bunch of errors when it 
        # tries to fire the callback and the widget is gone.
        cbk = partial(om.MMessage.removeCallback, self._sel_cbk_id)
        self.destroyed.connect(cbk)

        # set up an animation object
        self._value_animator = QtCore.QPropertyAnimation(self, "value")
        self._value_animator.setDuration(500)
        self._value_animator.setStartValue(0.0)
        self._value_animator.setEndValue(1.0)

        # initialize the gauge to the current scene selection, if any
        self.updateGauge()
Пример #2
0
class SelectionGauge(QtGui.QDialog):
    """
    SelectionGauge(QtGui.QDialog)

    Uses a Gauge widget to track the current scene selections. 

    int maxValue -  gauge is FULL when this number of characters 
                    are selected (default 5)
    """
    def __init__(self, maxValue=5, parent=None):
        super(SelectionGauge, self).__init__(parent=parent)
        self.setWindowFlags(QtCore.Qt.Tool)
        self.resize(400,400)

        # Don't allow anything less than 1 for the maxValue
        self.maxValue = max(maxValue, 1)

        self.layout = QtGui.QVBoxLayout(self)
        self.layout.setSpacing(20)

        self.text = QtGui.QLabel()
        self.text.setObjectName("statusText")
        self.text.setAlignment(QtCore.Qt.AlignCenter)
        self.layout.addWidget(self.text)

        self.gauge = GaugeWidget()

        sizePolicy = QtGui.QSizePolicy()
        sizePolicy.setHorizontalPolicy(QtGui.QSizePolicy.Expanding)
        sizePolicy.setVerticalPolicy(QtGui.QSizePolicy.Expanding)

        self.gauge.setSizePolicy(sizePolicy)
        self.layout.addWidget(self.gauge)

        # Qt Stylesheet Reference:
        #   http://qt-project.org/doc/qt-4.7/stylesheet-reference.html
        # Selector Syntax: 
        #   http://doc.qt.digia.com/4.7-snapshot/stylesheet-syntax.html
        self.setStyleSheet("""
            #statusText {
                font-size   : 18px;
                color       : rgb(200,200,220);
            }
        """)

        # Notify us when the scene selection changes
        self._sel_cbk_id = om.MEventMessage.addEventCallback(
                            'SelectionChanged',
                            self.updateGauge)

        # Safely delete the previous callback if this widget gets
        # deleted. Otherwise you will see a bunch of errors when it 
        # tries to fire the callback and the widget is gone.
        cbk = partial(om.MMessage.removeCallback, self._sel_cbk_id)
        self.destroyed.connect(cbk)

        # set up an animation object
        self._value_animator = QtCore.QPropertyAnimation(self, "value")
        self._value_animator.setDuration(500)
        self._value_animator.setStartValue(0.0)
        self._value_animator.setEndValue(1.0)

        # initialize the gauge to the current scene selection, if any
        self.updateGauge()


    @QtCore.pyqtProperty(float) 
    def value(self):
        return self.gauge.value()

    @value.setter
    def value(self, val):
        self.gauge.setValue(val) 


    def updateGauge(self, *args, **kwargs):
        """
        updateGauge()

        Checks the current scene selection, and update 
        both the text label, and the gauge progress. 
        """
        sel = om.MSelectionList()
        om.MGlobal.getActiveSelectionList(sel)
        num_selected = sel.length()

        self.text.setText("Selected %d out of %d objects" % (num_selected, self.maxValue))

        progress = float(num_selected) / self.maxValue
        currentVal = self.gauge.value()

        # animate from our current value, to our new value
        anim = self._value_animator
        anim.setStartValue(currentVal)
        anim.setEndValue(progress)
        anim.start()