Chaco ToolbarPlot: change default toolbar

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Chaco ToolbarPlot: change default toolbar

Barth
Dear all,

I need to include a toolbar in my plots, in such a way that i can save the
plot, retrieve the data ( and later save them in a certain format),...

I therefore use the ToolbarPlot class, which has a default toolbar, and try
to incude an extra button, defined in the class SaveToDataFormat

The code is the following:

from enthought.chaco.toolbar_plot import ToolbarPlot
from chaco.tools.toolbars.plot_toolbar import PlotToolbar
from modules.additional_buttons import SaveToDataFormat

plotdata = ArrayPlotData(x=x, y=y)
plot = ToolbarPlot(plotdata)
plot.toolbar.add_button(SaveToQtData())

But this makes that the extra button is added outside the toolbar, that i
already full with the default buttons.

My question is: how can i remove unnecessary buttons from this toolbar ? And
how can i redraw the toolbar such as to have the extra buttons within the
toolbar ?
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco ToolbarPlot: change default toolbar

Adam Hughes
One way is to go into the source code and alter the ToolbarPlot object
itself.  There may be a better way hopefully someone will know of.

On Fri, Feb 3, 2012 at 10:01 AM, Pierre Barthelemy <[hidden email]>wrote:

> Dear all,
>
> I need to include a toolbar in my plots, in such a way that i can save the
> plot, retrieve the data ( and later save them in a certain format),...
>
> I therefore use the ToolbarPlot class, which has a default toolbar, and try
> to incude an extra button, defined in the class SaveToDataFormat
>
> The code is the following:
>
> from enthought.chaco.toolbar_plot import ToolbarPlot
> from chaco.tools.toolbars.plot_toolbar import PlotToolbar
> from modules.additional_buttons import SaveToDataFormat
>
> plotdata = ArrayPlotData(x=x, y=y)
> plot = ToolbarPlot(plotdata)
> plot.toolbar.add_button(SaveToQtData())
>
> But this makes that the extra button is added outside the toolbar, that i
> already full with the default buttons.
>
> My question is: how can i remove unnecessary buttons from this toolbar ?
> And
> how can i redraw the toolbar such as to have the extra buttons within the
> toolbar ?
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco ToolbarPlot: change default toolbar

Jonathan Rocher
In reply to this post by Barth
Hi Pierre,

Here is the strategy:
1. Create the buttons that you want
2. Create the toolbar that contains the buttons you want. For example

from chaco.tools.toolbars.toolbar_buttons import IndexAxisLogButton,\
        ValueAxisLogButton, SaveAsButton, CopyToClipboardButton, \
        ZoomResetButton
class MyToolbar(PlotToolbar):
    buttons = [ IndexAxisLogButton, ValueAxisLogButton,
                 SaveAsButton, CopyToClipboardButton, ZoomResetButton]

3. Create the ToolbarPlot with your custom toolbar
class MyPlot(HasTraits):
    toolbar_class = Type(MyPlotToolbar)
    plot = Instance(ToolbarPlot)
    plot_data = Instance(ArrayPlotData)

    def __init__(self):
        self.plot_data = ArrayPlotData(x=x, y=y)
        self.plot = ToolbarPlot(self.plot_data,
                                toolbar_class=self.toolbar_class)

HTH,
Jonathan

On Fri, Feb 3, 2012 at 9:01 AM, Pierre Barthelemy <[hidden email]> wrote:

> Dear all,
>
> I need to include a toolbar in my plots, in such a way that i can save the
> plot, retrieve the data ( and later save them in a certain format),...
>
> I therefore use the ToolbarPlot class, which has a default toolbar, and try
> to incude an extra button, defined in the class SaveToDataFormat
>
> The code is the following:
>
> from enthought.chaco.toolbar_plot import ToolbarPlot
> from chaco.tools.toolbars.plot_toolbar import PlotToolbar
> from modules.additional_buttons import SaveToDataFormat
>
> plotdata = ArrayPlotData(x=x, y=y)
> plot = ToolbarPlot(plotdata)
> plot.toolbar.add_button(SaveToQtData())
>
> But this makes that the extra button is added outside the toolbar, that i
> already full with the default buttons.
>
> My question is: how can i remove unnecessary buttons from this toolbar ?
> And
> how can i redraw the toolbar such as to have the extra buttons within the
> toolbar ?
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
>



--
Jonathan Rocher, PhD
Scientific software developer
Enthought, Inc.
[hidden email]
1-512-536-1057
http://www.enthought.com
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Chaco ToolbarPlot: change default toolbar

Jonathan Rocher
Note the typo in my previous code:
toolbar_class = Type(MyPlotToolbar)
should be replaced by
toolbar_class = Type(MyToolbar)

Also about the creation of the button, your button needs to derive from
from chaco.tools.toolbars.toolbar_buttons import ToolbarButton

and should define the 'label' and 'image' attributes as well as the
'__init__' and 'perform' methods. Finally from within these methods, the
plot instance can be accessed as self.container.

Jonathan

On Fri, Feb 3, 2012 at 9:37 AM, Jonathan Rocher <[hidden email]>wrote:

> Hi Pierre,
>
> Here is the strategy:
> 1. Create the buttons that you want
> 2. Create the toolbar that contains the buttons you want. For example
>
> from chaco.tools.toolbars.toolbar_buttons import IndexAxisLogButton,\
>         ValueAxisLogButton, SaveAsButton, CopyToClipboardButton, \
>         ZoomResetButton
> class MyToolbar(PlotToolbar):
>     buttons = [ IndexAxisLogButton, ValueAxisLogButton,
>                  SaveAsButton, CopyToClipboardButton, ZoomResetButton]
>
> 3. Create the ToolbarPlot with your custom toolbar
> class MyPlot(HasTraits):
>     toolbar_class = Type(MyPlotToolbar)
>     plot = Instance(ToolbarPlot)
>     plot_data = Instance(ArrayPlotData)
>
>     def __init__(self):
>         self.plot_data = ArrayPlotData(x=x, y=y)
>         self.plot = ToolbarPlot(self.plot_data,
>                                 toolbar_class=self.toolbar_class)
>
> HTH,
> Jonathan
>
>
> On Fri, Feb 3, 2012 at 9:01 AM, Pierre Barthelemy <[hidden email]>wrote:
>
>> Dear all,
>>
>> I need to include a toolbar in my plots, in such a way that i can save the
>> plot, retrieve the data ( and later save them in a certain format),...
>>
>> I therefore use the ToolbarPlot class, which has a default toolbar, and
>> try
>> to incude an extra button, defined in the class SaveToDataFormat
>>
>> The code is the following:
>>
>> from enthought.chaco.toolbar_plot import ToolbarPlot
>> from chaco.tools.toolbars.plot_toolbar import PlotToolbar
>> from modules.additional_buttons import SaveToDataFormat
>>
>> plotdata = ArrayPlotData(x=x, y=y)
>> plot = ToolbarPlot(plotdata)
>> plot.toolbar.add_button(SaveToQtData())
>>
>> But this makes that the extra button is added outside the toolbar, that i
>> already full with the default buttons.
>>
>> My question is: how can i remove unnecessary buttons from this toolbar ?
>> And
>> how can i redraw the toolbar such as to have the extra buttons within the
>> toolbar ?
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>
>
>
> --
> Jonathan Rocher, PhD
> Scientific software developer
> Enthought, Inc.
> [hidden email]
> 1-512-536-1057
> http://www.enthought.com
>
>


--
Jonathan Rocher, PhD
Scientific software developer
Enthought, Inc.
[hidden email]
1-512-536-1057
http://www.enthought.com
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev