Skip to content

Commit 17b60dc

Browse files
committed
RF: Title available in show mehtod.
- actors parameter is show method can accept a single object as well - updated the title in the show manager to handle empty and none values.
1 parent 5e47124 commit 17b60dc

2 files changed

Lines changed: 49 additions & 6 deletions

File tree

fury/tests/test_window.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Scene as GfxScene,
2323
ScreenCoordsCamera,
2424
Texture,
25+
TrackballController,
2526
have_imgui_bundle,
2627
)
2728
from fury.ui import Rectangle2D, UIContext
@@ -222,7 +223,7 @@ def test_screen_initialization_default():
222223
assert screen.size == (640, 480) # Default size of pygfx
223224
assert screen.position == (0, 0) # Default position of pygfx
224225
assert isinstance(screen.camera, PerspectiveCamera)
225-
assert isinstance(screen.controller, OrbitController)
226+
assert isinstance(screen.controller, TrackballController)
226227

227228
assert (
228229
len(screen.scene.main_scene.children) == 3
@@ -522,11 +523,40 @@ def test_show_manager_with_empty_config():
522523
assert len(show_m.screens) == 1
523524

524525

526+
def test_show_manager_with_empty_title():
527+
"""Test initialization with empty screen config."""
528+
show_m = ShowManager(window_type="offscreen", title=None)
529+
assert show_m._title == "FURY 2.0"
530+
show_m = ShowManager(window_type="offscreen", title="")
531+
assert show_m._title == "FURY 2.0"
532+
533+
525534
def test_display_default(sample_actor):
526535
"""Test the display function with default parameters."""
527536
with patch("fury.window.ShowManager") as mock_show_manager:
528-
show([sample_actor])
537+
show(sample_actor)
529538
mock_show_manager.assert_called_once()
539+
kwargs = mock_show_manager.call_args.kwargs
540+
assert kwargs["window_type"] == "default"
541+
assert kwargs["title"] == "FURY 2.0"
542+
assert sample_actor in kwargs["scene"].main_scene.children
543+
mock_show_manager.return_value.start.assert_called_once_with()
544+
545+
546+
def test_display_accepts_iterable_actors(sample_actor):
547+
"""Test the display function with a non-list iterable of actors."""
548+
second_actor = sphere(np.array([[1, 0, 0]]), material="basic", impostor=False)
549+
actors = (item for item in (sample_actor, second_actor))
550+
551+
with patch("fury.window.ShowManager") as mock_show_manager:
552+
show(actors, window_type="offscreen", title="Iterable actors")
553+
554+
kwargs = mock_show_manager.call_args.kwargs
555+
assert kwargs["window_type"] == "offscreen"
556+
assert kwargs["title"] == "Iterable actors"
557+
assert sample_actor in kwargs["scene"].main_scene.children
558+
assert second_actor in kwargs["scene"].main_scene.children
559+
mock_show_manager.return_value.start.assert_called_once_with()
530560

531561

532562
def test_add_remove_ui_to_from_scene(sample_actor):

fury/window.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import logging
1212
import os
1313
import sys
14+
from typing import Iterable
1415

1516
from PIL.Image import fromarray as image_from_array
1617
import numpy as np
@@ -690,6 +691,8 @@ def __init__(
690691
event handling.
691692
"""
692693
self._size = size
694+
if not title:
695+
title = "FURY 2.0"
693696
self._title = title
694697
self._is_qt = False
695698
self._qt_app = qt_app
@@ -1743,7 +1746,12 @@ def __str__(self):
17431746
return report
17441747

17451748

1746-
def show(actors, *, window_type="default"):
1749+
def show(
1750+
actors,
1751+
*,
1752+
window_type="default",
1753+
title="FURY 2.0",
1754+
):
17471755
"""
17481756
Display one or more actors in a new window quickly.
17491757
@@ -1756,9 +1764,14 @@ def show(actors, *, window_type="default"):
17561764
The PyGfx actor(s) to display.
17571765
window_type : str, optional
17581766
The type of window canvas to create ('default', 'glfw', 'qt',
1759-
'jupyter', 'offscreen'). Defaults to 'default'.
1767+
'jupyter', 'offscreen').
1768+
title : str, optional
1769+
The title for the window.
17601770
"""
17611771
scene = Scene()
1762-
scene.add(*actors)
1763-
show_m = ShowManager(scene=scene, window_type=window_type)
1772+
if isinstance(actors, Iterable):
1773+
scene.add(*actors)
1774+
else:
1775+
scene.add(actors)
1776+
show_m = ShowManager(scene=scene, window_type=window_type, title=title)
17641777
show_m.start()

0 commit comments

Comments
 (0)