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

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

     1  #!/usr/bifn/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  @lastEditedBy: Carlos Mão de Ferro (carlos.maodeferro@neuro.fchampalimaud.org)
    12  '''
    13  import sip
    14
    15  from PyQt4 import QtGui
    16  from pyforms.gui.Controls.ControlBase import ControlBase
    17  from pyforms.gui.BaseWidget import BaseWidget
    18
    19
    20 -class ControlEmptyWidget(ControlBase, QtGui.QWidget):
    21
    22
    23 -        def __init__(self, label=''):
    24                  ControlBase.__init__(self, label)
    25                  QtGui.QWidget.__init__(self)
    26
    27                  layout = QtGui.QVBoxLayout(); layout.setMargin(0)
    28                  self.form.setLayout( layout )
    29
    30 -        def initForm(self):
    31                  pass
    32
    33          ############################################################################
    34          ############ Properties ####################################################
    35          ############################################################################
    36
    37          @property
    38 -        def value(self): return ControlBase.value.fget(self)
    39
    40          @value.setter
    41 -        def value(self, value):
    42                  ControlBase.value.fset(self, value)
    43                  self.__clearLayout()
    44
    45
    46                  if value is None or value=='':  return
    47
    48                  if isinstance( self._value, list ):
    49                          for w in self._value:
    50                                  if w!=None and w!="": self.form.layout().removeWidget( w.form )
    51
    52                  if isinstance( value, list ):
    53                          for w in value:
    54                                  self.form.layout().addWidget( w.form )
    55                  else:
    56                          self.form.layout().addWidget( value.form )
    57
    58                  #The initForm should be called only for the BaseWidget
    59                  if isinstance(value, BaseWidget): value.initForm()
    60
    61
    62          @property
    63 -        def form(self): return self
    64
    65 -        def save(self, data):
    66                  if self.value!='':
    67                          data['value'] = {}
    68                          self.value.save(data['value'])
    69
    70 -        def load(self, data):
    71                  if 'value' in data: self.value.load(data['value'])
    72
    73
    74
    75
    76
    77 -        def __clearLayout(self):
    78                  if self.form.layout() is not None:
    79                          old_layout = self.form.layout()
    80                          for i in reversed(range(old_layout.count())):
    81                                  old_layout.itemAt(i).widget().setParent(None)
    82
    83
    84 -        def show(self):
    85                  """
    86                  Show the control
    87                  """
    88                  QtGui.QWidget.show(self)
    89
    90 -        def hide(self):
    91                  """
    92                  Hide the control
    93                  """
    94                  QtGui.QWidget.hide(self)
    95