From 312d26a71a3427c49f33ade07bbc848d7d077af2 Mon Sep 17 00:00:00 2001 From: fuzzythecat Date: Sat, 14 Oct 2017 03:44:37 +0900 Subject: [PATCH 1/4] Fix minor bug in vertex insert --- examples/event_handling/poly_editor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/event_handling/poly_editor.py b/examples/event_handling/poly_editor.py index 13b139d56bab..3e6d5f6654af 100644 --- a/examples/event_handling/poly_editor.py +++ b/examples/event_handling/poly_editor.py @@ -127,9 +127,9 @@ def key_press_callback(self, event): d = dist_point_to_segment(p, s0, s1) if d <= self.epsilon: self.poly.xy = np.array( - list(self.poly.xy[:i]) + + list(self.poly.xy[:i + 1]) + [(event.xdata, event.ydata)] + - list(self.poly.xy[i:])) + list(self.poly.xy[i + 1:])) self.line.set_data(zip(*self.poly.xy)) break From d9839d4de441381c2908d832ac320c58bf7e3695 Mon Sep 17 00:00:00 2001 From: fuzzythecat Date: Sat, 14 Oct 2017 05:35:29 +0900 Subject: [PATCH 2/4] Make insert clearer --- examples/event_handling/poly_editor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/event_handling/poly_editor.py b/examples/event_handling/poly_editor.py index 3e6d5f6654af..10ecbc1e3264 100644 --- a/examples/event_handling/poly_editor.py +++ b/examples/event_handling/poly_editor.py @@ -126,10 +126,10 @@ def key_press_callback(self, event): s1 = xys[i + 1] d = dist_point_to_segment(p, s0, s1) if d <= self.epsilon: - self.poly.xy = np.array( - list(self.poly.xy[:i + 1]) + - [(event.xdata, event.ydata)] + - list(self.poly.xy[i + 1:])) + self.poly.xy = np.insert( + self.poly.xy, i+1, + [event.xdata, event.ydata], + axis=0) self.line.set_data(zip(*self.poly.xy)) break From a7c4e9fbfeefbc78500bed3932f5820cbe3e5b4e Mon Sep 17 00:00:00 2001 From: fuzzythecat Date: Sat, 14 Oct 2017 05:39:21 +0900 Subject: [PATCH 3/4] Make delete clearer --- examples/event_handling/poly_editor.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/event_handling/poly_editor.py b/examples/event_handling/poly_editor.py index 10ecbc1e3264..1154c74a73e5 100644 --- a/examples/event_handling/poly_editor.py +++ b/examples/event_handling/poly_editor.py @@ -114,9 +114,8 @@ def key_press_callback(self, event): elif event.key == 'd': ind = self.get_ind_under_point(event) if ind is not None: - self.poly.xy = [tup - for i, tup in enumerate(self.poly.xy) - if i != ind] + self.poly.xy = np.delete(self.poly.xy, + ind, axis=0) self.line.set_data(zip(*self.poly.xy)) elif event.key == 'i': xys = self.poly.get_transform().transform(self.poly.xy) From bcfd4f5e2ff3c1c6a573572354267a73a64a26f2 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sat, 21 Oct 2017 14:31:15 -0400 Subject: [PATCH 4/4] DOC: tweak how initial draw and updates are handled --- examples/event_handling/poly_editor.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/event_handling/poly_editor.py b/examples/event_handling/poly_editor.py index 1154c74a73e5..83626968f08e 100644 --- a/examples/event_handling/poly_editor.py +++ b/examples/event_handling/poly_editor.py @@ -59,7 +59,8 @@ def draw_callback(self, event): self.background = self.canvas.copy_from_bbox(self.ax.bbox) self.ax.draw_artist(self.poly) self.ax.draw_artist(self.line) - self.canvas.blit(self.ax.bbox) + # do not need to blit here, this will fire before the screen is + # updated def poly_changed(self, poly): 'this method is called whenever the polygon object is called' @@ -131,8 +132,8 @@ def key_press_callback(self, event): axis=0) self.line.set_data(zip(*self.poly.xy)) break - - self.canvas.draw() + if self.line.stale: + self.canvas.draw_idle() def motion_notify_callback(self, event): 'on mouse movement'