Control - Advanced


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

Widget selector

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

IInt control widget

All Qt sliders define "value" and "setValue" methods directly compatible with IInt (int), so there is almost nothing to do:

We will use these widgets depending on context:
  • QDial for responsive, large and small shapes
  • QSlider for vline
  • QSpinBox for hline

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.


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.


create mode
Users want to create a control from scratch. In other words, it can be considered as "write-only" widget.
view mode
Users want to visualize a control. If control value changes, users may want to see changes. In other words, it can be considered as a "read-only" with option to enable auto-read mode.
edit mode
Users want to edit a control. If control value changes, users may want to reload changes. Users may want theirs changes to be applied dynamically or not. In other words, it can be considered as a "read/write" widget with options to enable both auto-read mode mode and auto-apply mode.
auto-read mode
If widget has auto-read mode enabled: if value changes, view is automatically refreshed to display new value.
auto-apply mode
If widget has auto-apply mode enabled: each time users modify data in the view, changes are automatically applied to object being edited.
control shape

shape supported by a control editor or viewer:

  • hline: widget fits well in an horizontal line for example in a cell in a table or spreadsheet, in a 200x20px widget, ...
  • vline: widget fits well in a vertical line, for example in 20x200px widget
  • small: widget fits well in a small squared widget (100x100 px to 300x300 px)
  • large: widget fits well in large space (> 300x300 px)
  • responsive: widget can fit well in all shapes and sizes. Hardest to create but easiest to use.


Table Of Contents

Previous topic


Next topic

<no title>

This Page