Exemplo n.º 1
0
class JsComponentB(app.JsComponent):

    sub1 = event.ComponentProp(settable=True)
    sub2 = event.ComponentProp(settable=True)

    @event.action
    def sub1_to_sub2(self):
        self.set_sub2(self.sub1)
Exemplo n.º 2
0
class Node(event.Component):

    val = event.IntProp(settable=True)
    parent = event.ComponentProp(settable=True)
    children = event.TupleProp(settable=True)

    @event.reaction('parent.val')
    def handle_parent_val(self, *events):
        xx = []
        for ev in events:
            if self.parent:
                xx.append(self.parent.val)
            else:
                xx.append(None)
        print('parent.val ' + ', '.join([str(x) for x in xx]))

    @event.reaction('children*.val')
    def handle_children_val(self, *events):
        xx = []
        for ev in events:
            if isinstance(ev.new_value, (int, float)):
                xx.append(ev.new_value)
            else:
                xx.append(None)
        print('children.val ' + ', '.join([str(x) for x in xx]))
Exemplo n.º 3
0
class MyObject(event.Component):
    
    att = event.Attribute()
    
    # Props to test basic stuff
    foo = event.AnyProp(6, settable=True, doc='can be anything')
    bar = event.StringProp('xx')  # not settable
    
    # Props to test array mutations
    eggs = event.ListProp([], settable=True)
    eggs2 = event.ListProp(settable=True)
    eggs3 = event.ListProp([3, 4])

    # All kinds of props, defaults
    anyprop = event.AnyProp(doc='can be anything', settable=True)
    boolprop = event.BoolProp(settable=True)
    tristateprop = event.TriStateProp(settable=True)
    intprop = event.IntProp(settable=True)
    floatprop = event.FloatProp(settable=True)
    stringprop = event.StringProp(settable=True)
    tupleprop = event.TupleProp(settable=True)
    listprop = event.ListProp(settable=True)
    dictprop = event.DictProp(settable=True)
    componentprop = event.ComponentProp(settable=True)  # can be None
    # nullprop = event.NullProp(None, settable=True)
    # eitherprop = event.EitherProp(event.IntProp, event.NoneProp)
    _privateprop = event.IntProp(settable=True)
Exemplo n.º 4
0
class CompWithInit3(event.Component):

    sub = event.ComponentProp(settable=True)

    @event.reaction('sub.a_prop')
    def _on_sub(self, *events):
        for ev in events:
            print('sub prop changed', ev.new_value)
Exemplo n.º 5
0
class CreatingJsComponent2(app.JsComponent):

    sub = event.ComponentProp(settable=True)

    @event.action
    def create_sub(self):
        with self:
            c = CreatingJsComponent2()
            self.set_sub(c)
Exemplo n.º 6
0
class MyDefaults(event.Component):
    # Custom defaults
    anyprop2 = event.AnyProp(7, doc='can be anything')
    boolprop2 = event.BoolProp(True)
    intprop2 = event.IntProp(-9)
    floatprop2 = event.FloatProp(800.45)
    stringprop2 = event.StringProp('heya')
    tupleprop2 = event.TupleProp((2, 'xx'))
    listprop2 = event.ListProp([3, 'yy'])
    dictprop2 = event.DictProp({'foo':3, 'bar': 4})
    componentprop2 = event.ComponentProp(None)
Exemplo n.º 7
0
class MyComponent4(event.Component):

    foo = event.IntProp(settable=True)
    other = event.ComponentProp(settable=True)

    @event.reaction('other.foo')
    def on_foo_explicit(self, *events):
        print('other foo is', events[-1].new_value)

    @event.reaction
    def on_foo_implicit(self):
        if self.other is not None:
            print('other foo is implicit', self.other.foo)
Exemplo n.º 8
0
class PyComponentA(app.PyComponent):

    foo = event.IntProp(settable=True)
    sub = event.ComponentProp(settable=True)

    @event.action
    def greet(self, msg):
        print('hi', msg)

    @event.emitter
    def bar_event(self, v):
        return dict(value=v)

    @event.reaction
    def _on_foo(self):
        if self.sub is not None:
            print('sub foo changed', self.sub.foo)

    @event.reaction('bar_event')
    def _on_bar(self, *events):
        print('got bar event', [ev.value for ev in events])
Exemplo n.º 9
0
class Test2(event.Component):

    other = event.ComponentProp(None, settable=True)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.data = []  # just a local variable, not a property

    @event.reaction('other.data')
    def track_data(self, *events):
        for ev in events:
            if ev.mutation == 'set':
                self.data[:] = ev.new_value
            elif ev.mutation == 'insert':
                self.data[ev.index:ev.index] = ev.objects
            elif ev.mutation == 'remove':
                self.data[ev.index:ev.index + ev.objects] = [
                ]  # objects is int here
            elif ev.mutation == 'replace':
                self.data[ev.index:ev.index + len(ev.objects)] = ev.objects
            else:
                raise NotImplementedError(ev.mutation)