root/gaphor/trunk/gaphor/diagram/comment.py

Revision 2120, 1.7 kB (checked in by arj..@yirdis.nl, 1 year ago)

Changed diagramitems to use the new notification system.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 """
2 CommentItem diagram item
3 """
4
5 from gaphor import UML
6 from elementitem import ElementItem
7 from gaphas.item import NW
8 from gaphas.util import text_multiline, text_extents
9
10
11 class CommentItem(ElementItem):
12
13     __uml__ = UML.Comment
14
15     EAR=15
16     OFFSET=5
17
18     def __init__(self, id=None):
19         ElementItem.__init__(self, id)
20         self.min_width = CommentItem.EAR + 2 * CommentItem.OFFSET
21         self.height = 50
22         self.width = 100
23         self.add_watch(UML.Comment.body)
24
25     def edit(self):
26         #self.start_editing(self._body)
27         pass
28
29     # DiaCanvasItem callbacks:
30
31     def pre_update(self, context):
32         if not self.subject: return
33         cr = context.cairo
34         w, h = text_extents(cr, self.subject.body, multiline=True, padding=2)
35         self.min_width = w + 10
36         self.min_height = h + 10
37         ElementItem.pre_update(self, context)
38
39     def post_update(self, context):
40         ElementItem.post_update(self, context)
41
42     def draw(self, context):
43         if not self.subject: return
44         c = context.cairo
45         # Width and height, adjusted for line width...
46         ox = float(self._handles[NW].x)
47         oy = float(self._handles[NW].y)
48         w = self.width + ox
49         h = self.height + oy
50         ear = CommentItem.EAR
51         c.move_to(w - ear, oy)
52         line_to = c.line_to
53         line_to(w - ear, oy + ear)
54         line_to(w, oy + ear)
55         line_to(w - ear, oy)
56         line_to(ox, oy)
57         line_to(ox, h)
58         line_to(w, h)
59         line_to(w, oy + ear)
60         c.stroke()
61         if self.subject.body:
62             # Do not print empty string, since cairo-win32 can't handle it.
63             text_multiline(c, 5, 5, self.subject.body, padding=2)
64             #c.move_to(10, 15)
65             #c.show_text(self.subject.body)
66
67 # vim:sw=4
Note: See TracBrowser for help on using the browser.