root/gaphor/tags/gaphor-0.3.0/gaphor/diagram/actor.py

Revision 215, 3.8 kB (checked in by arjanmol, 5 years ago)

*** empty log message ***

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 '''
2 ActorItem diagram item
3 '''
4 # vim:sw=4
5
6 from __future__ import generators
7
8 import gobject
9 import pango
10 import diacanvas
11
12 import gaphor.UML as UML
13 from gaphor.diagram import initialize_item
14
15 from classifier import ClassifierItem
16
17 class ActorItem(ClassifierItem):
18     HEAD=11
19     ARM=19
20     NECK=10
21     BODY=20
22
23     __gproperties__ = {
24         'name-width':        (gobject.TYPE_DOUBLE, 'name width',
25                          '', 0.0, 10000.0,
26                          1, gobject.PARAM_READWRITE),
27     }
28
29     def __init__(self, id=None):
30         ClassifierItem.__init__(self, id)
31         self.set(height=(ActorItem.HEAD + ActorItem.NECK + ActorItem.BODY + ActorItem.ARM),
32                  width=(ActorItem.ARM * 2),
33                  min_height=(ActorItem.HEAD + ActorItem.NECK + ActorItem.BODY + ActorItem.ARM),
34                  min_width=(ActorItem.ARM * 2))
35         # Head
36         self._head = diacanvas.shape.Ellipse()
37         self._head.set_line_width(2.0)
38         # Body
39         self._body = diacanvas.shape.Path()
40         self._body.set_line_width(2.0)
41         # Arm
42         self._arms = diacanvas.shape.Path()
43         self._arms.set_line_width(2.0)
44         # Legs
45         self._legs = diacanvas.shape.Path()
46         self._legs.set_line_width(2.0)
47
48     def save (self, save_func):
49         ClassifierItem.save(self, save_func)
50         #self.save_property(save_func, 'name-width')
51
52     def do_set_property (self, pspec, value):
53         #print 'Actor: Trying to set property', pspec.name, value
54         if pspec.name == 'name-width':
55             #self._name.set_property('width', value)
56             pass
57         else:
58             ClassifierItem.do_set_property (self, pspec, value)
59
60     def do_get_property(self, pspec):
61         if pspec.name == 'name-width':
62             #w, h = self.get_name_size()
63             return 0.0
64         else:
65             return ClassifierItem.do_get_property (self, pspec)
66
67     # DiaCanvasItem callbacks:
68
69     def on_update(self, affine):
70         # Center the text (from ClassifierItem):
71         w, h = self.get_name_size()
72         if w < self.width:
73             w = self.width
74         self.update_name(x=(self.width - w) / 2, y=self.height,
75                          width=w, height=h)
76
77         ClassifierItem.on_update(self, affine)
78
79         # scaling factors (also compenate the line width):
80         fx = self.width / (ActorItem.ARM * 2 + 2);
81         fy = self.height / (ActorItem.HEAD + ActorItem.NECK + ActorItem.BODY + ActorItem.ARM + 2);
82         self._head.ellipse((ActorItem.ARM * fx, (ActorItem.HEAD / 2) * fy),
83                             ActorItem.HEAD * fx, ActorItem.HEAD * fy)
84         self._body.line(((ActorItem.ARM * fx, ActorItem.HEAD * fy),
85                          (ActorItem.ARM * fx, (ActorItem.HEAD
86                           + ActorItem.NECK + ActorItem.BODY) * fy)))
87         self._arms.line(((0, (ActorItem.HEAD + ActorItem.NECK) * fy),
88                          (ActorItem.ARM * 2 * fx,
89                           (ActorItem.HEAD + ActorItem.NECK) * fy)))
90         self._legs.line(((0, (ActorItem.HEAD + ActorItem.NECK
91                                + ActorItem.BODY + ActorItem.ARM) * fy),
92                           (ActorItem.ARM * fx,
93                            (ActorItem.HEAD + ActorItem.NECK + ActorItem.BODY) * fy),
94                           (ActorItem.ARM * 2 * fx, (ActorItem.HEAD + ActorItem.NECK + ActorItem.BODY + ActorItem.ARM) * fy)))
95         # update the bounding box:
96         ulx, uly, lrx, lry = self.bounds
97         #w, h = self._name.get_property('layout').get_pixel_size()
98         if w > self.width:
99             ulx = (self.width / 2) - (w / 2)
100             lrx = (self.width / 2) + (w / 2)
101         self.set_bounds ((ulx, uly-1, lrx+1, lry + h))
102
103     def on_shape_iter(self):
104         yield self._head
105         yield self._body
106         yield self._arms
107         yield self._legs
108         for s in ClassifierItem.on_shape_iter(self):
109             yield s
110
111 initialize_item(ActorItem, UML.Actor)
Note: See TracBrowser for help on using the browser.