from functools import partial
from pywebio import start_server, config
from pywebio.input import *
from pywebio.output import *
from pywebio.pin import *
from pywebio.session import *
def pin_widgets():
put_markdown("# Pin widget")
options = [
{
"label": "Option one",
"value": 1,
"selected": True,
},
{
"label": "Option two",
"value": 2,
},
{
"label": "Disabled option",
"value": 3,
"disabled": True
}
]
put_input('input', label='Text input', placeholder="Enter email",
help_text="We'll never share your email with anyone else.")
put_input('valid_input', label="Valid input", value="correct value")
put_input('invalid_input', label="Invalid input", value="wrong value")
put_textarea('textarea', label='Textarea', rows=3, maxlength=10, minlength=20, value=None,
placeholder='This is placeholder message', readonly=False)
put_textarea('code', label='Code area', rows=4, code={'mode': 'python'},
value='import pywebio\npywebio.output.put_text("hello world")')
put_select('select', options=options, label='Select')
put_select('select_multiple', options=options, label='Multiple select', multiple=True, value=None)
put_checkbox('checkbox', options=options, label='Checkbox', inline=False, value=None)
put_checkbox('checkbox_inline', options=options, label='Inline checkbox', inline=True, value=None)
put_radio('radio', options=options, label='Radio', inline=False, value=None)
put_radio('radio_inline', options=options, label='Inline radio', inline=True, value='B')
put_slider('slider', label='Slider')
put_actions('actions', buttons=[
{'label': 'Submit', 'value': '1'},
{'label': 'Warning', 'value': '2', 'color': 'warning'},
{'label': 'Danger', 'value': '3', 'color': 'danger'},
], label='Actions')
pin_update('valid_input', valid_status=True, valid_feedback="Success! You've done it.")
pin_update('invalid_input', valid_status=False, invalid_feedback="Sorry, that username's taken. Try another?")
def form():
options = [
{
"label": "Option one",
"value": 1,
"selected": True,
},
{
"label": "Option two",
"value": 2,
},
{
"label": "Disabled option",
"value": 3,
"disabled": True
}
]
input_group('Input group', [
input('Text', type=TEXT, datalist=['candidate-%s' % i for i in range(10)], name='text', required=True,
help_text='Required'),
input('Number', type=NUMBER, value="42", name='number'),
input('Float', type=FLOAT, name='float'),
input('Password', type=PASSWORD, name='password'),
textarea('Textarea', rows=3, maxlength=20, name='textarea',
placeholder="The maximum number of characters you can input is 20"),
textarea('Code', name='code', code={'mode': 'python'},
value='import pywebio\npywebio.output.put_text("hello world")'),
select('Multiple select', options, name='select-multiple', multiple=True),
select('Select', options, name='select'),
checkbox('Inline checkbox', options, inline=True, name='checkbox-inline'),
checkbox('Checkbox', options, name='checkbox'),
radio('Inline radio', options, inline=True, name='radio-inline'),
radio('Radio', options, inline=False, name='radio'),
file_upload('File upload', name='file_upload', max_size='10m'),
actions('Actions', [
{'label': 'Submit', 'value': 'submit'},
{'label': 'Disabled', 'disabled': True},
{'label': 'Reset', 'type': 'reset', 'color': 'warning'},
{'label': 'Cancel', 'type': 'cancel', 'color': 'danger'},
], name='actions'),
])
def output_widgets():
###########################################################################################
put_markdown("# Typography")
put_row([
put_markdown("""
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
[PyWebIO](https://github.com/pywebio/PyWebIO) is awesome!
*This text will be italic*
**This text will be bold**
_You **can** combine them_
~~Strikethrough~~
This is `inline code`
As Kanye West said:
> We're living the future so
> the present is our past.
"""),
put_markdown("""
### Lists
* Item 1
* Item 2
* Item 2a
* Item 2b
1. Item 1
1. Item 2
1. Item 2a
1. Item 2b
### Task Lists
- [x] [links](), **formatting**, and tags supported
- [x] list syntax required (any unordered or ordered list supported)
- [x] this is a complete item
- [ ] this is an incomplete item
""")
])
###########################################################################################
put_markdown("""
# Code
```python
from pywebio import *
def main(): # PyWebIO application function
name = input.input("what's your name")
output.put_text("hello", name)
start_server(main, port=8080, debug=True)
```
""")
###########################################################################################
put_markdown('# Image')
with use_scope('image'):
put_image(
"https://opengraph.githubassets.com/6bcea5272d0b5901f48a67d9d05da6c7a7c7c68da32a5327943070ff9c9a3dfb/pywebio/PyWebIO").style("""
max-height: 250px;
border: 2px solid #fff;
border-radius: 25px;
""")
###########################################################################################
put_markdown("# Buttons")
# small=None, link_style=False, outline=False, group=False
put_buttons([
dict(label=i, value=i, color=i)
for i in ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark']
], onclick=lambda b: toast(f'Clicked {b} button'))
put_buttons([
dict(label=i, value=i, color=i)
for i in ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark']
], onclick=lambda b: toast(f'Clicked {b} button'), small=True)
put_buttons([
dict(label=i, value=i, color=i)
for i in ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark']
], onclick=lambda b: toast(f'Clicked {b} button'), link_style=True)
put_buttons([
dict(label=i, value=i, color=i)
for i in ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark']
], onclick=lambda b: toast(f'Clicked {b} button'), outline=True)
put_buttons([
dict(label=i, value=i, color=i)
for i in ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark']
], onclick=lambda b: toast(f'Clicked {b} button'), group=True)
###########################################################################################
put_markdown('# Tables')
put_markdown("""
First Header | Second Header
------------ | -------------
Content from cell 1 | Content from cell 2
Content in the first column | Content in the second column
""")
put_table([
['Type', 'Content'],
['text', '
{THEME_SUMMARY.get(theme, '')}