Can't exit pan or zoom mode automatically when activating widget

Viewed 131

I added a widget into the matplotlib toolbar called 'Select Points' that allows me to select a group of points in my figure window and write them to a file. This works fine. However, if I previously had to zoom or pan into my region of interest before clicking my widget button on the toolbar, the zoom or pan modes remain active and I am unable to select my points with my widget button unless I manually click the zoom/pan buttons on the toolbar again to deactivate those modes. Is there a way to programmatically exit from the zoom or pan mode when my widget button is clicked? It's a small pain, but a nice feature I would like to have.

I have tried looking all through the plt.gcf().canvas methods and I can't seem to find where I can select/deselect toolbar modes from within my code.

---PART OF CODE THAT LINKS TOOLBAR WIDGET BUTTON CALLED 'SELECT POINTS' TO getPoints CLASS---

# Get figure handles
figNum = plt.gcf()
ax = plt.gca()
pts = ax.collections[-1]

# Route 'Select Points' button to matplotlib figure window
fig1.canvas.manager.toolmanager.add_tool('Select Points', getPoints, figNum = figNum, ax = ax, pts = pts, outPath = outPath, origTitle = origTitle)
fig1.canvas.manager.toolbar.add_tool('Select Points', 'navigation', 3)

---getPoints CLASS---

class getPoints(ToolToggleBase):

default_toggled = False

def __init__(self, *args, figNum, ax, pts, outPath, origTitle, **kwargs):

    # Initialize base variables
    self.figNum = figNum
    self.ax = ax
    self.pts = pts
    self.outPath = outPath
    self.origTitle = origTitle

    # Call super-initialized variables
    super().__init__(*args, **kwargs)


def enable(self, *args, **kwargs):

    # Get inputs for getPlotPts function
    figNum = self.figNum
    ax = self.ax
    pts = self.pts
    outPath = self.outPath 
    origTitle = self.origTitle
    onState = True

    # Call getPlotPts function
    getPlotPts(self, figNum, ax, pts, outPath, origTitle, onState)


def disable(self, *args, **kwargs):

    # Get inputs for getPlotPts function
    figNum = self.figNum
    ax = self.ax
    pts = self.pts
    outPath = self.outPath 
    origTitle = self.origTitle
    onState = False

    # Call getPlotPts function
    getPlotPts(self, figNum, ax, pts, outPath, origTitle, onState)
0 Answers
Related