Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 34ff9a2

Browse filesBrowse files
committed
create Output context classes, basic layout of Frame, not tested yet
1 parent 88f33c3 commit 34ff9a2
Copy full SHA for 34ff9a2
Expand file treeCollapse file tree

13 files changed

+443
-879
lines changed
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from ._frame import Frame

‎fastplotlib/layouts/_frame/_frame.py

Copy file name to clipboard
+123Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import os
2+
3+
from ._toolbar import ToolBar
4+
5+
from .._utils import CANVAS_OPTIONS_AVAILABLE
6+
7+
class UnavailableOutputContext:
8+
def __init__(self, *arg, **kwargs):
9+
raise ModuleNotFoundError("Unavailable output context")
10+
11+
12+
if CANVAS_OPTIONS_AVAILABLE["jupyter"]:
13+
from ._jupyter_output import JupyterOutput
14+
else:
15+
JupyterOutput = UnavailableOutputContext
16+
17+
if CANVAS_OPTIONS_AVAILABLE["qt"]:
18+
from ._qt_output import QtOutput
19+
else:
20+
JupyterOutput = UnavailableOutputContext
21+
22+
23+
# Single class for PlotFrame to avoid determining inheritance at runtime
24+
class Frame:
25+
"""Mixin class for Plot and GridPlot that gives them the toolbar"""
26+
def __init__(self):
27+
"""
28+
29+
Parameters
30+
----------
31+
plot:
32+
`Plot` or `GridPlot`
33+
toolbar
34+
"""
35+
self._plot_type = self.__class__.__name__
36+
self._output = None
37+
38+
@property
39+
def toolbar(self) -> ToolBar:
40+
return self._output.toolbar
41+
42+
def render(self):
43+
raise NotImplemented
44+
45+
def _autoscale_init(self, maintain_aspect: bool):
46+
"""autoscale function that is called only during show()"""
47+
if hasattr(self, "_subplots"):
48+
for subplot in self:
49+
if maintain_aspect is None:
50+
_maintain_aspect = subplot.camera.maintain_aspect
51+
else:
52+
_maintain_aspect = maintain_aspect
53+
subplot.auto_scale(maintain_aspect=_maintain_aspect, zoom=0.95)
54+
else:
55+
if maintain_aspect is None:
56+
maintain_aspect = self.camera.maintain_aspect
57+
self.auto_scale(maintain_aspect=maintain_aspect, zoom=0.95)
58+
59+
def show(
60+
self,
61+
autoscale: bool = True,
62+
maintain_aspect: bool = None,
63+
toolbar: bool = True,
64+
sidecar: bool = False,
65+
sidecar_kwargs: dict = None,
66+
):
67+
"""
68+
Begins the rendering event loop and returns the canvas
69+
70+
Parameters
71+
----------
72+
autoscale: bool, default ``True``
73+
autoscale the Scene
74+
75+
maintain_aspect: bool, default ``True``
76+
maintain aspect ratio
77+
78+
toolbar: bool, default ``True``
79+
show toolbar
80+
81+
sidecar: bool, default ``True``
82+
display plot in a ``jupyterlab-sidecar``
83+
84+
sidecar_kwargs: dict, default ``None``
85+
kwargs for sidecar instance to display plot
86+
i.e. title, layout
87+
88+
Returns
89+
-------
90+
WgpuCanvas
91+
the canvas
92+
93+
"""
94+
if self._output is not None:
95+
return self._output
96+
97+
self.canvas.request_draw(self.render)
98+
self.canvas.set_logical_size(*self._starting_size)
99+
100+
if autoscale:
101+
self._autoscale_init(maintain_aspect)
102+
103+
if "NB_SNAPSHOT" in os.environ.keys():
104+
# used for docs
105+
if os.environ["NB_SNAPSHOT"] == "1":
106+
return self.canvas.snapshot()
107+
108+
if self.canvas.__class__.__name__ == "JupyterWgpuCanvas":
109+
return JupyterOutput(
110+
frame=self,
111+
make_toolbar=toolbar,
112+
use_sidecar=sidecar,
113+
sidecar_kwargs=sidecar_kwargs
114+
)
115+
116+
elif self.canvas.__class__.__name__ == "QWgpuCanvas":
117+
QtOutput(
118+
frame=self,
119+
make_toolbar=toolbar,
120+
)
121+
122+
def close(self):
123+
self._output.close()

‎fastplotlib/layouts/_frame/_frame_base.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_frame/_frame_base.py
-89Lines changed: 0 additions & 89 deletions
This file was deleted.

‎fastplotlib/layouts/_frame/_frame_desktop.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_frame/_frame_desktop.py
Whitespace-only changes.

‎fastplotlib/layouts/_frame/_frame_notebook.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_frame/_frame_notebook.py
-103Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.