How to use the flexx.event function in flexx

To help you get started, we’ve selected a few flexx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flexxui / flexx / flexx / event / examples / greeter1.py View on Github external
    @event.emitter
    def eat(self):
        #self.emit('eat', {'name': self.first_name})
        return {'name': self.first_name}
github flexxui / flexx / flexx / ui / widgets / _tree.py View on Github external
def init(self):

            with ui.TreeWidget(max_selected=2):

                for t in ['foo', 'bar', 'spam', 'eggs']:
                    ui.TreeItem(text=t, checked=True)

Also see examples: :ref:`tree.py`, :ref:`control_with_keys.py`.

"""

from ... import event
from .._widget import Widget, create_element

loop = event.loop


# todo: icons
# todo: tooltips
# todo: a variant that can load data dynamically from Python, for biggish data


class TreeWidget(Widget):
    """
    A Widget that can be used to structure information in a list or a tree.
    It's items are represented by its children, which may only be TreeItem
    objects. Sub items can be created by instantiating TreeItems in the context
    of another TreeItem.

    When the items in the tree have no sub-items themselves, the TreeWidget is
    in "list mode". Otherwise, items can be collapsed/expanded etc.
github flexxui / flexx / flexx / event / tmp.py View on Github external
    @event.readonly
    def bar(self, v=42):
        return float(v)
github flexxui / flexx / flexx / event / examples / properties_demo.py View on Github external
"""
Small example to demonstrate properties:
"""

from flexx import event


class Example(event.Component):
    
    foo = event.AnyProp(settable=True, doc='This can be anything.')
    bar = event.IntProp(10, doc='This is an int.')
    eggs = event.TupleProp(settable=True)
    
    @event.action
    def raise_the_bar(self):
        """ Action to change the value of bar. """
        self._mutate_bar(self.bar + 1)

    @event.reaction
    def _report(self):
        # This gets automatically called when any of the used properties change
        print('foo is', self.foo)
        print('bar is', self.bar)
        print('eggs is', self.eggs)
github flexxui / flexx / flexx / ui / widgets / _dropdown.py View on Github external
selected_key = event.StringProp('', settable=True, doc="""
        The currently selected item key. Can be '' if no item has
        been selected or when the text was changed manually (if editable).
        Can also be programatically set.
        """)

    placeholder_text = event.StringProp('', settable=True, doc="""
        The placeholder text to display in editable mode.
        """)

    editable = event.BoolProp(False, settable=True, doc="""
        Whether the combobox's text is editable.
        """)

    options = event.TupleProp((), settable=True, doc="""
        A list of tuples (key, text) representing the options. Both
        keys and texts are converted to strings if they are not already.
        For items that are given as a string, the key and text are the same.
        If a dict is given, it is transformed to key-text pairs.
        """)

    _highlighted = app.LocalProperty(-1, settable=True, doc="""
        The index of the currently highlighted item.
        """)

    @event.action
    def set_options(self, options):
        # If dict ...
        if isinstance(options, dict):
            keys = options.keys()
            keys = sorted(keys)  # Sort dict by key
github flexxui / flexx / flexx / ui / widgets / _button.py View on Github external
}

    .flx-RadioButton > input, .flx-CheckBox > input{
        margin-left: 0.3em;
        margin-right: 0.3em;
    }

    .flx-RadioButton > input, .flx-CheckBox > input {
        color: #333;
    }
    .flx-RadioButton:hover > input, .flx-CheckBox:hover > input {
        color: #036;
    }
    """

    text = event.StringProp('', settable=True, doc="""
        The text on the button.
        """)

    checked = event.BoolProp(False, settable=True, doc="""
        Whether the button is checked.
        """)

    disabled = event.BoolProp(False, settable=True, doc="""
        Whether the button is disabled.
        """)

    @event.reaction('pointer_click')
    def __on_pointer_click(self, e):
        self.node.blur()

    @event.emitter
github flexxui / flexx / flexx / app / examples / init_order2.py View on Github external
        @event.connect('bar')
        def on_bar(self, *events):
            for ev in events:
                print('JS %s: handling %s event' % (self.id, ev.type),
                      self.bar + self.eggs)
github flexxui / flexx / flexx / ui / layouts / _split.py View on Github external
        @event.prop
        def spacing(self, v=5):
            """ The space between two child elements (in pixels)"""
            return float(v)
github flexxui / flexx / flexx / app / examples / react_to_props_js.py View on Github external
    @event.connect('foo')
    def react_to_bar_b(self, *events):
        print('B: foo changed from %s to %s' % (events[0].old_value, 
                                                events[-1].new_value))
github flexxui / flexx / flexx / event / examples / greeter2.py View on Github external
for ev in events:
        p = ev.source
        print('Hi explicit1 %s %s' % (p.first_name, p.last_name))


def greet_explicit2(*events):
    for ev in events:
        p = ev.source
        print('Hi explicit2 %s %s' % (p.first_name, p.last_name))
p1.reaction(greet_explicit2, 'first_name', 'last_name')


p1.set_first_name('Jane')
p1.set_last_name('Jansen')

event.loop.iter()