Changeset 1116
- Timestamp:
- 01/11/07 06:26:48 (2 years ago)
- Files:
-
- gaphor/branches/new-canvas/gaphor/actions/itemactions.py (modified) (3 diffs)
- gaphor/branches/new-canvas/gaphor/adapters/connectors.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/adapters/editors.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/classifier.py (modified) (6 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/elementitem.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/interface.py (modified) (4 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/nameditem.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/style.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/tests/test_class.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/tests/test_interface.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/branches/new-canvas/gaphor/actions/itemactions.py
r1087 r1116 917 917 #log.debug('Action %s: %s' % (self.id, item.subject.name)) 918 918 919 item.drawing_style = item s.InterfaceItem.DRAW_ICON919 item.drawing_style = item.DRAW_ICON 920 920 921 921 register_action(FoldAction, 'ItemFocus') … … 932 932 #log.debug('Action %s: %s' % (self.id, item.subject.name)) 933 933 934 item.drawing_style = item s.InterfaceItem.DRAW_COMPARTMENT934 item.drawing_style = item.DRAW_COMPARTMENT 935 935 # Make sure lines are updated properly: 936 936 #item.canvas.update_now() … … 1162 1162 try: 1163 1163 item = get_parent_focus_item(self._window) 1164 self.active = isinstance(item, items.AssemblyConnectorItem) \ 1165 or isinstance(item, items.InterfaceItem) and item.is_folded() 1164 #self.active = isinstance(item, items.AssemblyConnectorItem) \ 1165 1166 self.active = isinstance(item, items.InterfaceItem) and item.is_folded() 1166 1167 except NoFocusItemError: 1167 1168 pass gaphor/branches/new-canvas/gaphor/adapters/connectors.py
r1115 r1116 733 733 734 734 # TODO: make element at head end update! 735 c1.request_update() 735 736 736 737 # Find all associations and determine if the properties on gaphor/branches/new-canvas/gaphor/adapters/editors.py
r1104 r1116 61 61 def update_text(self, text): 62 62 self._item.subject.name = text 63 self._item.request_update() 63 64 64 65 def key_pressed(self, pos, key): gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py
r1112 r1116 83 83 cr.set_line_width(2) 84 84 cr.stroke() 85 85 86 86 super(ActivityFinalNodeItem, self).draw(context) 87 87 gaphor/branches/new-canvas/gaphor/diagram/classifier.py
r1093 r1116 58 58 vspacing = self.owner.style.compartment_vspacing 59 59 self.height += vspacing * len(sizes) 60 margin = self.owner.style.compartment_margin61 self.width += margin[1] + margin[3]62 self.height += margin[0] + margin[2]60 padding = self.owner.style.compartment_padding 61 self.width += padding[1] + padding[3] 62 self.height += padding[0] + padding[2] 63 63 64 64 def update(self, context): … … 69 69 def draw(self, context): 70 70 cr = context.cairo 71 margin = self.owner.style.compartment_margin71 padding = self.owner.style.compartment_padding 72 72 vspacing = self.owner.style.compartment_vspacing 73 cr.translate( margin[1], margin[0])73 cr.translate(padding[1], padding[0]) 74 74 offset = 0 75 75 for item in self: … … 117 117 'min-size': (100, 50), 118 118 'icon-size': (20, 20), 119 'compartment-margin': (5, 5, 5, 5), # (top, right, bottom, left) 119 'from-padding': (7, 2, 7, 2), 120 'compartment-padding': (5, 5, 5, 5), # (top, right, bottom, left) 120 121 'compartment-vspacing': 2, 122 # Fix name, stereotype and from drawing! 123 'name-padding': (10, 10, 10, 10), 124 'stereotype-padding': (10, 10, 2, 10), 121 125 } 122 126 # Default size for small icons … … 262 266 s_w = s_h = 0 263 267 if self.stereotype: 264 s_w, s_h = text_extents(cr, self.stereotype) 265 n_w, n_h = text_extents(cr, self.subject.name) 268 s_w, s_h = 0, 0 #text_extents(cr, self.stereotype) 269 padding = self.style.stereotype_padding 270 s_w += padding[1] + padding[3] 271 s_h += padding[0] + padding[2] 272 273 n_w, n_h = 0, 0 #text_extents(cr, self.subject.name) 274 padding = self.style.name_padding 275 n_w += padding[1] + padding[3] 276 n_h += padding[0] + padding[2] 266 277 267 278 f_w, f_h = 0, 0 268 if self.subject.namespace: 269 f_w, f_h = text_extents(cr, self._from, font=font.FONT_SMALL) 279 if self._from: #self.subject.namespace: 280 f_w, f_h = 0, 0 #text_extents(cr, self._from, font=font.FONT_SMALL) 281 padding = self.style.from_padding 282 f_w += padding[1] + padding[3] 283 f_h += padding[0] + padding[2] 270 284 271 285 sizes = [comp.get_size() for comp in self._compartments] 272 286 self.update_name_size(context) 273 287 sizes.append(self.get_name_size()) 288 sizes.append((s_w, s_h)) 289 sizes.append((f_w, f_h)) 274 290 self.min_width = max(s_w, n_w, f_w) 275 291 self.min_height = 0 … … 292 308 293 309 def update_compartment(self, context): 294 """Update state for box-style presentation. 295 """ 296 pass 310 """ 311 Update state for box-style presentation. 312 """ 313 super(ClassifierItem, self).update(context) 297 314 298 315 def update_compartment_icon(self, context): 299 """Update state for box-style w/ small icon. 300 """ 301 pass 316 """ 317 Update state for box-style w/ small icon. 318 """ 319 super(ClassifierItem, self).update(context) 302 320 303 321 def update_icon(self, context): 304 322 """ 305 """ 306 pass 323 Update state for icon-only presentation. 324 """ 325 super(ClassifierItem, self).update(context) 307 326 308 327 def get_icon_pos(self): … … 326 345 327 346 # draw stereotype 328 y += 10329 347 if self.stereotype: 348 padding = self.style.stereotype_padding 349 y += padding[0] 330 350 text_set_font(cr, font.FONT) 331 351 text_center(cr, width / 2, y, self.stereotype) 352 y += padding[2] 332 353 333 354 # draw name 334 y += 10 355 padding = self.style.name_padding 356 y += padding[0] 357 n_w, n_h = text_extents(cr, self.subject.name) 335 358 text_set_font(cr, font.FONT_NAME) 336 text_center(cr, width / 2, y , self.subject.name)337 338 y += 10 359 text_center(cr, width / 2, y + n_h/2, self.subject.name) 360 y += padding[2] + n_h/2 361 339 362 # draw 'from ... ' 340 363 if self._from: 364 padding = self.style.from_padding 365 y += padding[0] 341 366 text_set_font(cr, font.FONT_SMALL) 342 367 text_center(cr, width / 2, y, self._from) 343 344 y += 5 368 y += padding[2] 369 345 370 cr.translate(0, y) 346 371 gaphor/branches/new-canvas/gaphor/diagram/elementitem.py
r1115 r1116 14 14 __style__ = { 15 15 'min-size': (0, 0), 16 'stereotype-padding': (5, 10, 5, 10), 16 17 } 17 18 gaphor/branches/new-canvas/gaphor/diagram/interface.py
r1070 r1116 9 9 from gaphor.diagram.dependency import DependencyItem 10 10 from gaphor.diagram.implementation import ImplementationItem 11 #from gaphor.diagram.interfaceicon import AssembledInterfaceIcon, \12 # ProvidedInterfaceIcon, RequiredInterfaceIcon13 11 from gaphor.diagram.klass import ClassItem 14 12 from gaphor.diagram.nameditem import NamedItem 15 13 from gaphor.diagram.rotatable import SimpleRotation 14 from gaphor.diagram.style import ALIGN_TOP, ALIGN_BOTTOM, ALIGN_CENTER 16 15 17 16 class InterfaceItem(ClassItem, SimpleRotation): 18 """This item represents an interface drawn as a dot. The class-like 17 """ 18 This item represents an interface drawn as a dot. The class-like 19 19 representation is provided by ClassItem. These representations can be 20 20 switched by using the Fold and Unfold actions. … … 33 33 'name-outside': False, 34 34 } 35 36 UNFOLDED_STYLE = { 37 'name-align': (ALIGN_CENTER, ALIGN_TOP), 38 'name-outside': False, 39 } 40 41 FOLDED_STYLE = { 42 'name-align': (ALIGN_CENTER, ALIGN_BOTTOM), 43 'name-outside': True, 44 } 45 35 46 RADIUS_PROVIDED = 10 36 47 RADIUS_REQUIRED = 14 … … 42 53 self._draw_provided = False 43 54 44 # self._ricon = RequiredInterfaceIcon(self) 45 # self._aicon = AssembledInterfaceIcon(self) 46 # self._picon = ProvidedInterfaceIcon(self) 47 # 48 # self._icon = self._aicon 55 def set_drawing_style(self, style): 56 """ 57 In addition to setting the drawing style, the handles are 58 make non-movable if the icon (folded) style is used. 59 """ 60 ClassItem.set_drawing_style(self, style) 61 # TODO: adjust offsets so the center point is the same 62 if self._drawing_style == self.DRAW_ICON: 63 self.style.update(self.FOLDED_STYLE) 64 self.request_update() 65 else: 66 self.style.update(self.UNFOLDED_STYLE) 67 self.request_update() 49 68 69 drawing_style = property(lambda self: self._drawing_style, set_drawing_style) 50 70 51 # def set_drawing_style(self, style): 52 # """In addition to setting the drawing style, the handles are 53 # make non-movable if the icon (folded) style is used. 54 # """ 55 # ClassItem.set_drawing_style(self, style) 56 # # TODO: adjust offsets so the center point is the same 57 # if self.drawing_style == self.DRAW_ICON: 58 # self.set(width = self._icon.width, height = self._icon.height) 59 # # Do not allow resizing of the node 60 # for h in self.handles: 61 # h.props.movable = False 62 # 63 # # copy align data from class to item instance, we need this because 64 # # interface align data can change because of folding/unfolding 65 # # interface 66 # self.s_align = self.s_align.copy() 67 # self.n_align = self.n_align.copy() 68 # 69 # self.s_align.valign = V_ALIGN_BOTTOM 70 # self.s_align.outside = True 71 # self.s_align.margin = (0, 2) * 4 72 # self.n_align.valign = V_ALIGN_BOTTOM 73 # self.n_align.outside = True 74 # self.n_align.margin = (2, ) * 4 75 # 76 # self._shapes.remove(self._border) 77 # 78 # # update connected handles 79 # self.update_handle_pos() 80 # else: 81 # # Do allow resizing of the node 82 # for h in self.handles: 83 # h.props.movable = True 84 # 85 # # back to default InterfaceItem class align 86 # del self.s_align 87 # del self.n_align 88 # 89 # self._shapes.add(self._border) 90 # 91 # self.update_stereotype() 92 93 94 # def update_handle_pos(self): 95 # """ 96 # Update connected lines position. 97 # """ 98 # for h in self.connected_handles: 99 # f = None 100 # if gives_provided(h): 101 # f = self._icon.get_provided_pos_w 102 # elif gives_required(h): 103 # f = self._icon.get_required_pos_w 104 # if f: 105 # x, y = f() 106 # h.set_pos_w(x, y) 107 # self.connect_handle(h) 108 109 110 # def get_popup_menu(self): 111 # if self.drawing_style == self.DRAW_ICON: 112 # return NamedItem.popup_menu + ('separator', 'Rotate', 'Unfold',) 113 # else: 114 # return ClassItem.get_popup_menu(self) 115 71 def get_popup_menu(self): 72 if self.drawing_style == self.DRAW_ICON: 73 return NamedItem.popup_menu + ('separator', 'Rotate', 'Unfold',) 74 else: 75 return ClassItem.get_popup_menu(self) 116 76 117 77 def is_folded(self): 118 """Returns True if the interface is drawn as a circle/dot. 78 """ 79 Returns True if the interface is drawn as a circle/dot. 119 80 Unfolded means it's drawn like a classifier. 120 81 """ 121 82 return self.drawing_style == self.DRAW_ICON 122 83 123 124 84 def pre_update_icon(self, context): 125 """Figure out if this interface represents a required, provided, 85 """ 86 Figure out if this interface represents a required, provided, 126 87 assembled (wired) or dotted (minimal) look. 127 88 """ … … 164 125 super(InterfaceItem, self).draw(context) 165 126 166 def on_glue(self, handle, wx, wy):167 """Allow connect only to provided/required points in case168 of interface icon.169 In folded mode, only allow connections from Implementation and170 Realization dependencies.171 """172 if self.drawing_style == self.DRAW_ICON:173 if d < 15:174 f = None175 if gives_provided(handle):176 f = self._icon.get_provided_pos_w177 elif gives_required(handle):178 f = self._icon.get_required_pos_w179 180 if f:181 p2 = f()182 p1 = p2183 return d, p1184 185 186 127 def rotate(self, step = 1): 187 128 """ gaphor/branches/new-canvas/gaphor/diagram/nameditem.py
r1093 r1116 76 76 self.style.name_align, self.style.name_padding, 77 77 self.style.name_outside) 78 79 78 super(NamedItem, self).update(context) 80 79 gaphor/branches/new-canvas/gaphor/diagram/style.py
r1071 r1116 41 41 setattr(self, name, value) 42 42 43 def update(self, style): 44 for name, value in style.items(): 45 self.add(name, value) 43 46 44 47 def items(self): gaphor/branches/new-canvas/gaphor/diagram/tests/test_class.py
r1005 r1116 88 88 self.assertEqual('+ method()', edit.get_text()) 89 89 90 91 # vim:sw=4:et:ai
