Package Camelot :: Package camelot :: Package view :: Package controls :: Package delegates :: Module enumerationdelegate |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.controls.delegates.enumerationdelegate

     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 customdelegate import CustomDelegate, DocumentationMetaclass
    29  from PyQt4 import QtGui, QtCore
    30  from PyQt4.QtGui import QComboBox, QItemDelegate
    31  from PyQt4.QtCore import QVariant, QString, Qt
    32
    33  from camelot.view.controls import editors
    34  from camelot.core.utils import variant_to_pyobject
    35  from camelot.view.proxy import ValueLoading
    36
    37 -class EnumerationDelegate(CustomDelegate):
    38      """Contrary to the comboboxdelegate, the enumeration delegate does not support dynamic
    39      choices"""
    40
    41      __metaclass__ = DocumentationMetaclass
    42      editor = editors.ChoicesEditor
    43
    44 -    def __init__(self, parent=None, choices=[], editable=True, **kwargs):
    45          CustomDelegate.__init__(self, parent, editable=editable, **kwargs)
    46          self.choices = choices
    47          self._choices_dict = dict(choices)
    48
    49 -    def createEditor(self, parent, option, index):
    50          editor = super(EnumerationDelegate, self).createEditor(parent, option, index)
    51          editor.set_choices(self.choices)
    52          return editor
    53
    54 -    def paint(self, painter, option, index):
    55          value = variant_to_pyobject(index.data(Qt.EditRole))
    56          if value in (None, ValueLoading):
    57              value = ''
    58          painter.save()
    59          self.paint_text(painter, option, index, unicode(self._choices_dict.get(value, '...')))
    60          painter.restore()
    61