Home | Download/Install | Documentation | Packages | Screenshots | News | Forum/Mailing-lists | Contact | GForge
Interface are used to specify the type of data structure which are exchanged between nodes. They are used to generate node widgets but also to do automatic conversion between different type of objects.
In this document we show:
OpenAlea provides a set of common interfaces with associated widgets.
IFloat and IInt : Numeric value
IFloat and IInt interfaces support min and max specification. ex: IInt(0, 20)
IStr : String
IBool : Boolean
IFileStr and IDirStr : File or Directory names
You can specify a filename filter : IFileStr(“mtg (*.mtg)”)
IRGBColor : RGB Color
IEnumStr : Enumeration
You can specify the possible input values : IEnumStr([“Val1”, “Val2”])
ISequence : List
ITuple : Tuple
IDict : Dictionnary
IDateTime : Date and Time
If you need to use your own interface, you can declare it in your wralea.py file.
from openalea.core.interface import * class IMyInterface(IInterface): """ My own interface """ __metaclass__ = IInterfaceMetaClass # interface methods
You can also declare an interface widget which will be automatically associated with the interface.
Nota : Interface widget are registered in the platform by adding the following lines in the class declaration :
__interface__ = IFloat # Associated Interface class __metaclass__ = make_metaclass() # Registration by Metaclass
from openalea.core import * class IFloat(IInterface): """ Interface for Float object """ __metaclass__ = IInterfaceMetaClass __pytype__ = types.FloatType class IFloatWidget(IInterfaceWidget, QtGui.QWidget): """ Float spin box widget """ # Associate widget with the IFloat interface __interface__ = IFloat __metaclass__ = make_metaclass() def __init__(self, node, parent, parameter_str, interface): """ @param parameter_str : the parameter key the widget is associated to @param interface : instance of interface object """ QtGui.QWidget.__init__(self, parent) IInterfaceWidget.__init__(self, node, parent, parameter_str, interface) hboxlayout = QtGui.QHBoxLayout(self) self.spin = QtGui.QDoubleSpinBox (self) self.spin.setRange(interface.min, interface.max) hboxlayout.addWidget(self.spin) self.notify(None,None) self.connect(self.spin, QtCore.SIGNAL("valueChanged(double)"), self.valueChanged) def valueChanged(self, newval): self.node.set_input_by_key(self.param_str, newval) def notify(self, sender, event): """ Notification sent by node """ try: v = float(self.node.get_input_by_key(self.param_str)) except: v = 0. self.spin.setValue(v)