Skip to content

Commit 73313cf

Browse files
committed
chore: Rename all occurences of handle_on, rework app templates. #1484
1 parent edf5070 commit 73313cf

File tree

16 files changed

+380
-396
lines changed

16 files changed

+380
-396
lines changed

py/examples/hash_routing_parameters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Use the browser's [location hash](https://developer.mozilla.org/en-US/docs/Web/API/Location/hash)
33
# for #routing using URLs, with parameters.
44
# ---
5-
from h2o_wave import main, app, Q, ui, on, handle_on
5+
from h2o_wave import main, app, Q, ui, on, run_on
66

77
air_passengers_fields = ['Year', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
88
air_passengers_rows = [
@@ -62,6 +62,6 @@ async def serve(q: Q):
6262
content='Click on a cell in the table above!',
6363
)
6464

65-
await handle_on(q)
65+
await run_on(q)
6666

6767
await q.page.save()

py/examples/plot_events_routing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Plot / Events / Routing
22
# Handle #events on a #plot card using routing.
33
# ---
4-
from h2o_wave import main, app, on, handle_on, Q, ui, data
4+
from h2o_wave import main, app, on, run_on, Q, ui, data
55

66

77
@on('pricing.select_marks')
@@ -32,4 +32,4 @@ async def serve(q: Q):
3232
)
3333
await q.page.save()
3434
else:
35-
await handle_on(q)
35+
await run_on(q)

py/examples/routing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Routing
2-
# Use `on` and `handle_on` to simplify query handling by #routing queries to designated functions.
2+
# Use `on` and `run_on` to simplify query handling by #routing queries to designated functions.
33
# ---
4-
from h2o_wave import main, app, Q, ui, on, handle_on
4+
from h2o_wave import main, app, Q, ui, on, run_on
55

66

77
# This function is called when q.args['empty_cart'] is True.
@@ -60,4 +60,4 @@ async def serve(q: Q):
6060
],
6161
)
6262
await q.page.save()
63-
await handle_on(q)
63+
await run_on(q)

py/examples/routing_predicates.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Routing / Predicates
2-
# Use `on` and `handle_on` with predicates to handle routing with custom conditions.
2+
# Use `on` and `run_on` with predicates to handle routing with custom conditions.
33
# ---
4-
from h2o_wave import main, app, Q, ui, on, handle_on
4+
from h2o_wave import main, app, Q, ui, on, run_on
55

66

77
# This function is called when q.args['temperature'] < 15.
@@ -29,7 +29,7 @@ async def serve(q: Q):
2929
q.args.temperature = 20
3030
await show_slider(q, "")
3131
else:
32-
await handle_on(q)
32+
await run_on(q)
3333

3434

3535
async def show_slider(q: Q, message: str):

py/examples/tour.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from typing import Dict, List, Optional, Tuple
1515
from urllib.parse import urlparse
1616

17-
from h2o_wave import Q, app, handle_on, main, on, ui
17+
from h2o_wave import Q, app, run_on, main, on, ui
1818

1919
example_dir = os.path.dirname(os.path.realpath(__file__))
2020
tour_tmp_dir = os.path.join(example_dir, '_tour_apps_tmp')
@@ -415,7 +415,7 @@ async def serve(q: Q):
415415
q.client.path = uuid.uuid4()
416416
await setup_page(q)
417417

418-
await handle_on(q)
418+
await run_on(q)
419419

420420
search = q.args[q.args['#'] or default_example_name]
421421
if search and not q.events.editor:

py/h2o_lightwave/h2o_lightwave/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from .core import Ref, data, pack, Expando, expando_to_dict, clone_expando, copy_expando
2525
from .server import Q, wave_serve
26-
from .routing import on, handle_on
26+
from .routing import on, run_on, handle_on
2727
from .types import *
2828
from .version import __version__
2929

