Overriding Save button on Toolbar

I'm trying to override the behaviour of the toolbar, with partial success.

This works:

...but this doesn't:

Having actually created a figure, I can get a bound method for save_figure:

This I can override, and call my override function successfully from my
script - but pressing the save button on the toolbar doesn't call my
function...

I'm running matplotlib 1.1.1rc and python 2.7.3

Thanks,

Will

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Overriding-Save-button-on-Toolbar-tp40864.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hmm, problems with html, will try again in plain text:

I’m trying to override the behaviour of the toolbar, with partial success.

This works:

from matplotlib.backend_bases import NavigationToolbar2

home = NavigationToolbar2.home

def new_home(self, *args, **kwargs):
print ‘home pressed’
home(self, *args, **kwargs)

NavigationToolbar2.home = new_home

…but this doesn’t:

from matplotlib.backend_bases import NavigationToolbar2

save_figure = NavigationToolbar2.save_figure

def new_save(self, *args, **kwargs):
print ‘save_figure pressed’
save_figure(self, *args, **kwargs)

NavigationToolbar2.save_figure = new_save

Having actually created a figure, I can get a bound method for save_figure:

get_current_fig_manager().toolbar.save_figure()

This I can override, and call my override function successfully from my script - but pressing the save button on the toolbar doesn’t call my function…

I’m running matplotlib 1.1.1rc and python 2.7.3

Thanks,

Will

···

On Wed, Apr 10, 2013 at 11:55 AM, Willw <will.woods2@…287…> wrote:

I’m trying to override the behaviour of the toolbar, with partial success.

This works:

…but this doesn’t:

Having actually created a figure, I can get a bound method for save_figure:

This I can override, and call my override function successfully from my

script - but pressing the save button on the toolbar doesn’t call my

function…

I’m running matplotlib 1.1.1rc and python 2.7.3

Thanks,

Will

View this message in context: http://matplotlib.1069221.n5.nabble.com/Overriding-Save-button-on-Toolbar-tp40864.html

Sent from the matplotlib - users mailing list archive at Nabble.com.


Precog is a next-generation analytics platform capable of advanced

analytics on semi-structured data. The platform includes APIs for building

apps and a phenomenal toolset for data science. Developers can use

our toolset for easy data analysis & visualization. Get a free account!

http://www2.precog.com/precogplatform/slashdotnewsletter


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Answering my own question - the solution is to add a binding to the save button, and prevent the event from propagating after calling new_save() by adding ‘return “break”’ at the end:

def new_save(self, *args, **kwargs):
print ‘save_figure pressed’
return “break”

get_current_fig_manager().toolbar.bsave.bind(’’, new_save)

I would still like to know why the mechanism that works for the Home button fails for the Save button though…

Will

···

On Wed, Apr 10, 2013 at 12:00 PM, Will Woods <will.woods2@…287…> wrote:

Hmm, problems with html, will try again in plain text:

I’m trying to override the behaviour of the toolbar, with partial success.

This works:

from matplotlib.backend_bases import NavigationToolbar2

home = NavigationToolbar2.home

def new_home(self, *args, **kwargs):
print ‘home pressed’
home(self, *args, **kwargs)

NavigationToolbar2.home = new_home

…but this doesn’t:

from matplotlib.backend_bases import NavigationToolbar2

save_figure = NavigationToolbar2.save_figure

def new_save(self, *args, **kwargs):
print ‘save_figure pressed’
save_figure(self, *args, **kwargs)

NavigationToolbar2.save_figure = new_save

Having actually created a figure, I can get a bound method for save_figure:

get_current_fig_manager().toolbar.save_figure()

This I can override, and call my override function successfully from my script - but pressing the save button on the toolbar doesn’t call my function…

I’m running matplotlib 1.1.1rc and python 2.7.3

Thanks,

Will

On Wed, Apr 10, 2013 at 11:55 AM, Willw <will.woods2@…287…> wrote:

I’m trying to override the behaviour of the toolbar, with partial success.

This works:

…but this doesn’t:

Having actually created a figure, I can get a bound method for save_figure:

This I can override, and call my override function successfully from my

script - but pressing the save button on the toolbar doesn’t call my

function…

I’m running matplotlib 1.1.1rc and python 2.7.3

Thanks,

Will

View this message in context: http://matplotlib.1069221.n5.nabble.com/Overriding-Save-button-on-Toolbar-tp40864.html

Sent from the matplotlib - users mailing list archive at Nabble.com.


Precog is a next-generation analytics platform capable of advanced

analytics on semi-structured data. The platform includes APIs for building

apps and a phenomenal toolset for data science. Developers can use

our toolset for easy data analysis & visualization. Get a free account!

http://www2.precog.com/precogplatform/slashdotnewsletter


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users