Skip to content

Commit 216e68f

Browse files
committed
feat: add sidecar option in widgets
1 parent 502648f commit 216e68f

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ visualization = [
5454
"jupyter-rfb==0.4.2",
5555
"Pillow==10.2.0",
5656
"simplejpeg==1.7.2",
57+
"sidecar==0.7.0"
5758
]
5859

5960
[tool.flit.module]

src/ansys/stk/core/stkengine/experimental/jupyterwidgets.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ def __init__(self,
217217
root: StkObjectRoot,
218218
w: int = 800,
219219
h: int = 600,
220+
title: str = None,
220221
resizable: bool = True):
221222

222223
super().__init__()
@@ -266,6 +267,7 @@ def __init__(self,
266267
asyncioTimerManager = AsyncioTimerManager()
267268

268269
self.root = root
270+
self.title = title or self.root.current_scenario.instance_name
269271
self.camera = self.root.current_scenario.scene_manager.scenes.item(0).camera
270272

271273
def __del__(self):
@@ -352,6 +354,9 @@ def handle_event(self, event):
352354
dy = int(event["dy"] * self.pixel_ratio/100)
353355
self._rfb.notify_mouse_wheel(x, y, -dy, self.__get_modifiers(event))
354356

357+
def set_title(self, title):
358+
self.title = title
359+
355360
def get_frame(self):
356361
self._rfb.snap_to_rbg_raster(self.pointer)
357362
return self.frame
@@ -360,9 +365,15 @@ def animate(self):
360365
self.root.execute_command("Animate * Start Loop")
361366
self.show()
362367

363-
def show(self, **snapshot_kwargs):
364-
needs_snapshot = os.environ.get("BUILD_EXAMPLES", "true") == "true"
365-
return self.snapshot(**snapshot_kwargs) if needs_snapshot else self
368+
def show(self, in_sidecar=False, **snapshot_kwargs):
369+
needs_snapshot = os.environ.get("BUILD_EXAMPLES", "false") == "true"
370+
canvas = self.snapshot(**snapshot_kwargs) if needs_snapshot else self
371+
if in_sidecar:
372+
from sidecar import Sidecar
373+
with Sidecar(title=self.title):
374+
display(canvas)
375+
else:
376+
return canvas
366377

367378
class GlobeWidget(UiAxGraphics3DCntrl, WidgetBase):
368379
'''
@@ -383,8 +394,8 @@ class GlobeWidget(UiAxGraphics3DCntrl, WidgetBase):
383394
_progid = "STKX12.VOControl.1"
384395
_interface = UiAxGraphics3DCntrl
385396

386-
def __init__(self, root: StkObjectRoot, w: int, h: int):
387-
WidgetBase.__init__(self, root, w, h)
397+
def __init__(self, root: StkObjectRoot, w: int, h: int, title: str):
398+
WidgetBase.__init__(self, root, w, h, title)
388399

389400
def __setattr__(self, attrname, value):
390401
WidgetBase.__setattr__(self, attrname, value)
@@ -398,8 +409,8 @@ class MapWidget(UiAx2DCntrl, WidgetBase):
398409
_progid = "STKX12.2DControl.1"
399410
_interface = UiAx2DCntrl
400411

401-
def __init__(self, root: StkObjectRoot, w: int, h: int):
402-
WidgetBase.__init__(self, root, w, h)
412+
def __init__(self, root: StkObjectRoot, w: int, h: int, title: str):
413+
WidgetBase.__init__(self, root, w, h, title)
403414

404415
def __setattr__(self, attrname, value):
405416
WidgetBase.__setattr__(self, attrname, value)

0 commit comments

Comments
 (0)