예제 #1
0
class IntegerProperty(Property, QWidget):
    """ Property which hold editable integer numbers.
    
    A Spinbox is provided when the property is editable.
    """

    USER_INFO = "Integer field"

    def __init__(self, name, value, categoryName=None):
        """ Constructor
        """
        Property.__init__(self, name, categoryName)
        QWidget.__init__(self)
        self.setLayout(QHBoxLayout())
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(0, 0, 0, 0)

        self._spinbox = QSpinBox()
        #self.maxint = sys.maxint     # does not work on Mac OS X (Snow Leopard 10.6.2), confusion between 32 and 64 bit limits
        self.maxint = 2**31
        self._spinbox.setRange(-self.maxint + 1, self.maxint - 1)
        self._spinbox.setFrame(False)
        self.layout().addWidget(self._spinbox)
        self.setFocusProxy(self._spinbox)
        self._lineedit = QLineEdit()
        self._lineedit.setReadOnly(True)
        self._lineedit.setFrame(False)
        self._lineedit.setContentsMargins(0, 0, 0, 0)
        self.layout().addWidget(self._lineedit)
        self._lineedit.hide()

        self.setValue(value)
        self.connect(self._spinbox, SIGNAL('valueChanged(int)'),
                     self.valueChanged)

    def setReadOnly(self, readOnly):
        """ Switches between lineedit and spinbox.
        """
        if readOnly:
            self._spinbox.hide()
            self._lineedit.show()
            self.setFocusProxy(self._lineedit)
        else:
            self._spinbox.show()
            self._lineedit.hide()
            self.setFocusProxy(self._spinbox)

    def value(self):
        """ Returns integer value.
        """
        return self._spinbox.value()

    def setValue(self, value):
        self.disconnect(self._spinbox, SIGNAL('valueChanged(int)'),
                        self.valueChanged)
        self._spinbox.setValue(value % self.maxint)
        self.connect(self._spinbox, SIGNAL('valueChanged(int)'),
                     self.valueChanged)
        self._lineedit.setText(str(value))
예제 #2
0
class IntegerProperty(Property,QWidget):
    """ Property which hold editable integer numbers.
    
    A Spinbox is provided when the property is editable.
    """
    
    USER_INFO = "Integer field"
    
    def __init__(self, name, value, categoryName=None):
        """ Constructor
        """
        Property.__init__(self, name, categoryName)
        QWidget.__init__(self)
        self.setLayout(QHBoxLayout())
        self.layout().setSpacing(0)
        self.layout().setContentsMargins(0, 0, 0, 0)
        
        self._spinbox=QSpinBox()
        #self.maxint = sys.maxint     # does not work on Mac OS X (Snow Leopard 10.6.2), confusion between 32 and 64 bit limits
        self.maxint = 2**31
        self._spinbox.setRange(-self.maxint+1, self.maxint-1)
        self._spinbox.setFrame(False)
        self.layout().addWidget(self._spinbox)
        self.setFocusProxy(self._spinbox)
        self._lineedit=QLineEdit()
        self._lineedit.setReadOnly(True)
        self._lineedit.setFrame(False)
        self._lineedit.setContentsMargins(0, 0, 0, 0)
        self.layout().addWidget(self._lineedit)
        self._lineedit.hide()

        self.setValue(value)
        self.connect(self._spinbox, SIGNAL('valueChanged(int)'), self.valueChanged)
        
    def setReadOnly(self, readOnly):
        """ Switches between lineedit and spinbox.
        """
        if readOnly:
            self._spinbox.hide()
            self._lineedit.show()
            self.setFocusProxy(self._lineedit)
        else:
            self._spinbox.show()
            self._lineedit.hide()
            self.setFocusProxy(self._spinbox)
        
    def value(self):
        """ Returns integer value.
        """
        return self._spinbox.value()
    
    def setValue(self,value):
        self.disconnect(self._spinbox, SIGNAL('valueChanged(int)'), self.valueChanged)
        self._spinbox.setValue(value % self.maxint)
        self.connect(self._spinbox, SIGNAL('valueChanged(int)'), self.valueChanged)
        self._lineedit.setText(str(value))
