Package Camelot :: Package camelot :: Package view :: Package controls :: Package editors :: Module booleditor |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.controls.editors.booleditor

      1  #  ============================================================================

      2  #

      3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved.

      4  #  www.conceptive.be / project-camelot@conceptive.be

      5  #

      6  #  This file is part of the Camelot Library.

      7  #

      8  #  This file may be used under the terms of the GNU General Public

      9  #  License version 2.0 as published by the Free Software Foundation

     10  #  and appearing in the file LICENSE.GPL included in the packaging of

     11  #  this file.  Please review the following information to ensure GNU

     12  #  General Public Licensing requirements will be met:

     13  #  http://www.trolltech.com/products/qt/opensource.html

     14  #

     15  #  If you are unsure which license is appropriate for your use, please

     16  #  review the following information:

     17  #  http://www.trolltech.com/products/qt/licensing.html or contact

     18  #  project-camelot@conceptive.be.

     19  #

     20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE

     21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

     22  #

     23  #  For use of this library in commercial applications, please contact

     24  #  project-camelot@conceptive.be

     25  #

     26  #  ============================================================================

     27

     28  from PyQt4 import QtGui, QtCore
     29  from PyQt4.QtCore import Qt
     30

     31  from customeditor import AbstractCustomEditor
     32  from camelot.core import constants
     33  from camelot.core.utils import ugettext
     34

     35 -class BoolEditor(QtGui.QCheckBox, AbstractCustomEditor):
     36      """Widget for editing a boolean field"""
     37

     38 -    def __init__(self,

     39                   parent=None,

     40                   minimum=constants.camelot_minint,

     41                   maximum=constants.camelot_maxint,

     42                   editable=True,

     43                   **kwargs):
     44          QtGui.QCheckBox.__init__(self, parent)
     45          AbstractCustomEditor.__init__(self)
     46          self.setEnabled(editable)
     47          self.connect(self,

     48                       QtCore.SIGNAL('stateChanged(int)'),

     49                       self.editingFinished)
     50

     51 -    def set_value(self, value):
     52          value = AbstractCustomEditor.set_value(self, value)
     53          if value:
     54              self.setCheckState(Qt.Checked)
     55          else:
     56              self.setCheckState(Qt.Unchecked)
     57

     58 -    def get_value(self):
     59          value = self.isChecked()
     60          return AbstractCustomEditor.get_value(self) or value
     61

     62 -    def editingFinished(self, value=None):
     63          self.emit(QtCore.SIGNAL('editingFinished()'))
     64

     65 -    def set_enabled(self, editable=True):
     66          value = self.get_value()
     67          self.setDisabled(not editable)
     68          self.set_value(value)
     69

     70 -    def sizeHint(self):
     71          size = QtGui.QComboBox().sizeHint()
     72          return size
     73

     74 -class TextBoolEditor(QtGui.QLabel, AbstractCustomEditor):
     75      """

     76      :Parameter:

     77          color_yes: string

     78              text-color of the True representation

     79          color_no: string

     80              text-color of the False representation

     81      """
     82 -    def __init__(self,

     83                   parent=None,

     84                   yes="Yes",

     85                   no="No",

     86                   color_yes=None,

     87                   color_no=None,

     88                   **kwargs):
     89          QtGui.QLabel.__init__(self, parent)
     90          AbstractCustomEditor.__init__(self)
     91          self.setEnabled(False)
     92          self.yes = ugettext(yes)
     93          self.no = ugettext(no)
     94          self.color_yes = color_yes
     95          self.color_no = color_no
     96

     97 -    def set_value(self, value):
     98          value = AbstractCustomEditor.set_value(self, value)
     99          if value:
    100              self.setText(self.yes)
    101              if self.color_yes:
    102                  selfpalette = self.palette()
    103                  selfpalette.setColor(QtGui.QPalette.WindowText, self.color_yes)
    104                  self.setPalette(selfpalette)
    105          else:
    106              self.setText(self.no)
    107              if self.color_no:
    108                  selfpalette = self.palette()
    109                  selfpalette.setColor(QtGui.QPalette.WindowText, self.color_no)
    110                  self.setPalette(selfpalette)
    111