Changeset 1196
- Timestamp:
- 04/05/07 01:23:17 (2 years ago)
- Files:
-
- gaphas/trunk/demo.py (modified) (3 diffs)
- gaphas/trunk/gaphas/examples.py (modified) (2 diffs)
- gaphas/trunk/gaphas/tool.py (modified) (1 diff)
- gaphas/trunk/gaphas/util.py (modified) (2 diffs)
- gaphas/trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/trunk/demo.py
r1185 r1196 30 30 from gaphas.painter import ItemPainter 31 31 from gaphas import state 32 from gaphas.util import text_extents 32 33 33 34 # Global undo list … … 65 66 66 67 class MyText(Text): 67 """Text with experimental connection protocol.68 68 """ 69 pass 69 Text with experimental connection protocol. 70 """ 71 72 def draw(self, context): 73 Text.draw(self, context) 74 cr = context.cairo 75 w, h = text_extents(cr, self.text, multiline=self.multiline) 76 cr.rectangle(0, 0, w, h) 77 cr.set_source_rgba(.3, .3, 1., .6) 78 cr.stroke() 70 79 71 80 … … 306 315 l.orthogonal = True 307 316 308 t=MyText( )317 t=MyText('Single line') 309 318 t.matrix.translate(70,70) 319 c.add(t) 320 321 off_y = 0 322 for align_x in (-1, 0, 1): 323 for align_y in (-1, 0, 1): 324 t=MyText('Aligned text %d/%d' % (align_x, align_y), 325 align_x=align_x, align_y=align_y) 326 t.matrix.translate(120, 200 + off_y) 327 off_y += 30 328 c.add(t) 329 330 t=MyText('Multiple\nlines', multiline = True) 331 t.matrix.translate(70,100) 310 332 c.add(t) 311 333 gaphas/trunk/gaphas/examples.py
r1145 r1196 12 12 from constraint import LineConstraint 13 13 from geometry import point_on_rectangle, distance_rectangle_point 14 from util import text_extents, text_align, text_multiline 14 15 15 16 class Box(Element): … … 50 51 51 52 class Text(Item): 52 """Simple item shoring some text on the canvas. 53 """ 54 Simple item showing some text on the canvas. 53 55 """ 54 56 55 def __init__(self ):57 def __init__(self, text=None, plain=False, multiline=False, align_x=1, align_y=-1): 56 58 super(Text, self).__init__() 59 self.text = text is None and 'Hello' or text 60 self.plain = plain 61 self.multiline = multiline 62 self.align_x = align_x 63 self.align_y = align_y 57 64 58 65 def draw(self, context): 59 66 #print 'Text.draw', self 60 c = context.cairo 61 c.show_text('Hello') 67 cr = context.cairo 68 if self.multiline: 69 text_multiline(cr, 0, 0, self.text) 70 elif self.plain: 71 cr.show_text(self.text) 72 else: 73 text_align(cr, 0, 0, self.text, self.align_x, self.align_y) 62 74 context.draw_children() 63 75 gaphas/trunk/gaphas/tool.py
r1183 r1196 445 445 finally: 446 446 # Decrement handle strength, previously incremented on button press 447 self._grabbed_handle.x.strength -= 1 448 self._grabbed_handle.y.strength -= 1 447 if self._grabbed_handle: 448 self._grabbed_handle.x.strength -= 1 449 self._grabbed_handle.y.strength -= 1 449 450 context.view.queue_draw_item(context.view.hovered_item, handles=True) 450 451 context.ungrab() gaphas/trunk/gaphas/util.py
r1133 r1196 36 36 def text_align(cr, x, y, text, align_x=0, align_y=0, padding_x=0, padding_y=0): 37 37 """ 38 Draw text using (x, y) as center. 39 x - center x 40 y - center y 38 Draw text relative to (x, y). 39 x, y - coordinates 41 40 text - text to print (utf8) 42 41 align_x - -1 (top), 0 (middle), 1 (bottom) … … 77 76 for line in text.split('\n'): 78 77 x_bear, y_bear, w, h, x_adv, y_adv = cr.text_extents(text) 78 y += h 79 79 cr.move_to(x, y) 80 80 cr.show_text(line) 81 y += h + padding82 81 83 82 def text_set_font(cr, font): gaphas/trunk/setup.py
r1165 r1196 8 8 setup( 9 9 name='gaphas', 10 version='0.1. 3',10 version='0.1.4', 11 11 description='Gaphas is a GTK+ based diagramming widget', 12 12 long_description="""\