예제 #3
0
 def addSpinBox(self, name):
     sb = QSpinBox(self)
     sb.setEnabled(True)
     sb.setMinimumSize(QSize(60, 20))
     sb.setMaximumSize(QSize(60, 20))
     sb.setWrapping(False)
     sb.setFrame(True)
     sb.setButtonSymbols(QSpinBox.NoButtons)
     sb.setAccelerated(True)
     sb.setCorrectionMode(QSpinBox.CorrectToPreviousValue)
     sb.setKeyboardTracking(True)
     sb.setMinimum(0)
     sb.setMaximum(99999999)
     sb.setSingleStep(1000)
     sb.setAlignment(Qt.AlignRight|Qt.AlignTrailing|Qt.AlignVCenter)
     sb.setProperty("value", 0)
     sb.setObjectName(name)
     return sb
예제 #4
0
 def addSpinBox(self, name):
     sb = QSpinBox(self)
     sb.setEnabled(True)
     sb.setMinimumSize(QSize(60, 20))
     sb.setMaximumSize(QSize(60, 20))
     sb.setWrapping(False)
     sb.setFrame(True)
     sb.setButtonSymbols(QSpinBox.NoButtons)
     sb.setAccelerated(True)
     sb.setCorrectionMode(QSpinBox.CorrectToPreviousValue)
     sb.setKeyboardTracking(True)
     sb.setMinimum(0)
     sb.setMaximum(99999999)
     sb.setSingleStep(1000)
     sb.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter)
     sb.setProperty("value", 0)
     sb.setObjectName(name)
     return sb
예제 #5
0
class XTimeDeltaEdit(QFrame):
    def __init__(self, parent=None):
        super(XTimeDeltaEdit, self).__init__(parent)
        
        # define custom properties
        self.setStyleSheet(COMBO_STYLE)
        
        self._numberSpinner = QSpinBox(self)
        self._numberSpinner.setRange(0, 100000)
        self._numberSpinner.setFrame(False)
        self._numberSpinner.setButtonSymbols(QSpinBox.NoButtons)
        self._numberSpinner.setSizePolicy(QSizePolicy.Expanding,
                                          QSizePolicy.Expanding)
        
        self._unitCombo = QComboBox(self)
        self._unitCombo.setEditable(True)
        self._unitCombo.setInsertPolicy(QComboBox.NoInsert)
        self._unitCombo.setFrame(False)
        self._unitCombo.addItems(['year(s)',
                                  'month(s)',
                                  'week(s)',
                                  'day(s)',
                                  'hour(s)',
                                  'minute(s)',
                                  'second(s)'])
        
        self._unitCombo.setCurrentIndex(3)
        self._unitCombo.setSizePolicy(QSizePolicy.Expanding,
                                      QSizePolicy.Expanding)
        
        self._directionCombo = QComboBox(self)
        self._directionCombo.addItems(['ago', 'from now'])
        self._directionCombo.setEditable(True)
        self._directionCombo.setInsertPolicy(QComboBox.NoInsert)
        self._directionCombo.setFrame(False)
        self._directionCombo.setSizePolicy(QSizePolicy.Expanding,
                                           QSizePolicy.Expanding)
        
        # setup ui
        self.setFrameShape(QFrame.StyledPanel)
        self.setFrameShadow(QFrame.Sunken)
        self.setBackgroundRole(QPalette.Base)
        self.setAutoFillBackground(True)
        
        layout = QHBoxLayout()
        layout.setContentsMargins(2, 2, 2, 2)
        layout.setSpacing(0)
        layout.addWidget(self._numberSpinner)
        layout.addWidget(self._unitCombo)
        layout.addWidget(self._directionCombo)
        self.setLayout(layout)
        
    def delta(self):
        """
        Returns a delta based on this widget's information.
        
        :return     <datetime.timedelta>
        """
        number      = self._numberSpinner.value()
        unit        = self._unitCombo.currentText()
        direction   = self._directionCombo.currentText()
        
        # use past tense
        if direction == 'ago':
            number = -number
        
        if unit == 'year(s)':
            return datetime.timedelta(number * 365)
        elif unit == 'month(s)':
            return datetime.timedelta(number * 30)
        elif unit == 'week(s)':
            return datetime.timedelta(number * 7)
        elif unit == 'day(s)':
            return datetime.timedelta(number)
        elif unit == 'hour(s)':
            return datetime.timedelta(0, number * 3600)
        elif unit == 'minute(s)':
            return datetime.timedelta(0, number * 60)
        else:
            return datetime.timedelta(0, number)
    
    def setDelta(self, delta):
        """
        Sets the time delta for this widget to the inputed delta.
        
        :param      delta | <datetime.timedelta>
        """
        days = int(delta.days)
        secs = int(delta.total_seconds())
        
        direction = 'from now'
        if secs < 0:
            direction = 'ago'
        
        if days and days % 365 == 0:
            number = days / 365
            unit = 'year(s)'
        elif days and days % 30 == 0:
            number = days / 30
            unit = 'month(s)'
        elif days and days % 7 == 0:
            number = days / 7
            unit = 'week(s)'
        elif days:
            number = days
            unit = 'day(s)'
        elif secs % 3600 == 0:
            number = secs / 3600
            unit = 'hour(s)'
        elif secs % 60 == 0:
            number = secs / 60
            unit = 'minute(s)'
        else:
            number = secs
            unit = 'second(s)'
        
        self._numberSpinner.setValue(abs(int(number)))
        self._unitCombo.setCurrentIndex(self._unitCombo.findText(unit))
        index = self._directionCombo.findText(direction)
        self._directionCombo.setCurrentIndex(index)