py/h2o_wave/h2o_wave/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
.. include:: ../../docs/index.md
3131
"""
3232
from .core import Site, AsyncSite, site, Page, Ref, data, pack, Expando, expando_to_dict, clone_expando, copy_expando
33-
from .server import listen, Q, app, main
33+
from .server import Q, app, main
3434
from .routing import on, handle_on, run_on
3535
from .db import connect, WaveDBConnection, WaveDB, WaveDBError
3636
from .types import *

py/h2o_wave/project_templates/header.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from h2o_wave import main, app, Q, ui, on, handle_on
1+
from h2o_wave import main, app, Q, ui, on, run_on
22

33

44
@app('/')
@@ -9,7 +9,7 @@ async def serve(q: Q):
99
q.client.initialized = True
1010

1111
# Other browser interactions
12-
await handle_on(q)
12+
await run_on(q)
1313
await q.page.save()
1414

1515

py/h2o_wave/project_templates/header_nav.py

+51-58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from h2o_wave import main, app, Q, ui, on, handle_on, data
1+
from h2o_wave import main, app, Q, ui, on, run_on, data
22
from typing import Optional, List
33

44

@@ -112,65 +112,58 @@ async def page3(q: Q):
112112

113113

114114
@on('#page4')
115-
async def handle_page4(q: Q):
115+
@on('page4_reset')
116+
async def page4(q: Q):
117+
q.page['sidebar'].value = '#page4'
116118
# When routing, drop all the cards except of the main ones (header, sidebar, meta).
117-
# Since this page is interactive, we want to update its card instead of recreating it every time, so ignore 'form' card on drop.
119+
# Since this page is interactive, we want to update its card
120+
# instead of recreating it every time, so ignore 'form' card on drop.
118121
clear_cards(q, ['form'])
119122

120-
if q.args.step1:
121-
# Just update the existing card, do not recreate.
122-
q.page['form'].items = [
123-
ui.stepper(name='stepper', items=[
124-
ui.step(label='Step 1'),
125-
ui.step(label='Step 2'),
126-
ui.step(label='Step 3'),
127-
]),
128-
ui.textbox(name='textbox2', label='Textbox 1'),
129-
ui.buttons(justify='end', items=[
130-
ui.button(name='step2', label='Next', primary=True),
131-
])
132-
]
133-
elif q.args.step2:
134-
# Just update the existing card, do not recreate.
135-
q.page['form'].items = [
136-
ui.stepper(name='stepper', items=[
137-
ui.step(label='Step 1', done=True),
138-
ui.step(label='Step 2'),
139-
ui.step(label='Step 3'),
140-
]),
141-
ui.textbox(name='textbox2', label='Textbox 2'),
142-
ui.buttons(justify='end', items=[
143-
ui.button(name='step1', label='Cancel'),
144-
ui.button(name='step3', label='Next', primary=True),
145-
])
146-
]
147-
elif q.args.step3:
148-
# Just update the existing card, do not recreate.
149-
q.page['form'].items = [
150-
ui.stepper(name='stepper', items=[
151-
ui.step(label='Step 1', done=True),
152-
ui.step(label='Step 2', done=True),
153-
ui.step(label='Step 3'),
154-
]),
155-
ui.textbox(name='textbox3', label='Textbox 3'),
156-
ui.buttons(justify='end', items=[
157-
ui.button(name='step2', label='Cancel'),
158-
ui.button(name='submit', label='Next', primary=True),
159-
])
160-
]
161-
else:
162-
# If first time on this page, create the card.
163-
add_card(q, 'form', ui.form_card(box='vertical', items=[
164-
ui.stepper(name='stepper', items=[
165-
ui.step(label='Step 1'),
166-
ui.step(label='Step 2'),
167-
ui.step(label='Step 3'),
168-
]),
169-
ui.textbox(name='textbox1', label='Textbox 1'),
170-
ui.buttons(justify='end', items=[
171-
ui.button(name='step2', label='Next', primary=True),
172-
]),
173-
]))
123+
# If first time on this page, create the card.
124+
add_card(q, 'form', ui.form_card(box='vertical', items=[
125+
ui.stepper(name='stepper', items=[
126+
ui.step(label='Step 1'),
127+
ui.step(label='Step 2'),
128+
ui.step(label='Step 3'),
129+
]),
130+
ui.textbox(name='textbox1', label='Textbox 1'),
131+
ui.buttons(justify='end', items=[
132+
ui.button(name='page4_step2', label='Next', primary=True),
133+
]),
134+
]))
135+
136+
137+
@on()
138+
async def page4_step2(q: Q):
139+
# Just update the existing card, do not recreate.
140+
q.page['form'].items = [
141+
ui.stepper(name='stepper', items=[
142+
ui.step(label='Step 1', done=True),
143+
ui.step(label='Step 2'),
144+
ui.step(label='Step 3'),
145+
]),
146+
ui.textbox(name='textbox2', label='Textbox 2'),
147+
ui.buttons(justify='end', items=[
148+
ui.button(name='page4_step3', label='Next', primary=True),
149+
])
150+
]
151+
152+
153+
@on()
154+
async def page4_step3(q: Q):
155+
# Just update the existing card, do not recreate.
156+
q.page['form'].items = [
157+
ui.stepper(name='stepper', items=[
158+
ui.step(label='Step 1', done=True),
159+
ui.step(label='Step 2', done=True),
160+
ui.step(label='Step 3'),
161+
]),
162+
ui.textbox(name='textbox3', label='Textbox 3'),
163+
ui.buttons(justify='end', items=[
164+
ui.button(name='page4_reset', label='Finish', primary=True),
165+
])
166+
]
174167

175168

176169
async def init(q: Q) -> None:
@@ -213,6 +206,6 @@ async def serve(q: Q):
213206
q.client.initialized = True
214207

215208
# Handle routing.
216-
await handle_on(q)
209+
await run_on(q)
217210
await q.page.save()
218211

py/h2o_wave/project_templates/header_sidebar_nav.py

+50-58
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from h2o_wave import main, app, Q, ui, on, handle_on, data
2+
from h2o_wave import main, app, Q, ui, on, run_on, data
33
from typing import Optional, List
44

55

@@ -117,66 +117,58 @@ async def page3(q: Q):
117117

118118

119119
@on('#page4')
120-
async def handle_page4(q: Q):
120+
@on('page4_reset')
121+
async def page4(q: Q):
121122
q.page['sidebar'].value = '#page4'
122123
# When routing, drop all the cards except of the main ones (header, sidebar, meta).
123-
# Since this page is interactive, we want to update its card instead of recreating it every time, so ignore 'form' card on drop.
124+
# Since this page is interactive, we want to update its card
125+
# instead of recreating it every time, so ignore 'form' card on drop.
124126
clear_cards(q, ['form'])
125127

126-
if q.args.step1:
127-
# Just update the existing card, do not recreate.
128-
q.page['form'].items = [
129-
ui.stepper(name='stepper', items=[
130-
ui.step(label='Step 1'),
131-
ui.step(label='Step 2'),
132-
ui.step(label='Step 3'),
133-
]),
134-
ui.textbox(name='textbox2', label='Textbox 1'),
135-
ui.buttons(justify='end', items=[
136-
ui.button(name='step2', label='Next', primary=True),
137-
])
138-
]
139-
elif q.args.step2:
140-
# Just update the existing card, do not recreate.
141-
q.page['form'].items = [
142-
ui.stepper(name='stepper', items=[
143-
ui.step(label='Step 1', done=True),
144-
ui.step(label='Step 2'),
145-
ui.step(label='Step 3'),
146-
]),
147-
ui.textbox(name='textbox2', label='Textbox 2'),
148-
ui.buttons(justify='end', items=[
149-
ui.button(name='step1', label='Cancel'),
150-
ui.button(name='step3', label='Next', primary=True),
151-
])
152-
]
153-
elif q.args.step3:
154-
# Just update the existing card, do not recreate.
155-
q.page['form'].items = [
156-
ui.stepper(name='stepper', items=[
157-
ui.step(label='Step 1', done=True),
158-
ui.step(label='Step 2', done=True),
159-
ui.step(label='Step 3'),
160-
]),
161-
ui.textbox(name='textbox3', label='Textbox 3'),
162-
ui.buttons(justify='end', items=[
163-
ui.button(name='step2', label='Cancel'),
164-
ui.button(name='submit', label='Next', primary=True),
165-
])
166-
]
167-
else:
168-
# If first time on this page, create the card.
169-
add_card(q, 'form', ui.form_card(box='vertical', items=[
170-
ui.stepper(name='stepper', items=[
171-
ui.step(label='Step 1'),
172-
ui.step(label='Step 2'),
173-
ui.step(label='Step 3'),
174-
]),
175-
ui.textbox(name='textbox1', label='Textbox 1'),
176-
ui.buttons(justify='end', items=[
177-
ui.button(name='step2', label='Next', primary=True),
178-
]),
179-
]))
128+
# If first time on this page, create the card.
129+
add_card(q, 'form', ui.form_card(box='vertical', items=[
130+
ui.stepper(name='stepper', items=[
131+
ui.step(label='Step 1'),
132+
ui.step(label='Step 2'),
133+
ui.step(label='Step 3'),
134+
]),
135+
ui.textbox(name='textbox1', label='Textbox 1'),
136+
ui.buttons(justify='end', items=[
137+
ui.button(name='page4_step2', label='Next', primary=True),
138+
]),
139+
]))
140+
141+
142+
@on()
143+
async def page4_step2(q: Q):
144+
# Just update the existing card, do not recreate.
145+
q.page['form'].items = [
146+
ui.stepper(name='stepper', items=[
147+
ui.step(label='Step 1', done=True),
148+
ui.step(label='Step 2'),
149+
ui.step(label='Step 3'),
150+
]),
151+
ui.textbox(name='textbox2', label='Textbox 2'),
152+
ui.buttons(justify='end', items=[
153+
ui.button(name='page4_step3', label='Next', primary=True),
154+
])
155+
]
156+
157+
158+
@on()
159+
async def page4_step3(q: Q):
160+
# Just update the existing card, do not recreate.
161+
q.page['form'].items = [
162+
ui.stepper(name='stepper', items=[
163+
ui.step(label='Step 1', done=True),
164+
ui.step(label='Step 2', done=True),
165+
ui.step(label='Step 3'),
166+
]),
167+
ui.textbox(name='textbox3', label='Textbox 3'),
168+
ui.buttons(justify='end', items=[
169+
ui.button(name='page4_reset', label='Finish', primary=True),
170+
])
171+
]
180172

181173

182174
async def init(q: Q) -> None:
@@ -227,6 +219,6 @@ async def serve(q: Q):
227219
q.client.initialized = True
228220

229221
# Handle routing.
230-
await handle_on(q)
222+
await run_on(q)
231223
await q.page.save()
232224

0 commit comments

Comments
 (0)