Skip to content

Commit

Permalink
Notifications (#225)
Browse files Browse the repository at this point in the history
* initial commit (wip)

* wip

* add NotificationMessage

* update notification example

* notification changes

* add ability to clear notifications

* add notification handle

* ruff

* changes

* nits

* add different notif types

* clear individual notif func

* notif update func

* ruff

* clean

* notification api changes

* nits

* format

* wip setter/getter

* better update wip

* better update notif api

* examples changes for per-client notification api

* change to client side api

* ruff format

* ruff pls

* fixes to client api

* fixes for post_init and remove notifs

* Bump ruff

* Remove some unused fields, bump notification limit

* Minor refactor, add handle to docs

* ruff

* minor cleanup 🙂

* Add `color` field

* pyright

---------

Co-authored-by: Brent Yi <[email protected]>
  • Loading branch information
ginazhouhuiwu and brentyi authored Aug 29, 2024
1 parent 0ba85db commit 2e09df7
Show file tree
Hide file tree
Showing 32 changed files with 399 additions and 24 deletions.
6 changes: 1 addition & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ repos:
- id: end-of-file-fixer
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.1
rev: v0.6.2
hooks:
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/psf/black
rev: "23.3.0"
hooks:
- id: black
5 changes: 5 additions & 0 deletions docs/source/client_handles.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
:undoc-members:
:inherited-members:

.. autoclass:: viser.NotificationHandle
:members:
:undoc-members:
:inherited-members:

<!-- prettier-ignore-end -->
1 change: 1 addition & 0 deletions examples/01_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import imageio.v3 as iio
import numpy as onp

import viser


Expand Down
1 change: 1 addition & 0 deletions examples/02_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time

import numpy as onp

import viser


Expand Down
3 changes: 2 additions & 1 deletion examples/03_gui_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import time

import numpy as onp
import viser
from typing_extensions import assert_never

import viser


def main() -> None:
server = viser.ViserServer()
Expand Down
1 change: 1 addition & 0 deletions examples/05_camera_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time

import numpy as onp

import viser
import viser.transforms as tf

Expand Down
1 change: 1 addition & 0 deletions examples/06_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import numpy as onp
import trimesh

import viser
import viser.transforms as tf

Expand Down
3 changes: 2 additions & 1 deletion examples/07_record3d_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import numpy as onp
import tyro
from tqdm.auto import tqdm

import viser
import viser.extras
import viser.transforms as tf
from tqdm.auto import tqdm


def main(
Expand Down
1 change: 1 addition & 0 deletions examples/08_smpl_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import numpy as np
import numpy as onp
import tyro

import viser
import viser.transforms as tf

Expand Down
3 changes: 2 additions & 1 deletion examples/09_urdf_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

import numpy as onp
import tyro
import viser
from robot_descriptions.loaders.yourdfpy import load_robot_description

import viser
from viser.extras import ViserUrdf

# A subset of robots available in the robot_descriptions package.
Expand Down
3 changes: 2 additions & 1 deletion examples/10_realsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import numpy as np
import numpy.typing as npt
import pyrealsense2 as rs # type: ignore
import viser
from tqdm.auto import tqdm

import viser


@contextlib.contextmanager
def realsense_pipeline(fps: int = 30):
Expand Down
3 changes: 2 additions & 1 deletion examples/11_colmap_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
import imageio.v3 as iio
import numpy as onp
import tyro
from tqdm.auto import tqdm

import viser
import viser.transforms as tf
from tqdm.auto import tqdm
from viser.extras.colmap import (
read_cameras_binary,
read_images_binary,
Expand Down
1 change: 1 addition & 0 deletions examples/12_click_meshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time

import matplotlib

import viser


Expand Down
1 change: 1 addition & 0 deletions examples/15_gui_in_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Optional

import numpy as onp

import viser
import viser.transforms as tf

Expand Down
1 change: 1 addition & 0 deletions examples/17_background_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as onp
import trimesh
import trimesh.creation

import viser

server = viser.ViserServer()
Expand Down
1 change: 1 addition & 0 deletions examples/18_splines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time

import numpy as onp

import viser


Expand Down
1 change: 1 addition & 0 deletions examples/19_get_renders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import imageio.v3 as iio
import numpy as onp

import viser


Expand Down
1 change: 1 addition & 0 deletions examples/20_scene_pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import trimesh
import trimesh.creation
import trimesh.ray

import viser
import viser.transforms as tf
from viser.theme import TitlebarConfig
Expand Down
3 changes: 2 additions & 1 deletion examples/22_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import numpy as onp
import trimesh.creation
from typing_extensions import assert_never

import viser
import viser.transforms as tf
from typing_extensions import assert_never


def main() -> None:
Expand Down
3 changes: 2 additions & 1 deletion examples/23_plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import numpy as onp
import plotly.express as px
import plotly.graph_objects as go
import viser
from PIL import Image

import viser


def create_sinusoidal_wave(t: float) -> go.Figure:
"""Create a sinusoidal wave plot, starting at time t."""
Expand Down
1 change: 1 addition & 0 deletions examples/23_smpl_visualizer_skinned.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import numpy as np
import numpy as onp
import tyro

import viser
import viser.transforms as tf

Expand Down
97 changes: 97 additions & 0 deletions examples/24_notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""Notifications
Examples of adding notifications per client in Viser."""

import time

import viser


def main() -> None:
server = viser.ViserServer()

persistent_notif_button = server.gui.add_button(
"Show persistent notification (default)"
)
timed_notif_button = server.gui.add_button("Show timed notification")
controlled_notif_button = server.gui.add_button("Show controlled notification")
loading_notif_button = server.gui.add_button("Show loading notification")

remove_controlled_notif = server.gui.add_button("Remove controlled notification")

@persistent_notif_button.on_click
def _(event: viser.GuiEvent) -> None:
"""Show persistent notification when the button is clicked."""
client = event.client
assert client is not None

client.add_notification(
title="Persistent notification",
body="This can be closed manually and does not disappear on its own!",
loading=False,
with_close_button=True,
auto_close=False,
)

@timed_notif_button.on_click
def _(event: viser.GuiEvent) -> None:
"""Show timed notification when the button is clicked."""
client = event.client
assert client is not None

client.add_notification(
title="Timed notification",
body="This disappears automatically after 5 seconds!",
loading=False,
with_close_button=True,
auto_close=5000,
)

@controlled_notif_button.on_click
def _(event: viser.GuiEvent) -> None:
"""Show controlled notification when the button is clicked."""
client = event.client
assert client is not None

controlled_notif = client.add_notification(
title="Controlled notification",
body="This cannot be closed by the user and is controlled in code only!",
loading=False,
with_close_button=False,
auto_close=False,
)

@remove_controlled_notif.on_click
def _(_) -> None:
"""Remove controlled notification."""
controlled_notif.remove()

@loading_notif_button.on_click
def _(event: viser.GuiEvent) -> None:
"""Show loading notification when the button is clicked."""
client = event.client
assert client is not None

loading_notif = client.add_notification(
title="Loading notification",
body="This indicates that some action is in progress! It will be updated in 3 seconds.",
loading=True,
with_close_button=False,
auto_close=False,
)

time.sleep(3.0)

loading_notif.title = "Updated notification"
loading_notif.body = "This notification has been updated!"
loading_notif.loading = False
loading_notif.with_close_button = True
loading_notif.auto_close = 5000
loading_notif.color = "green"

while True:
time.sleep(1.0)


if __name__ == "__main__":
main()
3 changes: 2 additions & 1 deletion examples/experimental/gaussian_splats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import numpy as onp
import numpy.typing as onpt
import tyro
import viser
from plyfile import PlyData

import viser
from viser import transforms as tf


Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [
[project.optional-dependencies]
dev = [
"pyright>=1.1.308",
"ruff==0.4.6",
"ruff==0.6.2",
"pre-commit==3.3.2",
]
examples = [
Expand Down Expand Up @@ -110,5 +110,6 @@ lint.ignore = [
"PLR0912", # Too many branches.
"PLW0603", # Globa statement updates are discouraged.
"PLW2901", # For loop variable overwritten.
"PLW0642", # Reassigned self in instance method.
]
exclude = [ ".nodeenv" ]
1 change: 1 addition & 0 deletions src/viser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from ._gui_handles import GuiTabHandle as GuiTabHandle
from ._icons_enum import Icon as Icon
from ._icons_enum import IconName as IconName
from ._notification_handle import NotificationHandle as NotificationHandle
from ._scene_api import SceneApi as SceneApi
from ._scene_handles import BatchedAxesHandle as BatchedAxesHandle
from ._scene_handles import CameraFrustumHandle as CameraFrustumHandle
Expand Down
6 changes: 2 additions & 4 deletions src/viser/_gui_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,7 @@ def add_slider(
"""
value: IntOrFloat = initial_value
assert max >= min
if step > max - min:
step = max - min
step = __builtins__.min(step, max - min)
assert max >= value >= min

# GUI callbacks cast incoming values to match the type of the initial value. If
Expand Down Expand Up @@ -1326,8 +1325,7 @@ def add_multi_slider(
A handle that can be used to interact with the GUI element.
"""
assert max >= min
if step > max - min:
step = max - min
step = __builtins__.min(step, max - min)
assert all(max >= x >= min for x in initial_value)

# GUI callbacks cast incoming values to match the type of the initial value. If
Expand Down
Loading

0 comments on commit 2e09df7

Please sign in to comment.