예제 #6
0
class XTimeDeltaEdit(QFrame):
    def __init__(self, parent=None):
        super(XTimeDeltaEdit, self).__init__(parent)

        # define custom properties
        self.setStyleSheet(COMBO_STYLE)

        self._numberSpinner = QSpinBox(self)
        self._numberSpinner.setRange(0, 100000)
        self._numberSpinner.setFrame(False)
        self._numberSpinner.setButtonSymbols(QSpinBox.NoButtons)
        self._numberSpinner.setSizePolicy(QSizePolicy.Expanding,
                                          QSizePolicy.Expanding)

        self._unitCombo = QComboBox(self)
        self._unitCombo.setEditable(True)
        self._unitCombo.setInsertPolicy(QComboBox.NoInsert)
        self._unitCombo.setFrame(False)
        self._unitCombo.addItems([
            'year(s)', 'month(s)', 'week(s)', 'day(s)', 'hour(s)', 'minute(s)',
            'second(s)'
        ])

        self._unitCombo.setCurrentIndex(3)
        self._unitCombo.setSizePolicy(QSizePolicy.Expanding,
                                      QSizePolicy.Expanding)

        self._directionCombo = QComboBox(self)
        self._directionCombo.addItems(['ago', 'from now'])
        self._directionCombo.setEditable(True)
        self._directionCombo.setInsertPolicy(QComboBox.NoInsert)
        self._directionCombo.setFrame(False)
        self._directionCombo.setSizePolicy(QSizePolicy.Expanding,
                                           QSizePolicy.Expanding)

        # setup ui
        self.setFrameShape(QFrame.StyledPanel)
        self.setFrameShadow(QFrame.Sunken)
        self.setBackgroundRole(QPalette.Base)
        self.setAutoFillBackground(True)

        layout = QHBoxLayout()
        layout.setContentsMargins(2, 2, 2, 2)
        layout.setSpacing(0)
        layout.addWidget(self._numberSpinner)
        layout.addWidget(self._unitCombo)
        layout.addWidget(self._directionCombo)
        self.setLayout(layout)

    def delta(self):
        """
        Returns a delta based on this widget's information.
        
        :return     <datetime.timedelta>
        """
        number = self._numberSpinner.value()
        unit = self._unitCombo.currentText()
        direction = self._directionCombo.currentText()

        # use past tense
        if direction == 'ago':
            number = -number

        if unit == 'year(s)':
            return datetime.timedelta(number * 365)
        elif unit == 'month(s)':
            return datetime.timedelta(number * 30)
        elif unit == 'week(s)':
            return datetime.timedelta(number * 7)
        elif unit == 'day(s)':
            return datetime.timedelta(number)
        elif unit == 'hour(s)':
            return datetime.timedelta(0, number * 3600)
        elif unit == 'minute(s)':
            return datetime.timedelta(0, number * 60)
        else:
            return datetime.timedelta(0, number)

    def setDelta(self, delta):
        """
        Sets the time delta for this widget to the inputed delta.
        
        :param      delta | <datetime.timedelta>
        """
        days = int(delta.days)
        secs = int(delta.total_seconds())

        direction = 'from now'
        if secs < 0:
            direction = 'ago'

        if days and days % 365 == 0:
            number = days / 365
            unit = 'year(s)'
        elif days and days % 30 == 0:
            number = days / 30
            unit = 'month(s)'
        elif days and days % 7 == 0:
            number = days / 7
            unit = 'week(s)'
        elif days:
            number = days
            unit = 'day(s)'
        elif secs % 3600 == 0:
            number = secs / 3600
            unit = 'hour(s)'
        elif secs % 60 == 0:
            number = secs / 60
            unit = 'minute(s)'
        else:
            number = secs
            unit = 'second(s)'

        self._numberSpinner.setValue(abs(int(number)))
        self._unitCombo.setCurrentIndex(self._unitCombo.findText(unit))
        index = self._directionCombo.findText(direction)
        self._directionCombo.setCurrentIndex(index)
