From 72db396a780d3ff6132930a500a9e9cac5a6b670 Mon Sep 17 00:00:00 2001 From: Matthew Clapp Date: Sun, 16 Sep 2018 18:19:24 -0700 Subject: [PATCH] Only Bind on_motion while left button down. Fixes #141 --- marcam/image_scrolled_canvas.py | 10 +++++++--- marcam/image_scrolled_canvas_marks.py | 9 +++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/marcam/image_scrolled_canvas.py b/marcam/image_scrolled_canvas.py index 6bf14d1..96c300f 100644 --- a/marcam/image_scrolled_canvas.py +++ b/marcam/image_scrolled_canvas.py @@ -414,7 +414,6 @@ def __init__(self, parent, *args, **kwargs): self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) self.Bind(wx.EVT_LEFT_UP, self.on_left_up) self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_down) - self.Bind(wx.EVT_MOTION, self.on_motion) # determine widths of scrollbars self.get_scrollbar_widths() @@ -665,6 +664,9 @@ def on_left_down(self, evt): # we allow click outside of image in case we drag onto image + # start following motion until on_left_up, in case this is a drag + self.Bind(wx.EVT_MOTION, self.on_motion) + # in case we need a drag capture mouse self.CaptureMouse() @@ -682,8 +684,7 @@ def on_left_down(self, evt): 'is_toggling':is_toggling, } - # don't debug on_motion normally, too much log msgs - #@debug_fxn + @debug_fxn_debug def on_motion(self, evt): """EVT_MOTION handler: "mouse moving". Used esp. to track dragging @@ -788,6 +789,9 @@ def on_left_up(self, evt): if self.HasCapture(): self.ReleaseMouse() + # stop following motion + self.Unbind(wx.EVT_MOTION) + @debug_fxn def on_right_down(self, evt): """EVT_RIGHT_DOWN handler: mouse right-clicks diff --git a/marcam/image_scrolled_canvas_marks.py b/marcam/image_scrolled_canvas_marks.py index b85f403..2f3c0ed 100644 --- a/marcam/image_scrolled_canvas_marks.py +++ b/marcam/image_scrolled_canvas_marks.py @@ -152,6 +152,9 @@ def on_left_down(self, evt): else: # we allow click outside of image in case we drag onto image + # start following motion until on_left_up, in case this is a drag + self.Bind(wx.EVT_MOTION, self.on_motion) + # in case we need a drag capture mouse self.CaptureMouse() @@ -181,8 +184,7 @@ def on_left_down(self, evt): 'mark_pt_is_sel':mark_pt_is_sel } - # don't debug on_motion normally, too much log msgs - #@debug_fxn + @debug_fxn_debug def on_motion(self, evt): """EVT_MOTION handler: "mouse moving". Used esp. to track dragging @@ -407,6 +409,9 @@ def on_left_up(self, evt): if self.HasCapture(): self.ReleaseMouse() + # stop following motion + self.Unbind(wx.EVT_MOTION) + @debug_fxn def move_mark(self, from_mark_pt, to_mark_pt, is_selected): """Move mark from one location to another