Package pyforms :: Package gui :: Package Controls :: Module ControlSlider |
[hide private]
[frames] | no frames]

# Source Code for Module pyforms.gui.Controls.ControlSlider

     1  #!/usr/bin/python
     2  # -*- coding: utf-8 -*-
     3
     4  __author__      = "Ricardo Ribeiro"
     5  __credits__     = ["Ricardo Ribeiro"]
     6  __license__     = "MIT"
     7  __version__     = "0.0"
     8  __maintainer__  = "Ricardo Ribeiro"
     9  __email__       = "ricardojvr@gmail.com"
    10  __status__      = "Development"
    11
    12
    13  import pyforms.Utils.tools as tools
    14  from PyQt4 import uic, QtGui
    15  from pyforms.gui.Controls.ControlBase import ControlBase
    16
    17 -class ControlSlider(ControlBase):
    18
    19          _min = 0
    20          _max = 100
    21
    22 -        def __init__(self, label = "", defaultValue = 0, min = 0, max = 100):
    23                  self._updateSlider = True
    24                  self._min = min
    25                  self._max = max
    26
    27                  ControlBase.__init__(self, label, defaultValue)
    28                  self._form.value.setText( str(defaultValue) )
    29                  self._form.horizontalSlider.valueChanged.connect( self.valueChanged )
    30
    31 -        def initForm(self):
    32                  control_path = tools.getFileInSameDirectory(__file__,"sliderInput.ui")
    33                  self._form = uic.loadUi( control_path )
    34                  self._form.label.setText(self._label)
    35                  self._form.horizontalSlider.setMinimum(self._min)
    36                  self._form.horizontalSlider.setMaximum(self._max)
    37                  self._form.horizontalSlider.setValue( self._value )
    38
    39 -        def valueChanged(self, value):
    40                  self._updateSlider = False
    41                  self.value = value
    42                  self._updateSlider = True
    43
    44 -        def load(self, data):
    45                  if 'value' in data: self.value = data['value']
    46
    47
    48 -        def save(self, data):
    49                  if self.value: data['value'] = self.value
    50
    51          @property
    52 -        def value(self): return self._value
    53
    54          @value.setter
    55 -        def value(self, value):
    56                  ControlBase.value.fset(self, value)
    57                  if self._updateSlider and self._value!=None:  self._form.horizontalSlider.setValue( int(value) )
    58                  self._form.value.setText( str(value) )
    59
    60
    61          @property
    62 -        def min(self): return self._form.horizontalSlider.minimum()
    63
    64          @min.setter
    65 -        def min(self, value): self._form.horizontalSlider.setMinimum(value)
    66
    67          @property
    68 -        def max(self): return self._form.horizontalSlider.maximum()
    69
    70          @max.setter
    71 -        def max(self, value): self._form.horizontalSlider.setMaximum(value)
    72