2
from __future__ import with_statement
4
from enable.api import Component
5
from traits.api import Enum, Float, Instance, Trait, Tuple
7
from chaco.api import AbstractOverlay, BasePlotContainer
10
class TransientPlotOverlay(BasePlotContainer, AbstractOverlay):
11
""" Allows an arbitrary plot component to be overlaid on top of another one.
14
# The PlotComponent to draw as an overlay
15
overlay_component = Instance(Component)
17
# Where this overlay should draw relative to our .component
18
align = Enum("right", "left", "top", "bottom")
20
# The amount of space between the overlaying component and the underlying
21
# one. This is either horizontal or vertical (depending on the value of
22
# self.align), but is not both.
25
# An offset to apply in X and Y
26
offset = Trait(None, None, Tuple)
28
# Override default values of some inherited traits
32
def _bounds_default(self):
35
def _clear_bounds(self, gc, view_bounds):
36
if view_bounds is None:
37
view_bounds = (0,0, self.width, self.height)
38
gc.clip_to_rect(*view_bounds)
39
gc.set_fill_color((1.0,1.0,1.0,1.0))
44
def overlay(self, component, gc, view_bounds=None, mode="normal"):
47
self._clear_bounds(gc, view_bounds)
48
self.overlay_component._draw(gc, view_bounds, mode)
50
# TODO: Implement this more intelligently than the one in BasePlotContainer
51
#def get_preferred_size(self):
55
component = self.component
56
bounds = self.outer_bounds
58
if self.align in ("right", "left"):
59
y = component.outer_y -(bounds[1] - component.outer_height) / 2
60
if self.align == "right":
61
x = component.outer_x2 + self.margin
63
x = component.outer_x - bounds[0] - self.margin
65
else: # "top", "bottom"
66
x = component.outer_x -(bounds[0] - component.outer_width) / 2
67
if self.align == "top":
68
y = component.outer_y2 + self.margin
70
y = component.outer_y - bounds[1] - self.margin
72
if self.offset is not None:
76
overlay_component = self.overlay_component
77
overlay_component.outer_bounds = self.outer_bounds
78
overlay_component.outer_position = [x, y]
79
overlay_component._layout_needed = True
80
overlay_component.do_layout()
82
def dispatch(self, event, suffix):
83
if self.visible and self.overlay_component.is_in(event.x, event.y):
84
return self.overlay_component.dispatch(event, suffix)