Skip to content

forgot a callback #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion fastplotlib/layouts/_gridplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ._defaults import create_controller
from ._subplot import Subplot
from ._record_mixin import RecordMixin

from ..graphics.selectors import PolygonSelector

def to_array(a) -> np.ndarray:
if isinstance(a, np.ndarray):
Expand Down Expand Up @@ -481,6 +481,14 @@ def __init__(self, plot: GridPlot):
tooltip="y-axis direction",
)

self.add_polygon_button = Button(
value=False,
disabled=False,
icon="draw-polygon",
layout=Layout(width="auto"),
tooltip="add PolygonSelector"
)

self.record_button = ToggleButton(
value=False,
disabled=False,
Expand Down Expand Up @@ -510,6 +518,7 @@ def __init__(self, plot: GridPlot):
self.panzoom_controller_button,
self.maintain_aspect_button,
self.flip_camera_button,
self.add_polygon_button,
self.record_button,
self.dropdown,
]
Expand All @@ -520,6 +529,7 @@ def __init__(self, plot: GridPlot):
self.center_scene_button.on_click(self.center_scene)
self.maintain_aspect_button.observe(self.maintain_aspect, "value")
self.flip_camera_button.on_click(self.flip_camera)
self.add_polygon_button.on_click(self.add_polygon)
self.record_button.observe(self.record_plot, "value")

self.plot.renderer.add_event_handler(self.update_current_subplot, "click")
Expand Down Expand Up @@ -580,3 +590,8 @@ def record_plot(self, obj):
self.record_button.value = False
else:
self.plot.record_stop()

def add_polygon(self, obj):
ps = PolygonSelector(edge_width=3, edge_color="magenta")

self.current_subplot.add_graphic(ps, center=False)