Package pyforms :: Package web :: Package Controls :: Module ControlCombo |
[hide private]
[frames] | no frames]

# Source Code for Module pyforms.web.Controls.ControlCombo

     1  from pyforms.web.Controls.ControlBase import ControlBase
     2
     3 -class ControlCombo(ControlBase):
     4
     5
     6 -    def __init__(self, label = "", defaultValue = "", helptext=None):
     7          super(ControlCombo, self).__init__(label, defaultValue,helptext)
     8          self._items = {}
     9
    10 -    def initControl(self):
    11          if self._items==None: self._items={}
    12          self._addingItem = False
    13          values = [list(x) for x in sorted(self._items.items(), key=lambda x: x[1]) ]
    14          for v in values:
    15              if v[1]==self._value:
    16                  values.remove(v)
    17                  values.insert(0, v)
    18
    19          return "controls.push(new ControlCombo('%s','%s', %s,'%s'));" % (self._label, self._name, values ,self.help )
    20
    21 -    def currentIndexChanged(self, index):
    22          if not self._addingItem:
    23              if len(item)>=1:
    24                  OTControlBase.value.fset(self, self._items[str(item)])
    25
    26 -    def addItem(self, label, value = None):
    27          if self._items==None: self._items={}
    28          self._addingItem = True
    29
    30          firstValue = False
    31          if self._items=={}: firstValue = True
    32
    33          if value==None:
    34              self._items[label] = label
    35          else:
    36              self._items[label] = value
    37          self._addingItem = False
    38
    39          if firstValue: self.value = self._items[label]
    40
    41
    42 -    def clearItems(self):
    43          self._items = {}
    44          self._value = None
    45
    46      @property
    47 -    def items(self): return self._items.values()
    48
    49      @property
    50 -    def values(self): return self._items.items()
    51
    52      @property
    53 -    def value(self): return self._value
    54
    55      @value.setter
    56 -    def value(self, value):
    57          for key, val in self._items.items():
    58              if value == val:
    59                  if self._value!=value: self.valueUpdated(value)
    60                  self._value = val
    61
    62      @property
    63 -    def text(self): return ""
    64
    65      @text.setter
    66 -    def text(self, value):
    67          for key, val in self._items.items():
    68              if value == key:
    69                  self.value = val
    70                  break
    71