Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make default notebook widget size smaller and configurable #6827

Merged
merged 5 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/python/notebook/cube.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,45 @@
"rr.notebook_show(width=400, height=400)\n"
]
},
{
"cell_type": "markdown",
"id": "ff84c840",
"metadata": {},
"source": [
"To update the default width and height, you can use the `rerun.notebook.set_default_size` function.\n",
"\n",
"Note that you do not need to initialize a recording to use this function."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "81157021",
"metadata": {},
"outputs": [],
"source": [
"from rerun.notebook import set_default_size\n",
"\n",
"set_default_size(width=400, height=400)\n",
"\n",
"rr.init(\"rerun_example_cube\")\n",
"\n",
"small_cube = build_color_grid(3, 3, 3, twist=0)\n",
"rr.log(\"small_cube\", rr.Points3D(small_cube.positions, colors=small_cube.colors, radii=0.5))\n",
"\n",
"rr.notebook_show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "755957e0",
"metadata": {},
"outputs": [],
"source": [
"set_default_size(width=640, height=480)"
]
},
{
"cell_type": "markdown",
"id": "a9812634-067f-4e07-95fb-cb9a506c42d3",
Expand Down
38 changes: 30 additions & 8 deletions rerun_py/rerun_sdk/rerun/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,30 @@

from .recording_stream import RecordingStream, get_data_recording

DEFAULT_WIDTH = 950
DEFAULT_HEIGHT = 712
_default_width = 640
_default_height = 480


def set_default_size(*, width: int | None, height: int | None) -> None:
"""
Set the default size for the viewer.

This will be used for any viewers created after this call.

Parameters
----------
width : int
The width of the viewer in pixels.
height : int
The height of the viewer in pixels.

"""

global _default_width, _default_height
if width is not None:
_default_width = width
if height is not None:
_default_height = height


class Viewer:
Expand All @@ -26,8 +48,8 @@ class Viewer:
def __init__(
self,
*,
width: int = DEFAULT_WIDTH,
height: int = DEFAULT_HEIGHT,
width: int | None = None,
height: int | None = None,
blueprint: BlueprintLike | None = None,
recording: RecordingStream | None = None,
):
Expand Down Expand Up @@ -74,8 +96,8 @@ def __init__(
self._recording.send_blueprint(blueprint) # type: ignore[attr-defined]

self._viewer = _Viewer(
width=width,
height=height,
width=width if width is not None else _default_width,
height=height if height is not None else _default_height,
)

bindings.set_callback_sink(
Expand Down Expand Up @@ -115,8 +137,8 @@ def _repr_keys(self): # type: ignore[no-untyped-def]

def notebook_show(
*,
width: int = DEFAULT_WIDTH,
height: int = DEFAULT_HEIGHT,
width: int | None = None,
height: int | None = None,
blueprint: BlueprintLike | None = None,
recording: RecordingStream | None = None,
) -> None:
Expand Down
Loading