-
I am looking for a workaround to make a button trigger the pin_wait_change() call to return. The desired functionality can be obtained with a checkbox: from pywebio.output import *
from pywebio.pin import *
def button_callback(val):
# trigger a change event here to exit the pin_wait_change call
pass
put_markdown("# Test case")
put_row([
put_column([
put_select('select1', label='Choose:', options=['option1','option2']),
None,
put_input('input1', label='Write some text:'),
]),
None,
None,
put_column([
put_markdown('Show some **random** text *here*\nMore text...\nAnd some concluding remarks.'),
]),
])
put_row([
put_checkbox('checkbox', options=['check to proceed']),
#put_buttons(['proceed'], onclick=button_callback)
])
loop_flag = True
while loop_flag:
result = pin_wait_change(['checkbox'])
if result['name'] == 'checkbox':
loop_flag = False
put_markdown('We have left the `while` loop') Button clicks apparently do not trigger a change. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
If you just want to add a button to submit the form of pin widgets, you don't need the from pywebio.output import *
from pywebio.session import *
from pywebio.pin import *
def main():
put_markdown("# Test case")
put_row([
put_column([
put_select('select1', label='Choose:', options=['option1', 'option2']),
None,
put_input('input1', label='Write some text:'),
]),
None,
None,
put_column([
put_markdown('Show some **random** text *here*\nMore text...\nAnd some concluding remarks.'),
]),
])
def submit():
put_markdown('`select1` = `%s`' % pin.select1)
put_markdown('`input1` = `%s`' % pin.input1)
put_buttons(['check to proceed'], onclick=[submit])
hold()
pywebio.start_server(main, port=8080) |
Beta Was this translation helpful? Give feedback.
-
If you need a way to exit the from pywebio.output import *
from pywebio.session import *
from pywebio.pin import *
import threading
from queue import Queue
import pywebio
class PinChangeQueue:
def __init__(self, names, maxsize=10):
self.names = names
self.mq = Queue(maxsize=maxsize)
self.stopped = False
def start(self):
def mq_append():
while not self.stopped:
change = pin_wait_change(self.names)
self.mq.put(change)
t = threading.Thread(target=mq_append)
register_thread(t)
t.start()
def get(self):
if self.stopped:
raise RuntimeError("The queue is closed")
return self.mq.get()
def stop(self):
self.mq.put(None)
self.stopped = True
def main():
put_markdown("# Test case")
put_row([
put_column([
put_select('select1', label='Choose:', options=['option1', 'option2']),
None,
put_input('input1', label='Write some text:'),
]),
None,
None,
put_column([
put_markdown('Show some **random** text *here*\nMore text...\nAnd some concluding remarks.'),
]),
])
mq = PinChangeQueue(['select1', 'input1'])
put_buttons(['Stop watching'], onclick=[mq.stop])
mq.start()
while not mq.stopped:
changed_info = mq.get()
put_code(str(changed_info))
put_text('Stop watching Pin widgets')
pywebio.start_server(main, port=8080) |
Beta Was this translation helpful? Give feedback.
-
Update: in the latest version (v1.4) of pywebio, you can use |
Beta Was this translation helpful? Give feedback.
Update: in the latest version (v1.4) of pywebio, you can use
pin.put_actions()
to exit thepin_wait_change
call