Beispiel #1
0
    def __init__(self, parent=None, editable=True, **kw):
        CustomEditor.__init__(self, parent)
        self.years_spinbox = CustomDoubleSpinBox()
        self.months_spinbox = CustomDoubleSpinBox()
        self.years_spinbox.setMinimum(0)
        self.years_spinbox.setMaximum(10000)
        self.months_spinbox.setMinimum(0)
        self.months_spinbox.setMaximum(12)
        self.years_spinbox.setSuffix(_(' years'))
        self.months_spinbox.setSuffix(_(' months'))

        self.years_spinbox.setDecimals(0)
        self.years_spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.years_spinbox.setSingleStep(1)

        self.months_spinbox.setDecimals(0)
        self.months_spinbox.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
        self.months_spinbox.setSingleStep(1)

        self.years_spinbox.editingFinished.connect(
            self._spinbox_editing_finished)
        self.months_spinbox.editingFinished.connect(
            self._spinbox_editing_finished)

        layout = QHBoxLayout()
        layout.addWidget(self.years_spinbox)
        layout.addWidget(self.months_spinbox)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)
Beispiel #2
0
    def __init__(self, parent=None, editable=True, field_name='months', **kw):
        CustomEditor.__init__(self, parent)
        self.setObjectName( field_name )
        self.years_spinbox = CustomDoubleSpinBox()
        self.months_spinbox = CustomDoubleSpinBox()
        self.years_spinbox.setMinimum(0)
        self.years_spinbox.setMaximum(10000)
        self.months_spinbox.setMinimum(0)
        self.months_spinbox.setMaximum(12)
        self.years_spinbox.setSuffix(_(' years'))
        self.months_spinbox.setSuffix(_(' months'))
        
        self.years_spinbox.setDecimals(0)
        self.years_spinbox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
        self.years_spinbox.setSingleStep(1)
        
        self.months_spinbox.setDecimals(0)
        self.months_spinbox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
        self.months_spinbox.setSingleStep(1)

        self.years_spinbox.editingFinished.connect( self._spinbox_editing_finished )
        self.months_spinbox.editingFinished.connect( self._spinbox_editing_finished )
        
        layout = QHBoxLayout()
        layout.addWidget(self.years_spinbox)
        layout.addWidget(self.months_spinbox)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)
Beispiel #3
0
    def __init__(self, parent=None, editable=True, field_name='months', **kw):
        CustomEditor.__init__(self, parent)
        self.setSizePolicy( QtGui.QSizePolicy.Preferred,
                            QtGui.QSizePolicy.Fixed )        
        self.setObjectName( field_name )
        self.years_spinbox = CustomDoubleSpinBox()
        self.months_spinbox = CustomDoubleSpinBox()
        self.years_spinbox.setRange(-1, 10000)
        self.months_spinbox.setRange(-1, 12)
        self.years_spinbox.setSuffix(_(' years'))
        self.months_spinbox.setSuffix(_(' months'))
        
        self.years_spinbox.setDecimals(0)
        self.years_spinbox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
        self.years_spinbox.setSingleStep(1)
        
        self.months_spinbox.setDecimals(0)
        self.months_spinbox.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
        self.months_spinbox.setSingleStep(1)

        self.years_spinbox.editingFinished.connect( self._spinbox_editing_finished )
        self.months_spinbox.editingFinished.connect( self._spinbox_editing_finished )
        
        layout = QtWidgets.QHBoxLayout()
        layout.addWidget(self.years_spinbox)
        layout.addWidget(self.months_spinbox)
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)
Beispiel #4
0
    def set_value(self, value):
        # will set privates value_is_none and _value_loading
        CustomEditor.set_value(self, value)

        # TODO: might be better to have accessors for these
        if self._value_loading:
            return

        if self.value_is_none:
            value = 0

        # value comes as a months total
        years, months = divmod(value, 12)
        self.years_spinbox.setValue(years)
        self.months_spinbox.setValue(months)
Beispiel #5
0
    def set_value(self, value):
        # will set privates value_is_none and _value_loading
        CustomEditor.set_value(self, value)

        # TODO: might be better to have accessors for these
        if self._value_loading:
            return

        if self.value_is_none:
            value = 0

        # value comes as a months total
        years, months = divmod( value, 12 )
        self.years_spinbox.setValue(years)
        self.months_spinbox.setValue(months)
Beispiel #6
0
    def get_value(self):
        if CustomEditor.get_value(self) is ValueLoading:
            return ValueLoading

        self.years_spinbox.interpretText()
        years = int(self.years_spinbox.value())
        self.months_spinbox.interpretText()
        months = int(self.months_spinbox.value())
        value = (years * 12) + months
        return value
Beispiel #7
0
    def get_value(self):
        if CustomEditor.get_value(self) is ValueLoading:
            return ValueLoading

        self.years_spinbox.interpretText()
        years = int(self.years_spinbox.value())
        self.months_spinbox.interpretText()
        months = int(self.months_spinbox.value())
        value = (years * 12) + months
        return value
Beispiel #8
0
 def set_value(self, value):
     # will set privates value_is_none and _value_loading
     value = CustomEditor.set_value(self, value)
     if value is None:
         self.years_spinbox.setValue(self.years_spinbox.minimum())
         self.months_spinbox.setValue(self.months_spinbox.minimum())
     else:
         # value comes as a months total
         years, months = divmod( value, 12 )
         self.years_spinbox.setValue(years)
         self.months_spinbox.setValue(months)
Beispiel #9
0
 def get_value(self):
     if CustomEditor.get_value(self) is ValueLoading:
         return ValueLoading
     self.years_spinbox.interpretText()
     years = int(self.years_spinbox.value())
     self.months_spinbox.interpretText()
     months = int(self.months_spinbox.value())
     years_is_none = (years == self.years_spinbox.minimum())
     months_is_none = (months == self.months_spinbox.minimum())
     if years_is_none and months_is_none:
         return None
     if years_is_none:
         years = 0
     if months_is_none:
         months = 0
     return (years * 12) + months