MCPcopy Create free account
hub / github.com/pywebio/PyWebIO / pin_wait_change

Function pin_wait_change

pywebio/pin.py:326–365  ·  view source on GitHub ↗

``pin_wait_change()`` listens to a list of pin widgets, when the value of any widgets changes, the function returns with the name and value of the changed widget. :param str names: List of names of pin widget :param int/None timeout: If ``timeout`` is a positive number, ``pin_wait_chang

(*names, timeout: Optional[int] = None)

Source from the content-addressed store, hash-verified

324
325
326def pin_wait_change(*names, timeout: Optional[int] = None):
327 """``pin_wait_change()`` listens to a list of pin widgets, when the value of any widgets changes,
328 the function returns with the name and value of the changed widget.
329
330 :param str names: List of names of pin widget
331 :param int/None timeout: If ``timeout`` is a positive number, ``pin_wait_change()`` blocks at most ``timeout`` seconds
332 and returns ``None`` if no changes to the widgets within that time. Set to ``None`` (the default) to disable timeout.
333 :return dict/None: ``{"name": name of the changed widget, "value": current value of the changed widget }`` ,
334 when a timeout occurs, return ``None``.
335
336 Example:
337
338 .. exportable-codeblock::
339 :name: pin_wait_change
340 :summary: `pin_wait_change()` example
341
342 put_input('a', type='number', value=0)
343 put_input('b', type='number', value=0)
344
345 while True:
346 changed = pin_wait_change('a', 'b')
347 with use_scope('res', clear=True):
348 put_code(changed)
349 put_text("a + b = %s" % (pin.a + pin.b))
350
351 :demo_host:`Here </markdown_previewer>` is an demo of using `pin_wait_change()` to make a markdown previewer.
352
353 Note that: updating value with the :data:`pin` object or `pin_update()`
354 does not trigger `pin_wait_change()` to return.
355
356 When using :ref:`coroutine-based session <coroutine_based_session>`,
357 you need to use the ``await pin_wait_change()`` syntax to invoke this function.
358 """
359 assert len(names) >= 1, "`names` can't be empty."
360 if len(names) == 1 and isinstance(names[0], (list, tuple)):
361 names = names[0]
362
363 send_msg('pin_wait', spec=dict(names=names, timeout=timeout))
364
365 return get_client_val()
366
367
368def pin_update(name: str, **spec):

Callers 2

targetFunction · 0.85
mainFunction · 0.85

Calls 2

send_msgFunction · 0.85
get_client_valFunction · 0.85

Tested by 1

targetFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…