~ubuntu-branches/ubuntu/utopic/python-chaco/utopic

« back to all changes in this revision

Viewing changes to examples/demo/canvas/cliptest.py

  • Committer: Package Import Robot
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2014-06-01 17:04:08 UTC
  • mfrom: (7.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20140601170408-m86xvdjd83a4qon0
Tags: 4.4.1-1ubuntu1
* Merge from Debian unstable. Remaining Ubuntu changes:
 - Let the binary-predeb target work on the usr/lib/python* directory
   as we don't have usr/share/pyshared anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
"""
3
 
The main app for the PlotCanvas application
4
 
"""
5
 
 
6
 
# Enthought library imports
7
 
from traits.api import Float
8
 
from enable.api import Window, Container, Component, Pointer
9
 
from enable.tools.api import MoveTool
10
 
from enable.example_support import DemoFrame, demo_main
11
 
 
12
 
 
13
 
class Box(Component):
14
 
    """
15
 
    The box moves wherever the user clicks and drags.
16
 
    """
17
 
    normal_pointer = Pointer("arrow")
18
 
    moving_pointer = Pointer("hand")
19
 
 
20
 
    offset_x = Float
21
 
    offset_y = Float
22
 
 
23
 
    fill_color = (0.8, 0.0, 0.1, 1.0)
24
 
    moving_color = (0.0, 0.8, 0.1, 1.0)
25
 
 
26
 
    resizable = ""
27
 
 
28
 
    def __init__(self, *args, **kw):
29
 
        Component.__init__(self, *args, **kw)
30
 
 
31
 
    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
32
 
        with gc:
33
 
            gc.set_fill_color(self.fill_color)
34
 
            dx, dy = self.bounds
35
 
            x, y = self.position
36
 
            gc.clip_to_rect(x, y, dx, dy)
37
 
            gc.rect(x, y, dx, dy)
38
 
            gc.fill_path()
39
 
 
40
 
            ## draw line around outer box
41
 
            #gc.set_stroke_color((0,0,0,1))
42
 
            #gc.rect(self.outer_x, self.outer_y, self.outer_width, self.outer_height)
43
 
            #gc.stroke_path()
44
 
 
45
 
        return
46
 
 
47
 
    def normal_left_down(self, event):
48
 
        self.event_state = "moving"
49
 
        event.window.set_pointer(self.moving_pointer)
50
 
        event.window.set_mouse_owner(self, event.net_transform())
51
 
        self.offset_x = event.x - self.x
52
 
        self.offset_y = event.y - self.y
53
 
        event.handled = True
54
 
        return
55
 
 
56
 
    def moving_mouse_move(self, event):
57
 
        self.position = [event.x-self.offset_x, event.y-self.offset_y]
58
 
        event.handled = True
59
 
        self.request_redraw()
60
 
        return
61
 
 
62
 
    def moving_left_up(self, event):
63
 
        self.event_state = "normal"
64
 
        event.window.set_pointer(self.normal_pointer)
65
 
        event.window.set_mouse_owner(None)
66
 
        event.handled = True
67
 
        self.request_redraw()
68
 
        return
69
 
 
70
 
    def moving_mouse_leave(self, event):
71
 
        self.moving_left_up(event)
72
 
        event.handled = True
73
 
        return
74
 
 
75
 
class MainFrame(DemoFrame):
76
 
    def _create_window(self):
77
 
        a = Box(bounds=[75, 75], position=[50,50], fill_color=(1, 0, 0, 1))
78
 
        b = Box(bounds=[75, 75], position=[200,50], fill_color=(0, 1, 0, 1))
79
 
        c = Box(bounds=[75, 75], position=[50,200], fill_color=(0, 0, 1, 1))
80
 
        cont = Container(a, b, c, bounds=[400,400], border_visible=True, bgcolor="lightgray")
81
 
        #cont.unified_draw = True
82
 
        #cont.draw_layer = "background"
83
 
        cont2 = Container(bounds=[300,300], border_visible=True, bgcolor="cyan")
84
 
        cont.tools.append(MoveTool(cont, drag_button="left"))
85
 
        cont2.tools.append(MoveTool(cont2, drag_button="left"))
86
 
        outer = Container(cont, cont2, fit_window=True)
87
 
        return Window(self, -1, component=outer)
88
 
 
89
 
 
90
 
if __name__ == "__main__":
91
 
    demo_main(MainFrame, size=(800,800), title="ClipTest")
92