oneliners.pyΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
This example demonstrates how a property can be set to follow other properties
by setting the property to be a function, which is converted to a reaction by
Flexx.

This feature makes basic plumbing very easy, like e.g. showing values
of properties in a label widget.
"""

# todo: also a one-liner to invoke actions from emitters (issue #425)

from flexx import event


class Person(event.Component):

    first_name = event.StringProp('Jane', settable=True)
    last_name = event.StringProp('Doe', settable=True)


class Greeter(event.Component):

    message = event.StringProp('', settable=True)

    @event.reaction
    def show_message(self):
        print('Message:', self.message)

p = Person()

# This is the line that this is about
g = Greeter(message=lambda: p.first_name + ' ' + p.last_name)

p.set_first_name('Alice')

event.loop.iter()