~ubuntu-branches/ubuntu/trusty/python-enable/trusty

« back to all changes in this revision

Viewing changes to examples/enable/filled_container_demo.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2010-10-17 23:10:41 UTC
  • mto: (1.2.1 upstream) (8.1.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20101017231041-rziowhgl7zhxra2i
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
the container stretches to the minimum bounding box of its components
10
10
as the user drags the circles around.
11
11
"""
 
12
 
 
13
from __future__ import with_statement
 
14
 
12
15
from numpy import array
13
16
 
14
17
from enthought.enable.example_support import DemoFrame, demo_main
30
33
        if not self._font:
31
34
            self._font = str_to_font(None, None, "modern 10")
32
35
 
33
 
        gc.save_state()
34
 
        gc.set_fill_color(self.bgcolor_)
35
 
        gc.rect(self.x, self.y, self.width, self.height)
36
 
        gc.draw_path()
37
 
        self._draw_border(gc)
38
 
        gc.set_font(self._font)
39
 
        gc.set_fill_color((1.0, 1.0, 1.0, 1.0))
40
 
        tx, ty, tw, th = gc.get_text_extent("Container")
41
 
        tx = self.x + self.width/2.0 - tw/2.0
42
 
        ty = self.y + self.height/2.0 - th/2.0
43
 
        gc.show_text_at_point("Container", tx, ty)
44
 
        gc.restore_state()
 
36
        with gc:
 
37
            gc.set_fill_color(self.bgcolor_)
 
38
            gc.rect(self.x, self.y, self.width, self.height)
 
39
            gc.draw_path()
 
40
            self._draw_border(gc)
 
41
            gc.set_font(self._font)
 
42
            gc.set_fill_color((1.0, 1.0, 1.0, 1.0))
 
43
            tx, ty, tw, th = gc.get_text_extent("Container")
 
44
            tx = self.x + self.width/2.0 - tw/2.0
 
45
            ty = self.y + self.height/2.0 - th/2.0
 
46
            gc.show_text_at_point("Container", tx, ty)
 
47
 
45
48
        return
46
49
 
47
50
 
71
74
        return
72
75
 
73
76
    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
74
 
        gc.save_state()
75
 
        gc.set_fill_color(self.color)
76
 
        dx, dy = self.bounds
77
 
        x, y = self.position
78
 
        radius = min(dx/2.0, dy/2.0)
79
 
        gc.arc(x+dx/2.0, y+dy/2.0, radius, 0.0, 2*3.14159)
80
 
        gc.fill_path()
81
 
        gc.restore_state()
 
77
        with gc:
 
78
            gc.set_fill_color(self.color)
 
79
            dx, dy = self.bounds
 
80
            x, y = self.position
 
81
            radius = min(dx/2.0, dy/2.0)
 
82
            gc.arc(x+dx/2.0, y+dy/2.0, radius, 0.0, 2*3.14159)
 
83
            gc.fill_path()
82
84
        return
83
85
 
84
86
    def normal_left_down(self, event):
129
131
    resizable = ""
130
132
 
131
133
    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
132
 
        gc.save_state()
133
 
        gc.set_fill_color(self.color[0:3] + (self.color[3]*0.3,))
134
 
        dx, dy = self.bounds
135
 
        x, y = self.position
136
 
        radius = min(dx/2.0, dy/2.0)
137
 
        gc.arc(x+dx/2.0, y+dy/2.0, radius, 0.0, 2*3.14159)
138
 
        gc.fill_path()
139
 
        gc.restore_state()
 
134
        with gc:
 
135
            gc.set_fill_color(self.color[0:3] + (self.color[3]*0.3,))
 
136
            dx, dy = self.bounds
 
137
            x, y = self.position
 
138
            radius = min(dx/2.0, dy/2.0)
 
139
            gc.arc(x+dx/2.0, y+dy/2.0, radius, 0.0, 2*3.14159)
 
140
            gc.fill_path()
140
141
        return
141
142
 
142
143
class DashedCircle(Component):
148
149
    resizable = ""
149
150
 
150
151
    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
151
 
        gc.save_state()
152
 
        gc.set_fill_color(self.color)
153
 
        dx, dy = self.bounds
154
 
        x, y = self.position
155
 
        radius = min(dx/2.0, dy/2.0)
156
 
        gc.arc(x+dx/2.0, y+dy/2.0, radius, 0.0, 2*3.14159)
157
 
        gc.set_stroke_color(self.color[0:3] + (self.color[3]*0.8,))
158
 
        gc.set_line_dash(self.line_dash)
159
 
        gc.stroke_path()
160
 
        gc.restore_state()
 
152
        with gc:
 
153
            gc.set_fill_color(self.color)
 
154
            dx, dy = self.bounds
 
155
            x, y = self.position
 
156
            radius = min(dx/2.0, dy/2.0)
 
157
            gc.arc(x+dx/2.0, y+dy/2.0, radius, 0.0, 2*3.14159)
 
158
            gc.set_stroke_color(self.color[0:3] + (self.color[3]*0.8,))
 
159
            gc.set_line_dash(self.line_dash)
 
160
            gc.stroke_path()
161
161
        return
162
162
 
163
163