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

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

     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, QtCore
    15  from pyforms.gui.Controls.ControlBase import ControlBase
    16
    17 -class ControlCheckBoxList(ControlBase):
    18
    19 -    def initForm(self):
    20          control_path = tools.getFileInSameDirectory(__file__,"tree.ui")
    21          self._form = uic.loadUi( control_path )
    22
    23          self._form.label.setText(self._label)
    24
    25 -    def __add__(self, val):
    26          if isinstance( val, tuple ):
    27              item=QtGui.QListWidgetItem(val[0])
    28              if val[1]: item.setCheckState( QtCore.Qt.Checked)
    29              else: item.setCheckState( QtCore.Qt.Unchecked)
    30          else:
    31              item=QtGui.QListWidgetItem(val )
    32
    33          self._form.listWidget.addItem(item)
    34          return self
    35
    36 -    def clear(self):
    37          self._form.listWidget.clear()
    38
    39
    40      ############################################################################
    41      ############ Properties ####################################################
    42      ############################################################################
    43
    44      @property
    45 -    def count(self): return self._form.listWidget.count()
    46
    47      @property
    48 -    def checkedIndexes(self):
    49          results = []
    50          for row in range( self.count ):
    51              item = self._form.listWidget.item(row)
    52              if item!=None and item.checkState()==QtCore.Qt.Checked : results.append( row )
    53          return results
    54
    55      @property
    56 -    def value(self):
    57          results = []
    58          for row in range( self.count ):
    59              item = self._form.listWidget.item(row)
    60              if item!=None and item.checkState()==QtCore.Qt.Checked : results.append( item.text() )
    61          return results
    62
    63      @value.setter
    64 -    def value(self, value):
    65          for row in value: self += row
    66