From 63919c0db288cfd99110c1576b3a3524077ba93e Mon Sep 17 00:00:00 2001 From: Brent Yi Date: Tue, 18 Apr 2023 19:15:29 -0700 Subject: [PATCH] Docs fixes for viewer elements (#1770) --- docs/developer_guides/viewer/custom_gui.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/docs/developer_guides/viewer/custom_gui.md b/docs/developer_guides/viewer/custom_gui.md index 09275dac1..e11381d02 100644 --- a/docs/developer_guides/viewer/custom_gui.md +++ b/docs/developer_guides/viewer/custom_gui.md @@ -33,16 +33,15 @@ current_value = self.custom_value.value **Callbacks** You can register a callback that will be called whenever a new value for your GUI element is available. For example, one can use a callback to update config parameters when elements are changed: ```python -def on_change_callback(handle: GuiHandle): - self.config.example_parameter = handle.get_value() +def on_change_callback(handle: ViewerCheckbox) -> None: + self.config.example_parameter = handle.value self.custom_checkbox = ViewerCheckbox( name="Checkbox", - default_value = False, - cb_hook = on_change_callback + default_value=False, + cb_hook=on_change_callback, ) ``` -The GuiHandle value is a viser object which you can use to get the new value. **Thread safety** Note that `ViewerElement` values can change asynchronously to model execution. So, it's best practice to store the value of a viewer element once at the beginning @@ -63,13 +62,13 @@ class MyModel(Model): You can write to a viewer element in Python, which provides a convenient way to track values in your code without the need for wandb/tensorboard or relying on `print` statements. ```python -self.custom_value = x +self.custom_value.value = x ``` :::{admonition} Warning :class: warning -Note that updating module state while training can have unexpected side effects. It is up to the user to ensure that GUI actions are safe. In most cases, we recommend wrapping GUI related logic in `if self.training:` to ensure that the effects are only applied during inference. +Updating module state while training can have unexpected side effects. It is up to the user to ensure that GUI actions are safe. Conditioning on `self.training` can help determine whether effects are applied during forward passes for training or rendering. ::: ## Example Elements