deep_event_connections.pyΒΆ

open in new tab
 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
"""
Example that demonstrates how one can connect to events deep in the
hierachy. Instead of using the star notation to select all children,
one can use a double-star to select also the children's children, and
their children, etc.
"""

from flexx import flx


class DeepEventConnections(flx.Widget):

    def init(self):
        # Put a label and some sliders deep in the hierarchy

        with flx.VBox():
            self.label = flx.Label()
            with flx.HFix(flex=1):
                for j in range(2):
                    with flx.VBox(flex=1):
                        for i in range(5):
                            flx.Slider(value=i/5)

    @flx.reaction('!children**.value')
    def on_slider_change(self, *events):
        for ev in events:
            self.label.set_text('Slider %s changed to %f' %
                                (ev.source.id, ev.new_value))


if __name__ == '__main__':
    m = flx.launch(DeepEventConnections)
    flx.run()