Changeset 1070
- Timestamp:
- 11/08/06 23:51:20 (2 years ago)
- Files:
-
- gaphor/branches/new-canvas/gaphor/actions/itemactions.py (modified) (4 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/classifier.py (modified) (7 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/diagramitem.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/interface.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/branches/new-canvas/gaphor/actions/itemactions.py
r1056 r1070 911 911 #log.debug('Action %s: %s' % (self.id, item.subject.name)) 912 912 913 item. set_property('drawing-style', items.InterfaceItem.DRAW_ICON)913 item.drawing_style = items.InterfaceItem.DRAW_ICON 914 914 915 915 register_action(FoldAction, 'ItemFocus') … … 926 926 #log.debug('Action %s: %s' % (self.id, item.subject.name)) 927 927 928 item. set_property('drawing-style', items.InterfaceItem.DRAW_COMPARTMENT)928 item.drawing_style = items.InterfaceItem.DRAW_COMPARTMENT 929 929 # Make sure lines are updated properly: 930 item.canvas.update_now()931 item.canvas.update_now()930 #item.canvas.update_now() 931 #item.canvas.update_now() 932 932 933 933 register_action(UnfoldAction, 'ItemFocus') … … 1003 1003 def create_missing_relationships(self, item, diagram, item_type): 1004 1004 new_rel = diagram.create(item_type) 1005 for other_item in diagram.canvas. root.children:1005 for other_item in diagram.canvas.get_all_items(): 1006 1006 if not other_item.subject: 1007 1007 continue … … 1038 1038 @undoable 1039 1039 def execute(self): 1040 # TODO: AJM: disabled action 1041 return 1040 1042 diagram_tab = self._window.get_current_diagram_tab() 1041 1043 diagram = diagram_tab.get_diagram() gaphor/branches/new-canvas/gaphor/diagram/classifier.py
r1044 r1070 18 18 A compartment has a line on top and a list of FeatureItems. 19 19 """ 20 21 MARGIN_X = 522 MARGIN_Y = 523 20 24 21 def __init__(self, name, owner): … … 59 56 self.width = max(map(lambda p: p[0], sizes)) 60 57 self.height = sum(map(lambda p: p[1], sizes)) 61 self.width += 2 * self.MARGIN_X 62 self.height += 2 * self.MARGIN_Y 58 margin = self.owner.style.compartment_margin 59 self.width += margin[1] + margin[3] 60 self.height += margin[0] + margin[2] 63 61 64 62 def update(self, context): … … 69 67 def draw(self, context): 70 68 cr = context.cairo 71 cr.translate(self.MARGIN_X, self.MARGIN_Y) 69 margin = self.owner.style.compartment_margin 70 cr.translate(margin[1], margin[0]) 72 71 for item in self: 73 72 cr.save() … … 108 107 DRAW_ICON = 3 109 108 109 __style__ = { 110 'icon-size': (20, 20), 111 'compartment-margin': (5, 5, 5, 5), # (top, right, bottom, left) 112 } 110 113 # Default size for small icons 111 114 ICON_WIDTH = 15 … … 248 251 comp.pre_update(context) 249 252 250 if self._drawing_style == self.DRAW_COMPARTMENT: 251 cr = context.cairo 252 s_w = s_h = 0 253 if self.stereotype: 254 s_w, s_h = text_extents(cr, self.stereotype) 255 n_w, n_h = text_extents(cr, self.subject.name) 256 f_w, f_h = 0, 0 257 if self.subject.namespace: 258 f_w, f_h = text_extents(cr, self._from, font=font.FONT_SMALL) 259 260 sizes = [comp.get_size() for comp in self._compartments] 261 262 self.min_width = max(s_w, n_w, f_w) 263 self.min_height = self.NAME_COMPARTMENT_HEIGHT 264 265 if sizes: 266 w = max(map(lambda p: p[0], sizes)) 267 268 h = sum(map(lambda p: p[1], sizes)) 269 self.min_width = max(self.min_width, w) 270 self.min_height += h 271 super(ClassifierItem, self).pre_update(context) 253 cr = context.cairo 254 s_w = s_h = 0 255 if self.stereotype: 256 s_w, s_h = text_extents(cr, self.stereotype) 257 n_w, n_h = text_extents(cr, self.subject.name) 258 f_w, f_h = 0, 0 259 if self.subject.namespace: 260 f_w, f_h = text_extents(cr, self._from, font=font.FONT_SMALL) 261 262 sizes = [comp.get_size() for comp in self._compartments] 263 264 self.min_width = max(s_w, n_w, f_w) 265 self.min_height = self.NAME_COMPARTMENT_HEIGHT 266 267 if sizes: 268 w = max(map(lambda p: p[0], sizes)) 269 270 h = sum(map(lambda p: p[1], sizes)) 271 self.min_width = max(self.min_width, w) 272 self.min_height += h 273 super(ClassifierItem, self).pre_update(context) 272 274 273 275 def pre_update_compartment_icon(self, context): … … 275 277 276 278 def pre_update_icon(self, context): 277 pass279 super(ClassifierItem, self).pre_update(context) 278 280 279 281 def update_compartment(self, context): … … 288 290 289 291 def update_icon(self, context): 290 """ Update state to draw as one big icon.292 """ 291 293 """ 292 294 pass gaphor/branches/new-canvas/gaphor/diagram/diagramitem.py
r1068 r1070 82 82 print self, 'subject =', self.subject 83 83 else: 84 #log.debug('Setting unknown property "%s" -> "%s"' % (name, value))84 log.debug('Setting unknown property "%s" -> "%s"' % (name, value)) 85 85 try: 86 setattr(self, name , eval(value))86 setattr(self, name.replace('-', '_'), eval(value)) 87 87 except: 88 88 log.warning('%s has no property named %s (value %s)' % (self, name, value)) gaphor/branches/new-canvas/gaphor/diagram/interface.py
r1059 r1070 4 4 5 5 import itertools 6 from math import pi 6 7 from gaphas.item import NW, SE 7 8 from gaphor import UML … … 26 27 __uml__ = UML.Interface 27 28 __stereotype__ = {'interface': lambda self: self.drawing_style != self.DRAW_ICON} 28 29 __style__ = { 30 'icon-size': (20, 20), 31 'icon-size-provided': (20, 20), 32 'icon-size-required': (28, 28), 33 'name-outside': False, 34 } 29 35 RADIUS_PROVIDED = 10 30 36 RADIUS_REQUIRED = 14 … … 116 122 117 123 118 def update_icon(self, context):124 def pre_update_icon(self, context): 119 125 """Figure out if this interface represents a required, provided, 120 126 assembled (wired) or dotted (minimal) look. 121 127 """ 128 for h in self._handles: h.movable = False 129 self.style.name_outside = True 130 122 131 h_nw = self._handles[NW] 123 cx, xy = h_nw.x + self.width/2, h_nw.y + self.height/2132 cx, cy = h_nw.x + self.width/2, h_nw.y + self.height/2 124 133 self._draw_required = self._draw_provided = False 125 134 for item, handle in self.canvas.get_connected_items(self): … … 128 137 elif gives_provided(handle): 129 138 self._draw_provided = True 130 radius = RADIUS_PROVIDED 139 radius = self.RADIUS_PROVIDED 140 self.style.icon_size = self.style.icon_size_provided 131 141 if self._draw_required: 132 radius = RADIUS_REQUIRED 133 134 h_nw.x, h_nw.y = cx - radius, cy - radius 142 radius = self.RADIUS_REQUIRED 143 self.style.icon_size = self.style.icon_size_required 144 self.min_width, self.min_height = self.style.icon_size 145 self.width, self.height = self.style.icon_size 146 147 #h_nw.x, h_nw.y = cx - radius, cy - radius 135 148 h_se = self._handles[SE] 136 h_se.x, h_se.y = cx + radius, cy + radius137 149 #h_se.x, h_se.y = cx + radius, cy + radius 150 super(InterfaceItem, self).pre_update(context) 138 151 139 152 def draw_icon(self, context): … … 142 155 cx, cy = h_nw.x + self.width/2, h_nw.y + self.height/2 143 156 if self._draw_required: 144 cr.move_to(cx, cy + RADIUS_REQUIRED)145 cr.arc_negative(cx, cy, RADIUS_REQUIRED, pi/2, pi*1.5)157 cr.move_to(cx, cy + self.RADIUS_REQUIRED) 158 cr.arc_negative(cx, cy, self.RADIUS_REQUIRED, pi/2, pi*1.5) 146 159 cr.stroke() 147 160 if self._draw_provided or not self._draw_required: 148 cr.move_to(cx + RADIUS_PROVIDED, cy)149 cr.arc(cx, cy, RADIUS_PROVIDED, 0, pi*2)161 cr.move_to(cx + self.RADIUS_PROVIDED, cy) 162 cr.arc(cx, cy, self.RADIUS_PROVIDED, 0, pi*2) 150 163 cr.stroke() 164 super(InterfaceItem, self).draw(context) 151 165 152 166 def on_glue(self, handle, wx, wy):