예제 #7
0
class LayerItemWidget( QWidget ):
    @property
    def layer(self):
        return self._layer
    @layer.setter
    def layer(self, layer):
        if self._layer:
            self._layer.changed.disconnect(self._updateState)
        self._layer = layer
        self._updateState()
        self._layer.changed.connect(self._updateState)

    def __init__( self, parent=None ):
        QWidget.__init__( self, parent=parent )
        self._layer = None

        self._font = QFont(QFont().defaultFamily(), 9)
        self._fm = QFontMetrics( self._font )
        self.bar = FractionSelectionBar( initial_fraction = 0. )
        self.bar.setFixedHeight(10)
        self.nameLabel = QLabel()
        self.nameLabel.setFont( self._font )
        self.nameLabel.setText( "None" )
        self.opacityLabel = QLabel()
        self.opacityLabel.setAlignment(Qt.AlignRight)
        self.opacityLabel.setFont( self._font )
        self.opacityLabel.setText( u"\u03B1=%0.1f%%" % (100.0*(self.bar.fraction())))
        self.toggleEye = ToggleEye()
        self.toggleEye.setActive(False)
        self.toggleEye.setFixedWidth(35)
        self.toggleEye.setToolTip("Visibility")
        self.channelSelector = QSpinBox()
        self.channelSelector.setFrame( False )
        self.channelSelector.setFont( self._font )
        self.channelSelector.setMaximumWidth( 35 )
        self.channelSelector.setAlignment(Qt.AlignRight)
        self.channelSelector.setToolTip("Channel")
        self.channelSelector.setVisible(False)

        self._layout = QGridLayout()
        self._layout.addWidget( self.toggleEye, 0, 0 )
        self._layout.addWidget( self.nameLabel, 0, 1 )
        self._layout.addWidget( self.opacityLabel, 0, 2 )
        self._layout.addWidget( self.channelSelector, 1, 0)
        self._layout.addWidget( self.bar, 1, 1, 1, 2 )

        self._layout.setColumnMinimumWidth( 0, 35 )
        self._layout.setSpacing(0)
        self._layout.setContentsMargins(5,2,5,2)

        self.setLayout( self._layout)

        self.bar.fractionChanged.connect( self._onFractionChanged )
        self.toggleEye.activeChanged.connect( self._onEyeToggle )
        self.channelSelector.valueChanged.connect( self._onChannelChanged )

    def mousePressEvent( self, ev ):
        print "plonk", ev.pos(), ev.globalPos()
        QWidget.mousePressEvent( self, ev )

    def _onFractionChanged( self, fraction ):
        if self._layer and (fraction != self._layer.opacity):
            self._layer.opacity = fraction

    def _onEyeToggle( self, active ):
        if self._layer and (active != self._layer.visible):
            self._layer.visible = active

    def _onChannelChanged( self, channel ):
        if self._layer and (channel != self._layer.channel):
            self._layer.channel = channel

    def _updateState( self ):
        if self._layer:
            self.toggleEye.setActive(self._layer.visible)
            self.bar.setFraction( self._layer.opacity )
            self.opacityLabel.setText( u"\u03B1=%0.1f%%" % (100.0*(self.bar.fraction())))
            self.nameLabel.setText( self._layer.name )
            
            if self._layer.numberOfChannels > 1:
                self.channelSelector.setVisible( True )
                self.channelSelector.setMaximum( self._layer.numberOfChannels - 1 )
                self.channelSelector.setValue( self._layer.channel )
            else:
                self.channelSelector.setVisible( False )
                self.channelSelector.setMaximum( self._layer.numberOfChannels - 1)
                self.channelSelector.setValue( self._layer.channel )
            self.update()
