Example #1
0
def auto_view(model):
    """ Generate a view directly from a `HasTraits` instance.
    """
    descriptions = _model_traits(model)
    labels = [Label(text=desc.label) for desc in descriptions]
    editors = [_get_editor(model, desc) for desc in descriptions]
    objects = [widget for pair in zip(labels, editors) for widget in pair]
    return AutoView(objects=objects)
Example #2
0
def create_editor(obj, form=None):
    assert isinstance(obj, Atom)

    klass = obj.__class__

    form = form or Form()

    # get the members
    for member_name, member_descriptor in klass.members().items():
        # by default we are skipping members starting with _
        if member_name.startswith('_'):
            continue

        m = member_descriptor.metadata or {}
        if m.get('exclude', False):
            continue

        label_text = m.get('label', member_name)
        label = Label(text=label_text)

        widget = Field()
        model_attr = 'text'
        if isinstance(member_descriptor, Typed):
            type_ = member_descriptor.validate_mode[1]
            if issubclass(type_, datetime.date):
                widget = DatetimeSelector(calendar_popup=True)
                model_attr = 'datetime'
            elif issubclass(type_, int):
                widget = IntField()
                model_attr = 'value'

        form.insert_children(None, [label, widget])

        connect(obj, member_name, widget, model_attr)

    return form
Example #3
0
 def create_component(self):
     return Label(text=self.obj)
Example #4
0
 def create_component(self):
     return Label(text='test label')