~ubuntu-branches/ubuntu/vivid/python-chaco/vivid-proposed

« back to all changes in this revision

Viewing changes to enthought/chaco/toolbar_plot.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2010-02-28 14:05:25 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100228140525-1eo43ddoakb2j3j9
Tags: 3.3.0-1
* New upstream release
* Switch to source format 3.0 (quilt)
* Bump Standards-Version to 3.8.4
* Remove transition package: python-enthought-chaco2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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, \
 
4
        on_trait_change
 
5
 
 
6
class ToolbarPlot(Plot):
 
7
    # Should we turn on the auto-hide feature on the toolbar?
 
8
    auto_hide = DelegatesTo('toolbar')
 
9
 
 
10
    toolbar = Instance(PlotToolbar)
 
11
 
 
12
    toolbar_class = Type(PlotToolbar)
 
13
    toolbar_added = False
 
14
 
 
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')
 
21
 
 
22
    def __init__(self, *args, **kw):
 
23
        super(ToolbarPlot, self).__init__(*args, **kw)
 
24
        
 
25
        self.toolbar.component = self
 
26
        self.add_toolbar()
 
27
        
 
28
    def _toolbar_default(self):
 
29
        return self.toolbar_class(self, location=self.toolbar_location)
 
30
        
 
31
    def add_toolbar(self):
 
32
        if not self.toolbar_added:
 
33
            self.overlays.append(self.toolbar)
 
34
            self.toolbar_added = True
 
35
            self.request_redraw()
 
36
 
 
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
 
41
            self.request_redraw()
 
42
            
 
43
    def _bounds_changed(self, old, new):
 
44
        self.toolbar.do_layout(force=True)
 
45
        super(ToolbarPlot, self)._bounds_changed(old, new)
 
46
 
 
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
 
52
            
 
53
            self.overlays.remove(old)
 
54
            self.toolbar_added = False
 
55
            self.add_toolbar()