Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@event.reaction('buttons.children*.pointer_down')
def run_test(self, *events):
global window, perf_counter
self.status.set_text('Test results: ')
self.progress.set_value(0)
tests = []
for ev in events:
if isinstance(ev.source, ui.Button):
sze = 5 if '5' in ev.source.text else 1
n = int(ev.source.text.split(' ')[0])
for i in range(n):
tests.append(sze)
self.progress.set_max(len(tests))
self._start_time = perf_counter()
for n in tests:
@event.reaction('disabled')
def __disabled_changed(self, *events):
if events[-1].new_value:
self.node.setAttribute("disabled", "disabled")
else:
self.node.removeAttribute("disabled")
@event.reaction('key_down')
def __on_key(self, *events):
for ev in events:
value = self.value
if ev.key == 'Escape':
self.outernode.blur()
self.user_done()
elif ev.key == 'ArrowRight':
if isinstance(value, float):
self.user_value(value + self.step)
else:
self.user_value([v + self.step for v in value])
elif ev.key == 'ArrowLeft':
if isinstance(value, float):
self.user_value(value - self.step)
else:
self.user_value([v - self.step for v in value])
@event.reaction('!bar')
def on_bar(self, *events):
print('bar reaction called with %i events' % len(events))
@event.reaction
def _update_minmaxsize(self):
""" Update the internal _size_limits.
Note that this is an implicit reaction.
"""
# Get new limits
w1, w2, h1, h2 = self._query_min_max_size()
w1 = max(0, w1)
h1 = max(0, h1)
# Update the property, so that our parent may react
self._set_size_limits((w1, w2, h1, h2))
# Update the style, so that flexbox works
s = self.outernode.style
s['min-width'] = w1 + 'px'
s['max-width'] = w2 + 'px'
s['min-height'] = h1 + 'px'
s['max-height'] = h2 + 'px'
@event.reaction('!eat')
def track_eating(self, *events):
for ev in events:
print(ev.name + ' is eating')
@event.reaction('!children**.pointer_click', '!children**.pointer_double_click')
def _handle_item_clicked(self, *events):
self._last_highlighted_hint = events[-1].source.id
if self._highlight_on: # highhlight tracks clicks
self.highlight_show_item(events[-1].source)
if self.max_selected == 0:
# No selection allowed
pass
elif self.max_selected < 0:
# Select/deselect any, but only with CTRL and SHIFT
for ev in events:
item = ev.source
modifiers = ev.modifiers if ev.modifiers else []
if 'Shift' in modifiers: # Ctrl can also be in modifiers
# Select everything between last selected and current
@event.reaction
def __update_tabindex(self, *events):
# Note that this also makes the widget able to get focus, and thus
# able to do key events.
ti = self.tabindex
if ti < -1:
self.node.removeAttribute('tabIndex')
else:
self.node.tabIndex = ti
@event.reaction('foo')
def react_to_foo_b(self, *events):
# This function
print('B: foo changed from %i to %i' % (events[0].old_value,
events[-1].new_value))