11from __future__ import annotations
22
3- import warnings
43from typing import TYPE_CHECKING , Any , cast
54
65import numpy as np
@@ -40,7 +39,12 @@ def __init__(self, view: model.View, **backend_kwargs: Any) -> None:
4039 self ._snx_set_camera (view .camera )
4140 self ._snx_set_scene (view .scene )
4241
42+ # -- Layout connections -- #
43+ self ._model .layout .events .background_color .connect (self ._set_background_color )
4344 view .layout .events .all .connect (self ._on_layout_changed )
45+
46+ # -- Layout initialization -- #
47+ self ._set_background_color (view .layout .background_color )
4448 self ._on_layout_changed ()
4549
4650 def _on_vispy_viewbox_resized (self , event : Any ) -> None :
@@ -54,9 +58,6 @@ def _on_layout_changed(self, event: Any | None = None) -> None:
5458 self ._vispy_viewbox .update ()
5559 self ._cam_adaptor ._set_view (rect .width , rect .height )
5660
57- def _snx_get_native (self ) -> Any :
58- return self ._vispy_viewbox
59-
6061 def _snx_set_visible (self , arg : bool ) -> None :
6162 pass
6263
@@ -96,31 +97,9 @@ def _snx_set_camera(self, cam: model.Camera) -> None:
9697 def _draw (self ) -> None :
9798 self ._vispy_viewbox .update ()
9899
99- def _snx_set_position (self , arg : tuple [float , float ]) -> None :
100- raise NotImplementedError ()
101-
102- def _snx_set_size (self , arg : tuple [float , float ] | None ) -> None :
103- raise NotImplementedError ()
104-
105- def _snx_set_border_width (self , arg : float ) -> None :
106- warnings .warn (
107- "set_border_width not implemented for vispy" , RuntimeWarning , stacklevel = 2
108- )
109-
110- def _snx_set_border_color (self , arg : Color | None ) -> None :
111- warnings .warn (
112- "set_border_color not implemented for vispy" , RuntimeWarning , stacklevel = 2
113- )
114-
115- def _snx_set_padding (self , arg : int ) -> None :
116- warnings .warn (
117- "set_padding not implemented for vispy" , RuntimeWarning , stacklevel = 2
118- )
119-
120- def _snx_set_margin (self , arg : int ) -> None :
121- warnings .warn (
122- "set_margin not implemented for vispy" , RuntimeWarning , stacklevel = 2
123- )
100+ def _set_background_color (self , color : Color | None ) -> None :
101+ color_data = None if color is None else color .rgba
102+ self ._vispy_viewbox .bgcolor = color_data
124103
125104 def _snx_render (self ) -> np .ndarray :
126105 """Render to screenshot."""
0 commit comments