1
from enthought.chaco.api import Plot
2
from enthought.chaco.tools.toolbars.plot_toolbar import PlotToolbar
3
from enthought.traits.api import Type, DelegatesTo, Instance, Enum, \
6
class ToolbarPlot(Plot):
7
# Should we turn on the auto-hide feature on the toolbar?
8
auto_hide = DelegatesTo('toolbar')
10
toolbar = Instance(PlotToolbar)
12
toolbar_class = Type(PlotToolbar)
15
# Location of the default toolbar that is created if a toolbar
16
# is not specified with the `toolbar` attribute. Changing this
17
# attribute after the ToolbarPlot instance is created has no effect;
18
# use obj.toolbar.location to dynamically change the location of the
19
# instance `obj`s toolbar.
20
toolbar_location = Enum('top', 'right', 'bottom', 'left')
22
def __init__(self, *args, **kw):
23
super(ToolbarPlot, self).__init__(*args, **kw)
25
self.toolbar.component = self
28
def _toolbar_default(self):
29
return self.toolbar_class(self, location=self.toolbar_location)
31
def add_toolbar(self):
32
if not self.toolbar_added:
33
self.overlays.append(self.toolbar)
34
self.toolbar_added = True
37
def remove_toolbar(self):
38
if self.toolbar_added and self.auto_hide:
39
self.overlays.remove(self.toolbar)
40
self.toolbar_added = False
43
def _bounds_changed(self, old, new):
44
self.toolbar.do_layout(force=True)
45
super(ToolbarPlot, self)._bounds_changed(old, new)
47
@on_trait_change('toolbar')
48
def _toolbar_changed(self, name, obj, old, new):
49
if self.toolbar_added:
50
# fixup the new toolbar's component to match the old one
51
new.component = old.component
53
self.overlays.remove(old)
54
self.toolbar_added = False