Addition to callbacks & custom UIs - Python
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.2k
- Forks
- 242
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
https://polyscope.run/py/features/callbacks_and_UIs/#creating-custom-uis
#If we want to use local variables & assign to them in the UI code below,
# we need to mark them as nonlocal. This is because of how Python scoping
# rules work, not anything particular about Polyscope or ImGui.
# Of course, you can also use any other kind of python variable as a controllable
# value in the UI, such as a value from a dictionary, or a class member. Just be
# sure to assign the result of the ImGui call to the value, as in the examples below.
#
# If these variables are defined at the top level of a Python script file (i.e., not
# inside any method), you will need to use the `global` keyword instead of nonlocal`.
If you want to avoid using declarations global or nonlocal,
you can also use different module to store these values and call it on main module as below
variables.py
is_true: bool = False
main.py
import variables as vr
def callback()
change, vr.is_true = psim.Checkbox("Selection box", vr.is_true)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked callbacks and custom UIs documentation page and inspect the surrounding examples. Add the shown Python module-based approach for storing UI-controlled values alongside the existing global and nonlocal guidance, using variables.py and main.py as the example. Done means the page explains this alternative clearly and the example is consistent with the callback API.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100