Skip to content

Commit 0c84866

Browse files
authored
fix(widgets): Add Simput.register_layout() (#15)
* fix(widgets): Add Simput.register_layout() * docs(widgets): Add basic documentation for Simput widgets
1 parent a46d636 commit 0c84866

File tree

8 files changed

+84
-9
lines changed

8 files changed

+84
-9
lines changed

docs/api.md

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ widget or get your hand on its **proxymanager** to manage its proxies.
1212

1313
## Simput manager
1414

15-
The simput manager instance let you do the following:
15+
The simput manager instance lets you do the following:
1616
- Access its linked **proxymanager**
1717
- Reset cached UI layout elements by calling **clear_ui()**
1818
- Load definitions, language and UI by calling one of the following methods
@@ -298,6 +298,72 @@ def hints(self):
298298
"""Return a set of (level, message) when running the validation for the info level"""
299299
```
300300

301+
## UI Widgets
302+
303+
### Simput Widget
304+
305+
The `Simput` widget is a trame component that is used as the UI data management provider.
306+
This component must be registered as the root of the layout with the `register_layout(layout)` method (preferred method) or by setting `layout.root = simput_widget`.
307+
308+
```python
309+
@property
310+
def helper(self):
311+
"""Simput helper object"""
312+
313+
def apply(self, **kwargs):
314+
"""Flush modified properties so they can be pushed to their concrete objects"""
315+
316+
def reset(self, **kwargs):
317+
"""Unapply properties"""
318+
319+
def push(self, id=None, type=None, domains=None, proxy=None, **kwargs):
320+
"""Ask server to push data, ui, or constraints"""
321+
322+
def update(self, change_set, **kwargs):
323+
"""
324+
List of properties and value to update
325+
326+
>>> change_set = [
327+
... {"id":"12", "name":"Radius", "value": 0.75},
328+
... {"id": "12", "name":"Resolution", "value": 24}
329+
... ]
330+
"""
331+
332+
def register_layout(self, layout):
333+
"""
334+
Register self to the root of the layout and
335+
clear any previously registered elements (to support hot reloading)
336+
"""
337+
338+
def refresh(self, id=0, property="", **kwargs):
339+
"""Refresh the given id's property"""
340+
341+
def reload(self, name):
342+
"""Reload the given name (data, ui, domain)"""
343+
344+
@property
345+
def changeset(self):
346+
"""All unapplied changesets"""
347+
348+
@property
349+
def has_changes(self):
350+
"""Does the changeset have content?"""
351+
352+
@property
353+
def auto_update(self):
354+
"""Whether to automatically apply changes"""
355+
```
356+
357+
### SimputItem Widget
358+
359+
`SimputItem` is a trame component that is used to display a Simput item. This must be child of a Simput component to have access to Simput data.
360+
361+
```python
362+
item_proxy = pxm.create("Item")
363+
# Create a SimputItem widget to display the item
364+
simput.SimputItem(item_id=f"{item_proxy.id}")
365+
```
366+
301367
## Domains
302368

303369
### Range

examples/00_AddressBook/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def entry_ids(self):
100100

101101
with SinglePageWithDrawerLayout(server) as layout:
102102
layout.title.set_text("SimPut Address Book")
103-
layout.root = simput_widget
103+
simput_widget.register_layout(layout)
104104

105105
with layout.toolbar:
106106
vuetify.VSpacer()

examples/01_Widgets/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def update_ui(use_xml_ui, **kwargs):
5858
# -----------------------------------------------------------------------------
5959

6060
with SinglePageLayout(server) as layout:
61-
layout.root = simput_widget
61+
simput_widget.register_layout(layout)
6262

6363
with layout.toolbar as toolbar:
6464
layout.title.set_text("SimPut Widgets")

examples/02_Hints/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
# -----------------------------------------------------------------------------
4646

4747
with SinglePageLayout(server) as layout:
48-
layout.root = simput_widget
48+
simput_widget.register_layout(layout)
4949

5050
with layout.toolbar as toolbar:
5151
layout.title.set_text("SimPut Widgets")

examples/03_VTK/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def import_file(import_file, **kwargs):
120120
]
121121

122122
with SinglePageWithDrawerLayout(server) as layout:
123-
layout.root = simput_widget
123+
simput_widget.register_layout(layout)
124124

125125
with layout.drawer as drawer:
126126
with vuetify.VTabs(

examples/04_DynaDomain/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def update_advanced(ui_advanced, **kwargs):
7272
ctrl.simput_apply = simput_widget.apply
7373
ctrl.simput_reset = simput_widget.reset
7474
ctrl.simput_reload_domain = simput_widget.reload_domain
75-
layout.root = simput_widget
75+
simput_widget.register_layout(layout)
7676

7777
with layout.toolbar as toolbar:
7878
layout.title.set_text("SimPut Advanced view")

examples/05_ReadonlyDisabled/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# -----------------------------------------------------------------------------
2424

2525
with SinglePageLayout(server) as layout:
26-
layout.root = simput_widget
26+
simput_widget.register_layout(layout)
2727

2828
with layout.toolbar as toolbar:
2929
layout.title.set_text("Simput readonly and disabled example")

trame_simput/widgets/simput.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, _elem_name, children=None, **kwargs):
1212

1313
class Simput(HtmlElement):
1414
"""
15-
Simput data management component. This must be set as the root of a layout to provide children with Simput data.
15+
Simput data management component. This must be registered as the root of a layout to provide children with Simput data.
1616
1717
:param ui_manager: See simput docs |simput_link| for more info
1818
:param domains_manager: See simput docs |simput_link| for more info
@@ -23,7 +23,8 @@ class Simput(HtmlElement):
2323
:param children: The children nested within this element
2424
:type children: str | list[trame.html.*] | trame.html.* | None
2525
26-
>>> layout.root = simput.Simput(ui_manager, prefix="myForm")
26+
>>> simput_widget = simput.Simput(ui_manager, prefix="myForm")
27+
>>> simput_widget.register_layout(layout)
2728
"""
2829

2930
def __init__(self, ui_manager, prefix=None, children=None, **kwargs):
@@ -77,6 +78,14 @@ def update(self, change_set, **kwargs):
7778
"""
7879
self._helper.update(change_set)
7980

81+
def register_layout(self, layout):
82+
"""
83+
Register self to the root of the layout and
84+
clear any previously registered elements (to support hot reloading)
85+
"""
86+
self.clear()
87+
layout.root = self
88+
8089
def refresh(self, id=0, property="", **kwargs):
8190
self._helper.refresh(id, property)
8291

0 commit comments

Comments
 (0)