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

Source Code for Module Camelot.camelot.view.controls.editors.customeditor

 1  
 
 2  from PyQt4.QtCore import Qt 
 3  from PyQt4 import QtGui, QtCore 
 4  
 
 5  import camelot.types 
 6  from camelot.core.constants import * 
 7  from camelot.view.proxy import ValueLoading 
 8  from camelot.core.utils import create_constant_function 
 9  
 
10  editingFinished = QtCore.SIGNAL('editingFinished()') 
11   
 
12 -class AbstractCustomEditor(object):
13 """Helper class to be used to build custom editors. This class provides 14 functionallity to store and retrieve `ValueLoading` as an editor's value. 15 """ 16
17 - def __init__(self):
18 self._value_loading = True
19
20 - def set_value(self, value):
21 if value==ValueLoading: 22 self._value_loading = True 23 return None 24 else: 25 self._value_loading = False 26 return value
27
28 - def get_value(self):
29 if self._value_loading: 30 return ValueLoading 31 return None
32 33 34 """ 35 Get the 'standard' height for a cell 36 """
37 - def get_height(self):
38 39 height = [QtGui.QLineEdit().sizeHint().height(), 40 QtGui.QDateEdit().sizeHint().height(), 41 QtGui.QDateTimeEdit().sizeHint().height(), 42 QtGui.QSpinBox().sizeHint().height(), 43 QtGui.QDateEdit().sizeHint().height(), 44 QtGui.QComboBox().sizeHint().height()] 45 46 finalHeight = max(height) 47 48 return finalHeight
49
50 - def set_background_color(self, background_color):
51 if background_color not in (None, ValueLoading): 52 palette = self.palette() 53 for x in [QtGui.QPalette.Active, QtGui.QPalette.Inactive, QtGui.QPalette.Disabled]: 54 for y in [self.backgroundRole(), QtGui.QPalette.Window]: 55 palette.setColor(x, y, background_color) 56 self.setPalette(palette) 57 else: 58 return False
59
60 -class CustomEditor(QtGui.QWidget, AbstractCustomEditor):
61 """Base class for implementing custom editor widgets. This class provides 62 dual state functionality. Each editor should have the posibility to have as 63 its value `ValueLoading` specifying that no value has been set yet. 64 """
65 - def __init__(self, parent):
66 QtGui.QWidget.__init__(self, parent) 67 AbstractCustomEditor.__init__(self)
68