Skip to content

Commit

Permalink
Always disconnect before setting up new canvas connections
Browse files Browse the repository at this point in the history
Signed-off-by: Brianna Major <[email protected]>
  • Loading branch information
bnmajor committed Sep 6, 2023
1 parent 5ad2f1f commit 4ab41e0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions hexrd/ui/interactive_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def __init__(self, canvas, detector, axes=None, instrument=None):
self._static = True
self.axis_image = axes.get_images()[0] if axes else canvas.axes_images[0]

self.button_press_cid = None
self.button_release_cid = None
self.motion_cid = None
self.key_press_cid = None
self.button_drag_cid = None

@property
def axis(self):
if not self.current_canvas.raw_axes:
Expand All @@ -46,11 +52,9 @@ def static_mode(self, mode):
if mode == self._static:
return

if mode:
self.disconnect()
else:
self.connect_translate_rotate()
self._static = mode
if not mode:
self.connect_translate_rotate()

def update_image(self, img):
self.img = img
Expand All @@ -69,8 +73,7 @@ def create_polygon(self, verts, **polygon_kwargs):
self.shape.set_closed(False)
self.shape_styles.append(polygon_kwargs)
self.update_position()
if not self.static_mode:
self.connect_translate_rotate()
self.connect_translate_rotate()
self.axis.add_patch(self.shape)
self.redraw()

Expand Down Expand Up @@ -159,8 +162,7 @@ def toggle_boundaries(self, show):
self.shape.remove()
self.shape.set_linestyle(self.shape_styles[-1]['line'])
self.axis.add_patch(self.shape)
if not self.static_mode:
self.connect_translate_rotate()
self.connect_translate_rotate()
self.redraw()
else:
if self.shape:
Expand Down Expand Up @@ -253,6 +255,11 @@ def on_key(self, event):
self.on_key_translate(event)

def connect_translate_rotate(self):
if self.static_mode:
return

self.disconnect()

self.button_press_cid = self.current_canvas.mpl_connect(
'button_press_event', self.on_press)
self.button_release_cid = self.current_canvas.mpl_connect(
Expand Down

0 comments on commit 4ab41e0

Please sign in to comment.