06/13/13 18:12:28 (10 months ago)
Ales Erjavec <ales.erjavec@…>

Updated Widget development tutorial.

1 edited


  • docs/extend-widgets/rst/settings.rst

    r11439 r11593  
    4646    class OWDataSamplerB(OWWidget): 
    4747        settingsList = ['proportion', 'commitOnChange'] 
    48         def __init__(self, parent=None, signalManager=None): 
    5049Any setting has to be initialized, and then we need to call 
    157156of this widget. To distinguish it with a widget we have developed in the 
    158157previous section, we have designed a special 
    159 :download:`icon <DataSamplerB.png>` for it. If you wish to test is 
     158:download:`icon <DataSamplerB.svg>` for it. If you wish to test is 
    160159widget in the Orange Canvas, put its code in the Test directory we 
    161160have created for the previous widget, update the Canvas registry, and 
    410409:obj:`ContextField("attrX", DomainContextHandler.Required)` 
    412 .. 
    413    But see this monster from widget "Select Attributes" (file OWDataDomain.py):: 
    415        contextHandlers = {"": DomainContextHandler("", 
    416            [ContextField("chosenAttributes", 
    417                           DomainContextHandler.RequiredList, 
    418                           selected="selectedChosen", reservoir="inputAttributes"), 
    419             ContextField("classAttribute", 
    420                           DomainContextHandler.RequiredList, 
    421                           selected="selectedClass", reservoir="inputAttributes"), 
    422             ContextField("metaAttributes", 
    423                           DomainContextHandler.RequiredList, 
    424                           selected="selectedMeta", reservoir="inputAttributes") 
    425        ])} 
    428    :obj:`ContextField`'s constructor gets the name and flags and a list of 
    429    arguments that are written directly into the object instance. To follow the 
    430    example, recall what Select Attributes looks like: it allows you to select a 
    431    subset of attributes, the class attribute and the meta attributes that you 
    432    want to use; the attributes in the corresponding three list boxes are stored 
    433    in the widget's variables :obj:`chosenAttributes`, :obj:`classAttribute` 
    434    and :obj:`metaAttributes` respectively. When the user selects some attributes 
    435    in any of these boxes, the selection is stored in :obj:`selectedChosen`, 
    436    :obj:`selectedClass` and :obj:`selectedMeta`. The remaining attributes 
    437    - those that are not in any of these three list boxes - are in the leftover 
    438    listbox on the left-hand side of the widget, and the content of the box is 
    439    stored in the widget's variable :obj:`inputAttributes`. 
    441    The above definition tells that the context needs to store the contents of 
    442    the three list boxes by specifying the corresponding variables; the list of 
    443    attributes is given as the name of the field and the list of selected 
    444    attributes is in the optional named attribute :obj:`selected`. By 
    445    :obj:`reservoir` we told the context handler that the attributes are taken 
    446    from :obj:`inputAttributes`. So, when a context is retrieved, all the 
    447    attributes that are not in any of the three list boxes are put into 
    448    :obj:`inputAttributes`. 
    450    Why the mess? Couldn't we just store :obj:`inputAttributes` as the fourth 
    451    list box? Imagine that the user first loads the data with attributes A, B, 
    452    C, D, E and F, puts A, B, C in chosen and D in class. E and F are left in 
    453    :obj:`inputAttributes`. Now she loads another data which has attributes A, 
    454    B, C, D, E, and G. The contexts should match (the new data has all the 
    455    attributes we need), but :obj:`inputAttributes` should now contain E and 
    456    G, not E and F, since F doesn't exist any more, while G needs to be made 
    457    available. 
    459    You can use :obj:`ContextField` (instead of tuples and strings) for 
    460    declaring any fields, but you will usually need them only for lists or, 
    461    maybe, some complicated future controls. 
Note: See TracChangeset for help on using the changeset viewer.