For a complete explanation of code to write for each function, or to create a class from scratch, please have a look to IControlWidget and example after.
To create a class for standard QWidget, you can copy/paste this code
Here plugin is exactly the same as simple approach, except that it returns XyzControlWidgetSelector instead of XyzControlWidget.
from openalea.oalab.plugin.control import ControlWidgetSelectorPlugin
from openalea.deploy.shared_data import shared_data
class PluginXyzWidgetSelector(ControlWidgetSelectorPlugin):
controls = ['IXyz'] # Interface name like IInt
edit_shape = ['responsive']
name = 'XyzWidgetSelector'
def __call__(self):
from mypackage.plugins.selectors import XyzControlWidgetSelector
return XyzControlWidgetSelector
See also
See IInt example for real case
All Qt sliders define "value" and "setValue" methods directly compatible with IInt (int), so there is almost nothing to do:
We define also a widget to edit constraints
Now, lets define widget selector to group all classes together :
You can notice in line 11, instruction to set widget to fit to vline shape.
And finally, lets define plugin that links to it.
Warning
All classes can be defined in same file excepted last one. PluginIntWidgetSelector must be defined in a separated file to allow to load only description.
shape supported by a control editor or viewer:
Bases: object
Bases: openalea.core.interface.IInterface
Bases: openalea.core.interface.IInterface
An IControlWidget is a
Enable auto-read mode on given control. Important, control passed to autoread and autoapply can be identical or different. For example if you want to refresh view if a template changes and apply it automatically to your current control.
Method called when Observed control changes. Generally, when control send an event "ValueChanged", we want to refresh widget with new value.
Method called when value changed. This method generally read control and refresh view if auto-read mode is enabled.
Use control to preset widget. Starts to listen to control events and read control's values
Change widget value. If your class derivates from an third-party widget, it is sometime necessary to adapt control value type to widget supported type. Example unicode to QString in pyqt API v1.
Returns widget value. If your class derivates from an third-party widget, it is sometime necessary to adapt widget value type to control type. If widget supports more than one interface, returned value depends on given interface. If none, returns widget preferred type.
Bases: openalea.core.interface.IInterface
Returns an instance of IControlWidget that can generate controls.
Returns an instance of IControlWidget that modifies control in place. Control can be updated continuously or on explicit user action (click on apply button for instance)
Returns a widget to edit constraints. This widget must respect IConstraintWidget interface.