Changeset 1552
- Timestamp:
- 07/02/07 11:44:46 (1 year ago)
- Files:
-
- gaphas/branches/hw/demo.py (modified) (2 diffs)
- gaphas/branches/hw/gaphas/examples.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/branches/hw/demo.py
r1551 r1552 25 25 import cairo 26 26 from gaphas import Canvas, GtkView, View 27 from gaphas.examples import Box, Text, FatLine, DefaultExampleTool27 from gaphas.examples import Box, Text, FatLine, Circle, DefaultExampleTool 28 28 from gaphas.item import Line, NW, SE 29 29 from gaphas.tool import PlacementTool, HandleTool … … 310 310 h1.y = 50 311 311 fl.matrix.translate(50, 50) 312 fl.height = 50 312 313 c.add(fl) 313 fl.height = 50 314 fl.request_update() 314 315 316 circle = Circle() 317 h1, h2 = circle.handles() 318 h1.x = 50 319 h1.y = 150 320 h2.x = 50 321 h2.y = 80 322 circle.radius = 10 323 circle.matrix.translate(50, 150) 324 c.add(circle) 315 325 316 326 # bb=Box() gaphas/branches/hw/gaphas/examples.py
r1551 r1552 13 13 from constraint import BalanceConstraint, LessThanConstraint, EqualsConstraint 14 14 from geometry import point_on_rectangle, distance_rectangle_point 15 from util import text_extents, text_align, text_multiline 15 from util import text_extents, text_align, text_multiline, path_ellipse 16 16 17 17 class Box(Element): … … 117 117 cr.move_to(0, 0) 118 118 cr.line_to(0, self.height) 119 cr.stroke() 120 121 122 123 class Circle(Item): 124 def __init__(self): 125 super(Circle, self).__init__() 126 self._handles.extend((Handle(), Handle())) 127 128 129 def _set_radius(self, height): 130 h1, h2 = self._handles 131 return h1.y + height 132 133 134 def _get_radius(self): 135 h1, h2 = self._handles 136 return ((h2.x - h1.x) ** 2 + (h2.y - h1.y) ** 2) ** 0.5 137 138 139 radius = property(_get_radius, _set_radius) 140 141 142 def _get_pos(self): 143 h1, h2 = self._handles 144 x, y = h2.x - h1.x, h2.y - h1.y 145 if x > 0: 146 x = 0 147 if y > 0: 148 y = 0 149 return abs(x), abs(y) 150 151 152 pos = property(_get_pos) 153 154 155 def setup_canvas(self): 156 super(Circle, self).setup_canvas() 157 h1, h2 = self._handles 158 h1.movable = False 159 160 161 def draw(self, context): 162 cr = context.cairo 163 x, y = self.pos 164 path_ellipse(cr, x, y, 2 * self.radius, 2 * self.radius) 119 165 cr.stroke() 120 166
