Migrating some code which use NavigationToolbar2QT to matplotlib 2.x AND 3.x

Hello,

I have this code in one of the project I neded to update.
Since we are targetting Debian buster, I need to support
matplotlib 2.X (python2) AND matplotlib 3.X (python3)

class HiddenToolbar(NavigationToolbar2QT):
    def __init__(self, corner_callback, canvas):
        super(HiddenToolbar, self).__init__(canvas, None)
        self._corner_callback = corner_callback
        self.zoom()

    def press(self, event):
        self._corner_preclick = self._views()

    def release(self, event):
        if self._corner_preclick == self._views():
            self._corner_callback(event.xdata, event.ydata)
        self._corner_preclick = None

The problem, I have is with the _views() method.
The 3.X version, complains that it is not available in the NavigationToolbar2QT.

so I would like to know how to rewrite this in order to be 2.X and 3.X compatible.
I tryed to find some information in the documentation about this but I did not find it.

thanks for your help.

Frederic

Fedric,

Hello from NSLS-II!

`_veiws` is private so we reserve the right to change it at any time.
`.views()` was a Stack of lists of the xlim and ylim of all of the Axes in
the Figure. I suggest replacing it with something like

class HiddenToolbar(NavigationToolbar2QT):
    def __init__(self, corner_callback, canvas):
        super(HiddenToolbar, self).__init__(canvas, None)
        self._corner_callback = corner_callback
        self.zoom()

    def _generate_key(self):
        limits = []
        for a in self.canvas.figure.get_axes():
            limits.append([a.get_xlim(), a.get_ylim()])
        return limits

    def press(self, event):
        self._corner_preclick = self._generate_key()

    def release(self, event):
        if self._corner_preclick == self._generate_key():
            self._corner_callback(event.xdata, event.ydata)
        self._corner_preclick = None

which only uses public APIs from upstream.

What is the purpose of this code? It looks like this is a de-bouncer to
cancel a callback if something changes the limits while the mouse is held
down?

Tom

···

On Fri, Feb 15, 2019 at 3:52 AM PICCA Frederic-Emmanuel < frederic-emmanuel.picca at synchrotron-soleil.fr> wrote:

Hello,

I have this code in one of the project I neded to update.
Since we are targetting Debian buster, I need to support
matplotlib 2.X (python2) AND matplotlib 3.X (python3)

class HiddenToolbar(NavigationToolbar2QT):
    def __init__(self, corner_callback, canvas):
        super(HiddenToolbar, self).__init__(canvas, None)
        self._corner_callback = corner_callback
        self.zoom()

    def press(self, event):
        self._corner_preclick = self._views()

    def release(self, event):
        if self._corner_preclick == self._views():
            self._corner_callback(event.xdata, event.ydata)
        self._corner_preclick = None

The problem, I have is with the _views() method.
The 3.X version, complains that it is not available in the
NavigationToolbar2QT.

so I would like to know how to rewrite this in order to be 2.X and 3.X
compatible.
I tryed to find some information in the documentation about this but I did
not find it.

thanks for your help.

Frederic
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
https://mail.python.org/mailman/listinfo/matplotlib-users

--
Thomas Caswell
tcaswell at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20190215/a38d70b7/attachment.html>

Fedric,

Hello from NSLS-II!

:))

`_veiws` is private so we reserve the right to change it at any time. `.views()` was a Stack of lists of the xlim and ylim of all of the Axes in the Figure. I suggest replacing it > with something like

thanks a lot. I did not know that matplotlib guyes where working at NSLS-II.

...

which only uses public APIs from upstream.

I prefer also.

What is the purpose of this code? It looks like this is a de-bouncer to cancel a callback if something changes the limits while the mouse is held down?

I do not know for now, but I will tell you if I discover it :).
This is some code from binoculars that I need to migrates. to matplotlib 3.X.

Cheers

Fred