Pan view test.
This commit is contained in:
parent
1efed851e9
commit
8f6a455562
|
@ -896,7 +896,8 @@ class FlatCAMDraw(QtCore.QObject):
|
|||
:param event: Event object dispatched by Matplotlib
|
||||
:return: None
|
||||
"""
|
||||
if self.active_tool is not None:
|
||||
# Selection with left mouse button
|
||||
if self.active_tool is not None and event.button is 1:
|
||||
# Dispatch event to active_tool
|
||||
msg = self.active_tool.click(self.snap(event.xdata, event.ydata))
|
||||
self.app.info(msg)
|
||||
|
|
|
@ -66,6 +66,8 @@ class PlotCanvas:
|
|||
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
|
||||
|
||||
# Events
|
||||
self.canvas.mpl_connect('button_press_event', self.on_mouse_press)
|
||||
self.canvas.mpl_connect('button_release_event', self.on_mouse_release)
|
||||
self.canvas.mpl_connect('motion_notify_event', self.on_mouse_move)
|
||||
#self.canvas.connect('configure-event', self.auto_adjust_axes)
|
||||
self.canvas.mpl_connect('resize_event', self.auto_adjust_axes)
|
||||
|
@ -74,10 +76,14 @@ class PlotCanvas:
|
|||
self.canvas.mpl_connect('scroll_event', self.on_scroll)
|
||||
self.canvas.mpl_connect('key_press_event', self.on_key_down)
|
||||
self.canvas.mpl_connect('key_release_event', self.on_key_up)
|
||||
self.canvas.mpl_connect('draw_event', self.on_draw)
|
||||
|
||||
self.mouse = [0, 0]
|
||||
self.key = None
|
||||
|
||||
self.pan_axes = []
|
||||
self.panning = False
|
||||
|
||||
def on_key_down(self, event):
|
||||
"""
|
||||
|
||||
|
@ -148,7 +154,7 @@ class PlotCanvas:
|
|||
self.axes.grid(True)
|
||||
|
||||
# Re-draw
|
||||
self.canvas.draw()
|
||||
self.canvas.draw_idle()
|
||||
|
||||
def adjust_axes(self, xmin, ymin, xmax, ymax):
|
||||
"""
|
||||
|
@ -204,9 +210,8 @@ class PlotCanvas:
|
|||
ax.set_ylim((ymin, ymax))
|
||||
ax.set_position([x_ratio, y_ratio, 1 - 2 * x_ratio, 1 - 2 * y_ratio])
|
||||
|
||||
# Re-draw
|
||||
# Sync re-draw to proper paint on form resize
|
||||
self.canvas.draw()
|
||||
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
|
||||
|
||||
def auto_adjust_axes(self, *args):
|
||||
"""
|
||||
|
@ -257,9 +262,8 @@ class PlotCanvas:
|
|||
ax.set_xlim((xmin, xmax))
|
||||
ax.set_ylim((ymin, ymax))
|
||||
|
||||
# Re-draw
|
||||
self.canvas.draw()
|
||||
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
|
||||
# Async re-draw
|
||||
self.canvas.draw_idle()
|
||||
|
||||
def pan(self, x, y):
|
||||
xmin, xmax = self.axes.get_xlim()
|
||||
|
@ -273,8 +277,7 @@ class PlotCanvas:
|
|||
ax.set_ylim((ymin + y * height, ymax + y * height))
|
||||
|
||||
# Re-draw
|
||||
self.canvas.draw()
|
||||
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
|
||||
self.canvas.draw_idle()
|
||||
|
||||
def new_axes(self, name):
|
||||
"""
|
||||
|
@ -326,12 +329,50 @@ class PlotCanvas:
|
|||
self.pan(0, -0.3)
|
||||
return
|
||||
|
||||
def on_mouse_press(self, event):
|
||||
|
||||
# Check for middle mouse button press
|
||||
if event.button == 2:
|
||||
|
||||
# Prepare axes for pan (using 'matplotlib' pan function)
|
||||
self.pan_axes = []
|
||||
for a in self.figure.get_axes():
|
||||
if (event.x is not None and event.y is not None and a.in_axes(event) and
|
||||
a.get_navigate() and a.can_pan()):
|
||||
a.start_pan(event.x, event.y, 1)
|
||||
self.pan_axes.append(a)
|
||||
|
||||
# Set pan view flag
|
||||
if len(self.pan_axes) > 0: self.panning = True;
|
||||
|
||||
def on_mouse_release(self, event):
|
||||
|
||||
# Check for middle mouse button release to complete pan procedure
|
||||
if event.button == 2:
|
||||
for a in self.pan_axes:
|
||||
a.end_pan()
|
||||
|
||||
# Clear pan flag
|
||||
self.panning = False
|
||||
|
||||
def on_mouse_move(self, event):
|
||||
"""
|
||||
Mouse movement event hadler. Stores the coordinates.
|
||||
Mouse movement event hadler. Stores the coordinates. Updates view on pan.
|
||||
|
||||
:param event: Contains information about the event.
|
||||
:return: None
|
||||
"""
|
||||
self.mouse = [event.xdata, event.ydata]
|
||||
|
||||
# Update pan view on mouse move
|
||||
if self.panning is True:
|
||||
for a in self.pan_axes:
|
||||
a.drag_pan(1, event.key, event.x, event.y)
|
||||
|
||||
# Async re-draw (redraws only on thread idle state, uses timer on backend)
|
||||
self.canvas.draw_idle()
|
||||
|
||||
def on_draw(self, renderer):
|
||||
|
||||
# Store background on canvas redraw
|
||||
self.background = self.canvas.copy_from_bbox(self.axes.bbox)
|
||||
|
|
Loading…
Reference in New Issue