root/gaphor/tags/gaphor-0.12.5/gaphor/diagram/comment.py

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

renamed update() to post_update() for all diagram items.

  • 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
24     def edit(self):
25         #self.start_editing(self._body)
26         pass
27
28     def on_subject_notify(self, pspec):
29         """
30         See DiagramItem.on_subject_notify().
31         """
32         ElementItem.on_subject_notify(self, pspec, ('body',))
33         self.request_update()
34
35     def on_subject_notify__body(self, subject, pspec):
36         self.request_update()
37
38     # DiaCanvasItem callbacks:
39
40     def pre_update(self, context):
41         if not self.subject: return
42         cr = context.cairo
43         w, h = text_extents(cr, self.subject.body, multiline=True, padding=2)
44         self.min_width = w + 10
45         self.min_height = h + 10
46         ElementItem.pre_update(self, context)
47
48     def post_update(self, context):
49         ElementItem.post_update(self, context)
50
51     def draw(self, context):
52         if not self.subject: return
53         c = context.cairo
54         # Width and height, adjusted for line width...
55         ox = float(self._handles[NW].x)
56         oy = float(self._handles[NW].y)
57         w = self.width + ox
58         h = self.height + oy
59         ear = CommentItem.EAR
60         c.move_to(w - ear, oy)
61         line_to = c.line_to
62         line_to(w - ear, oy + ear)
63         line_to(w, oy + ear)
64         line_to(w - ear, oy)
65         line_to(ox, oy)
66         line_to(ox, h)
67         line_to(w, h)
68         line_to(w, oy + ear)
69         c.stroke()
70         if self.subject.body:
71             # Do not print empty string, since cairo-win32 can't handle it.
72             text_multiline(c, 5, 5, self.subject.body, padding=2)
73             #c.move_to(10, 15)
74             #c.show_text(self.subject.body)
75
76 # vim:sw=4
Note: See TracBrowser for help on using the browser.