When clicking an attribute in a creation/edition dialog box,
the createEditor
class method is executed. The signature
is the following :
def createEditor(cls, xattribute, parent, xobject, value, text)
cls
is the current class, xattribute
is the
xattribute corresponding to the item edited, parent
is the
parent qt widget. The xobject
is quite special. If it is
an object edition, this attribute contains the object being edited,
if it is an object creation, this attribute contains a dictionnary
whom keys are the attributes names already present and values are
the value founded in the dialog edition box. It allows to deals with
the dependencies between attributes at gui level. value
attribute
contains the current value or None
if not already setted and
text
attribute contains the current text or None
if
not already setted.
The default implementation of createEditor
class method coded
in XObject class do nearly nothing ... it's only called the
createEditor
method on the xattribute
object with the
following signature:
def createEditor(self, cls, parent, xobject, value, text)
self
is the XAttribute instance and other
attributes are the same as described previously.
The default implementation of createEditor
method is coded
in XAttribute class. It does nearly nothing ... it's only
called the createEditor
method on the xtype
object
contained in the xattribute
object with the
following signature:
def createEditor(self, xattribute, cls, parent, xobject, value, text)
self
is now an instance of XType class.
The default implementation is coded in XType class and
create the default behaviour i.e. a QLineEdit
.
All this mechanism provide a way to intercept easily the
way that the editors are created. A usual configuration
is to define his own XType
subclass and re-implement
the createEditor
method for this class. For instance :
from xdata import * class MyXInstance(XInstance): def createEditor(self, *args, **kwargs): ## do before job editor = super(MyXInstance, self).createEditor(*args, **kwargs) ## do after job ## return the editor ! return editor pass