File: run.py

package info (click to toggle)
python-enable 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,280 kB
  • ctags: 13,899
  • sloc: cpp: 48,447; python: 28,502; ansic: 9,004; makefile: 315; sh: 44
file content (67 lines) | stat: -rw-r--r-- 1,812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
""" An example showing moveable shapes. """
# Enthought library imports.
from enable.api import Container, Window
from enable.example_support import DemoFrame, demo_main

# Local imports
from box import Box
from circle import Circle


class MyFrame(DemoFrame):
    """ The top-level frame. """

    # 'DemoFrame' interface.
    #--------------------------------------------------------------------------

    def _create_window(self):
        """ Create an enable window. """

        container = Container(
            auto_size=False, bgcolor='black', *self._create_shapes()
        )

        return Window(self, component=container)

    # Private interface.
    #--------------------------------------------------------------------------

    def _create_shapes(self):
        """ Create some shapes. """

        box1 = Box(
            bounds     = [100, 100],
            position   = [50, 50],
            fill_color = 'lightpink',
            text       = 'Box 1'
        )

        box2 = Box(
            bounds     = [100, 100],
            position   = [150, 150],
            fill_color = 'greenyellow',
            text       = 'Box 2'
        )

        circle1 = Circle(
            radius     = 50,
            position   = [250,250],
            fill_color = 'cornflowerblue',
            text       = 'Circle 1'
        )

        circle2 = Circle(
            radius     = 50,
            position   = [350,350],
            fill_color = 'khaki',
            text       = 'Circle 2'
        )

        return box1, box2, circle1, circle2


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(MyFrame, size=(500, 500),
                     title="Click and drag the shapes")