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 80a3fb2

Browse filesBrowse files
committed
plot frame system working for jupyter
1 parent 34ff9a2 commit 80a3fb2
Copy full SHA for 80a3fb2

File tree

Expand file treeCollapse file tree

4 files changed

+36
-20
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+36
-20
lines changed

‎fastplotlib/layouts/_frame/_frame.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_frame/_frame.py
+23-5Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@
44

55
from .._utils import CANVAS_OPTIONS_AVAILABLE
66

7+
78
class UnavailableOutputContext:
8-
def __init__(self, *arg, **kwargs):
9-
raise ModuleNotFoundError("Unavailable output context")
9+
def __init__(self, context_name, msg):
10+
self.context_name = context_name
11+
self.msg = msg
12+
13+
def __call__(self, *args, **kwargs):
14+
raise ModuleNotFoundError(
15+
f"The following output context is not available: {self.context_name}\n{self.msg}"
16+
)
1017

1118

1219
if CANVAS_OPTIONS_AVAILABLE["jupyter"]:
1320
from ._jupyter_output import JupyterOutput
1421
else:
15-
JupyterOutput = UnavailableOutputContext
22+
JupyterOutput = UnavailableOutputContext(
23+
"Jupyter",
24+
"You must install `jupyter_rfb` to use this output context"
25+
)
1626

1727
if CANVAS_OPTIONS_AVAILABLE["qt"]:
1828
from ._qt_output import QtOutput
1929
else:
20-
JupyterOutput = UnavailableOutputContext
30+
QtOutput = UnavailableOutputContext(
31+
"Qt",
32+
"You must install `PyQt6` to use this output context"
33+
)
2134

2235

2336
# Single class for PlotFrame to avoid determining inheritance at runtime
@@ -94,6 +107,9 @@ def show(
94107
if self._output is not None:
95108
return self._output
96109

110+
if sidecar_kwargs is None:
111+
sidecar_kwargs = dict()
112+
97113
self.canvas.request_draw(self.render)
98114
self.canvas.set_logical_size(*self._starting_size)
99115

@@ -106,7 +122,7 @@ def show(
106122
return self.canvas.snapshot()
107123

108124
if self.canvas.__class__.__name__ == "JupyterWgpuCanvas":
109-
return JupyterOutput(
125+
self._output = JupyterOutput(
110126
frame=self,
111127
make_toolbar=toolbar,
112128
use_sidecar=sidecar,
@@ -119,5 +135,7 @@ def show(
119135
make_toolbar=toolbar,
120136
)
121137

138+
return self._output
139+
122140
def close(self):
123141
self._output.close()

‎fastplotlib/layouts/_frame/_ipywidget_toolbar.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_frame/_ipywidget_toolbar.py
+8-10Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from ._toolbar import ToolBar
99

1010

11-
class IpywidgetToolBar(ToolBar):
11+
class IpywidgetToolBar(HBox, ToolBar):
1212
def __init__(self, plot):
1313
"""
1414
Basic toolbar for a GridPlot instance.
@@ -17,7 +17,7 @@ def __init__(self, plot):
1717
----------
1818
plot:
1919
"""
20-
super().__init__(plot)
20+
ToolBar.__init__(self, plot)
2121

2222
self._auto_scale_button = Button(
2323
value=False,
@@ -102,7 +102,7 @@ def __init__(self, plot):
102102

103103
widgets.append(self._dropdown)
104104

105-
self.widget = HBox(widgets)
105+
# self.widget = HBox(widgets)
106106

107107
self._panzoom_controller_button.observe(self.panzoom_handler, "value")
108108
self._auto_scale_button.on_click(self.auto_scale_handler)
@@ -114,6 +114,8 @@ def __init__(self, plot):
114114

115115
self._maintain_aspect_button.value = self.current_subplot.camera.maintain_aspect
116116

117+
HBox.__init__(self, widgets)
118+
117119
def _get_subplot_dropdown_value(self) -> str:
118120
return self._dropdown.value
119121

@@ -127,7 +129,7 @@ def panzoom_handler(self, obj):
127129
self.current_subplot.controller.enabled = self._panzoom_controller_button.value
128130

129131
def maintain_aspect(self, obj):
130-
for camera in self.plot.controller.cameras:
132+
for camera in self.current_subplot.controller.cameras:
131133
camera.maintain_aspect = self._maintain_aspect_button.value
132134

133135
def y_direction_handler(self, obj):
@@ -164,11 +166,7 @@ def record_plot(self, obj):
164166

165167
def add_polygon(self, obj):
166168
ps = PolygonSelector(edge_width=3, edge_color="magenta")
167-
168169
self.current_subplot.add_graphic(ps, center=False)
169170

170-
def close(self):
171-
self.widget.close()
172-
173-
def __repr__(self):
174-
return self.widget
171+
def _repr_mimebundle(self, *args, **kwargs):
172+
super()._repr_mimebundle(*args, **kwargs)

‎fastplotlib/layouts/_frame/_jupyter_output.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_frame/_jupyter_output.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ def __init__(
1919

2020
self.use_sidecar = use_sidecar
2121

22-
if not make_toolbar and not use_sidecar:
22+
if not make_toolbar:
2323
self.output = frame.canvas
2424

2525
if make_toolbar:
2626
self.toolbar = IpywidgetToolBar(frame)
27-
self.output = VBox([frame.canvas, frame.toolbar])
27+
self.output = VBox([frame.canvas, self.toolbar])
2828

2929
if use_sidecar:
3030
self.sidecar = Sidecar(**sidecar_kwargs)
3131

32-
def __repr__(self):
32+
def _repr_mimebundle_(self, *args, **kwargs):
3333
if self.use_sidecar:
3434
with self.sidecar:
3535
return display(self.output)
3636
else:
37-
return self.output
37+
return self.output._repr_mimebundle_(*args, **kwargs)
3838

3939
def close(self):
4040
self.frame.canvas.close()

‎fastplotlib/layouts/_frame/_toolbar.py

Copy file name to clipboardExpand all lines: fastplotlib/layouts/_frame/_toolbar.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def current_subplot(self) -> Subplot:
1515
current = self._get_subplot_dropdown_value()
1616
if current[0] == "(":
1717
# str representation of int tuple to tuple of int
18-
current = (int(i) for i in current.strip("()").split(","))
18+
current = tuple(int(i) for i in current.strip("()").split(","))
1919
return self.plot[current]
2020
else:
2121
return self.plot[current]

0 commit comments

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