예제 #8
0
class LayerItemWidget( QWidget ):
    @property
    def layer(self):
        return self._layer
    @layer.setter
    def layer(self, layer):
        if self._layer:
            self._layer.changed.disconnect(self._updateState)
        self._layer = layer
        self._updateState()
        self._layer.changed.connect(self._updateState)

    def __init__( self, parent=None ):
        super(LayerItemWidget, self).__init__( parent=parent )
        self._layer = None

        self._font = QFont(QFont().defaultFamily(), 9)
        self._fm = QFontMetrics( self._font )
        self.bar = FractionSelectionBar( initial_fraction = 0. )
        self.bar.setFixedHeight(10)
        self.nameLabel = QLabel( parent=self )
        self.nameLabel.setFont( self._font )
        self.nameLabel.setText( "None" )
        self.opacityLabel = QLabel( parent=self )
        self.opacityLabel.setAlignment(Qt.AlignRight)
        self.opacityLabel.setFont( self._font )
        self.opacityLabel.setText( u"\u03B1=%0.1f%%" % (100.0*(self.bar.fraction())))
        self.toggleEye = ToggleEye( parent=self )
        self.toggleEye.setActive(False)
        self.toggleEye.setFixedWidth(35)
        self.toggleEye.setToolTip("Visibility")
        self.channelSelector = QSpinBox( parent=self )
        self.channelSelector.setFrame( False )
        self.channelSelector.setFont( self._font )
        self.channelSelector.setMaximumWidth( 35 )
        self.channelSelector.setAlignment(Qt.AlignRight)
        self.channelSelector.setToolTip("Channel")
        self.channelSelector.setVisible(False)

        self._layout = QGridLayout( self )
        self._layout.addWidget( self.toggleEye, 0, 0 )
        self._layout.addWidget( self.nameLabel, 0, 1 )
        self._layout.addWidget( self.opacityLabel, 0, 2 )
        self._layout.addWidget( self.channelSelector, 1, 0)
        self._layout.addWidget( self.bar, 1, 1, 1, 2 )

        self._layout.setColumnMinimumWidth( 0, 35 )
        self._layout.setSpacing(0)
        self._layout.setContentsMargins(5,2,5,2)

        self.setLayout( self._layout )

        self.bar.fractionChanged.connect( self._onFractionChanged )
        self.toggleEye.activeChanged.connect( self._onEyeToggle )
        self.channelSelector.valueChanged.connect( self._onChannelChanged )

    def mousePressEvent( self, ev ):
        super(LayerItemWidget, self).mousePressEvent( ev )

    def _onFractionChanged( self, fraction ):
        if self._layer and (fraction != self._layer.opacity):
            self._layer.opacity = fraction

    def _onEyeToggle( self, active ):
        if self._layer and (active != self._layer.visible):
            
            if self._layer._allowToggleVisible:
                self._layer.visible = active
            else:
                self.toggleEye.setActive(True)

    def _onChannelChanged( self, channel ):
        if self._layer and (channel != self._layer.channel):
            self._layer.channel = channel

    def _updateState( self ):
        if self._layer:
            self.toggleEye.setActive(self._layer.visible)
            self.bar.setFraction( self._layer.opacity )
            self.opacityLabel.setText( u"\u03B1=%0.1f%%" % (100.0*(self.bar.fraction())))
            self.nameLabel.setText( self._layer.name )
            
            if self._layer.numberOfChannels > 1:
                self.channelSelector.setVisible( True )
                self.channelSelector.setMaximum( self._layer.numberOfChannels - 1 )
                self.channelSelector.setValue( self._layer.channel )
            else:
                self.channelSelector.setVisible( False )
                self.channelSelector.setMaximum( self._layer.numberOfChannels - 1)
                self.channelSelector.setValue( self._layer.channel )
            self.update()