Changeset 2120
- Timestamp:
- 09/12/07 12:12:34 (1 year ago)
- Files:
-
- gaphor/trunk/gaphor/diagram/__init__.py (modified) (2 diffs)
- gaphor/trunk/gaphor/diagram/activitynodes.py (modified) (4 diffs)
- gaphor/trunk/gaphor/diagram/comment.py (modified) (1 diff)
- gaphor/trunk/gaphor/diagram/diagramitem.py (modified) (1 diff)
- gaphor/trunk/gaphor/diagram/diagramline.py (modified) (3 diffs)
- gaphor/trunk/gaphor/diagram/extension.py (modified) (1 diff)
- gaphor/trunk/gaphor/diagram/feature.py (modified) (5 diffs)
- gaphor/trunk/gaphor/diagram/flow.py (modified) (3 diffs)
- gaphor/trunk/gaphor/diagram/klass.py (modified) (2 diffs)
- gaphor/trunk/gaphor/diagram/nameditem.py (modified) (3 diffs)
- gaphor/trunk/gaphor/diagram/objectnode.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/trunk/gaphor/diagram/__init__.py
r1998 r2120 33 33 34 34 35 def namedelement(f):36 """37 Decorator for named items constructors. Injects name text element into38 an object.39 """40 def wrapper(*args, **kw):41 obj = args[0]42 f(*args, **kw)43 44 style = {45 'text-align': obj.style.name_align,46 'text-padding': obj.style.name_padding,47 'text-outside': obj.style.name_outside,48 'text-align-str': obj.style.name_align_str,49 'text-align-group': 'stereotype',50 }51 obj._name = obj.add_text('name', style=style, editable=True)52 53 return wrapper54 55 56 def nd_subject(f):57 """58 Named item subject notification decorator. Updates subject notification59 with subject's name notification.60 """61 def wrapper(obj, pspec, notifiers=()):62 notifiers = ('name',) + notifiers63 f(obj, pspec, notifiers)64 if obj.subject:65 obj.on_subject_notify__name(obj.subject)66 obj.request_update()67 return wrapper68 69 70 def nd_subject_name(f):71 """72 Named item subject name notification decorator. Updates text of name text73 element.74 """75 def wrapper(obj, subject, pspec=None):76 obj._name.text = subject.name77 obj.request_update()78 f(obj, subject, pspec)79 80 return wrapper81 82 83 35 class DiagramItemMeta(type): 84 36 """ … … 96 48 self.map_uml_class(data) 97 49 self.set_style(data) 98 self.set_namedelement(data)99 100 101 def set_namedelement(self, data):102 """103 If an diagram item is named element, then inject appropriate104 decorators and notification methods.105 """106 if '__namedelement__' in data and data['__namedelement__']:107 108 cls = self109 110 # inject or decorate notification methods111 if hasattr(self, 'on_subject_notify'):112 self.on_subject_notify = nd_subject(self.on_subject_notify)113 else:114 self.on_subject_notify = nd_subject(lambda *args: None)115 116 if hasattr(self, 'on_subject_notify__name'):117 self.on_subject_notify__name = nd_subject_name(self.on_subject_notify__name)118 else:119 self.on_subject_notify__name = nd_subject_name(lambda *args: None)120 121 # decorate constructor122 self.__init__ = namedelement(self.__init__)123 50 124 51 gaphor/trunk/gaphor/diagram/activitynodes.py
r2010 r2120 184 184 Representation of fork and join node. 185 185 """ 186 __namedelement__ = True187 186 188 187 element_factory = inject('element_factory') … … 216 215 style=self.STYLE_TOP, 217 216 visible=self.is_join_spec_visible) 217 218 obj._name = obj.add_text('name', style={ 219 'text-align': self.style.name_align, 220 'text-padding': self.style.name_padding, 221 'text-outside': self.style.name_outside, 222 'text-align-str': self.style.name_align_str, 223 'text-align-group': 'stereotype', 224 }, editable=True) 225 226 self.add_watch(UML.NamedElement.name, on_named_element_name) 227 self.add_watch(UML.JoinNode.joinSpec, on_join_node_join_spec) 228 self.add_watch(UML.LiteralSpecification.value, on_join_node_join_spec) 218 229 219 230 … … 319 330 320 331 321 def on_subject_notify(self, pspec, notifiers = ()): 322 """ 323 Detect changes of subject. 324 325 If subject is join node, then set subject of join specification 326 text element. 327 """ 332 def on_named_element_name(self, event): 333 self._name.text = subject.name 334 self.request_update() 335 336 def on_join_node_join_spec(self, event): 328 337 subject = self.subject 329 if is_join_node(subject): 330 join_spec_notifiers = ('joinSpec', 'joinSpec.value') 331 else: 332 join_spec_notifiers = () 333 334 DiagramItem.on_subject_notify(self, pspec, join_spec_notifiers + notifiers) 335 336 if is_join_node(subject) and not (subject.joinSpec and subject.joinSpec.value): 337 self.set_join_spec(DEFAULT_JOIN_SPEC) 338 self.request_update() 338 if self.subject and is_join_node(subject) and \ 339 (event.element is subject.joinSpec or \ 340 event.element is subject.joinSpec.value): 341 if is_join_node(subject) and not (subject.joinSpec and subject.joinSpec.value): 342 self.set_join_spec(DEFAULT_JOIN_SPEC) 343 self.request_update() 339 344 340 345 … … 357 362 358 363 359 def on_subject_notify__joinSpec(self, subject, pspec=None):360 self.request_update()361 362 363 def on_subject_notify__joinSpec_value(self, subject, pspec=None):364 self.request_update()365 366 367 364 def is_join_node(subject): 368 365 """ gaphor/trunk/gaphor/diagram/comment.py
r1747 r2120 21 21 self.height = 50 22 22 self.width = 100 23 self.add_watch(UML.Comment.body) 23 24 24 25 def edit(self): 25 26 #self.start_editing(self._body) 26 27 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 28 38 29 # DiaCanvasItem callbacks: gaphor/trunk/gaphor/diagram/diagramitem.py
r2116 r2120 409 409 if handler: 410 410 handler(event) 411 elif self.subject :411 elif self.subject and self.subject is event.element: 412 412 log.debug('on_element_changed') 413 413 self.request_update() gaphor/trunk/gaphor/diagram/diagramline.py
r2116 r2120 1 """2 Basic functionality for canvas line based items on a diagram.3 """4 5 from math import atan2, pi1 """ 2 Basic functionality for canvas line based items on a diagram. 3 """ 4 5 from math import atan2, pi 6 6 7 7 import gaphas … … 185 185 186 186 class NamedLine(DiagramLine): 187 __namedelement__ = True188 187 189 188 __style__ = { … … 194 193 } 195 194 195 def __init__(self, id=None): 196 DiagramLine.__init__(self, id) 197 obj._name = obj.add_text('name', style={ 198 'text-align': self.style.name_align, 199 'text-padding': self.style.name_padding, 200 'text-outside': self.style.name_outside, 201 'text-align-str': self.style.name_align_str, 202 'text-align-group': 'stereotype', 203 }, editable=True) 204 self.add_watch(UML.NamedElement.name, self.on_named_element_name) 205 206 207 def on_named_element_name(self, event): 208 self._name.text = subject.name 209 self.request_update() 196 210 197 211 gaphor/trunk/gaphor/diagram/extension.py
r1413 r2120 21 21 def __init__(self, id=None): 22 22 NamedLine.__init__(self, id) 23 self.add_watch(UML.Extension.ownedEnd) 23 24 24 def on_subject_notify(self, pspec, notifiers=()):25 NamedLine.on_subject_notify(self, pspec,26 notifiers + ('ownedEnd',))27 28 def on_subject_notify__ownedEnd(self, subject, pspec):29 self.request_update()30 25 31 26 def draw_head(self, context): gaphor/trunk/gaphor/diagram/feature.py
r2090 r2120 57 57 self.width, self.height = text_extents(cr, text) 58 58 59 def on_subject_notify(self, pspec, notifiers=()):60 DiagramItem.on_subject_notify(self, pspec, notifiers)61 #log.debug('setting text %s' % self.subject.render() or '')62 self.text = self.subject and self.subject.render() or ''59 # def on_subject_notify(self, pspec, notifiers=()): 60 # DiagramItem.on_subject_notify(self, pspec, notifiers) 61 # #log.debug('setting text %s' % self.subject.render() or '') 62 # self.text = self.subject and self.subject.render() or '' 63 63 64 64 def point(self, x, y): … … 74 74 self.need_sync = False 75 75 76 def on_subject_notify(self, pspec, notifiers=()): 77 FeatureItem.on_subject_notify(self, pspec, ('name', 78 'isDerived', 79 'visibility', 80 'lowerValue.value', 81 'upperValue.value', 82 'defaultValue.value', 83 'typeValue.value', 84 'taggedValue', 85 'association') 86 + notifiers) 87 #self._expression.set_text(self.subject.render() or '') 88 #self.request_update() 76 self.add_watch(UML.Property.name) 77 self.add_watch(UML.Property.isDerived) 78 self.add_watch(UML.Property.visibility) 79 self.add_watch(UML.Property.association, self.on_property_association) 80 self.add_watch(UML.Property.lowerValue) 81 self.add_watch(UML.Property.upperValue) 82 self.add_watch(UML.Property.defaultValue) 83 self.add_watch(UML.Property.typeValue) 84 self.add_watch(UML.Property.taggedValue) 85 self.add_watch(UML.ValueSpecification.value, self.on_feature_value) 89 86 90 def on_subject_notify__name(self, subject, pspec): 91 #log.debug('setting text %s' % self.subject.render() or '') 92 #self._expression.set_text(self.subject.render() or '') 93 self.request_update() 87 def on_feature_value(self, event): 88 element = event.element 89 subject = self.subject 90 if subject and element in (subject.lowerValue, subject.upperValue, subject.defaultValue, subject.typeValue, subject.taggedValue): 91 self.request_update() 94 92 95 on_subject_notify__isDerived = on_subject_notify__name96 on_subject_notify__visibility = on_subject_notify__name97 on_subject_notify__lowerValue_value = on_subject_notify__name98 on_subject_notify__upperValue_value = on_subject_notify__name99 on_subject_notify__defaultValue_value = on_subject_notify__name100 on_subject_notify__typeValue_value = on_subject_notify__name101 on_subject_notify__taggedValue = on_subject_notify__name102 93 103 def on_ subject_notify__association(self, subject, pspec):94 def on_property_association(self, event): 104 95 """ 105 96 Make sure we update the attribute compartment (in case … … 107 98 an association. 108 99 """ 109 #if self.parent: 110 # self.parent.sync_attributes() 111 self.need_sync = True 112 self.request_update() 100 if event.element is self.subject: 101 self.need_sync = True 102 self.request_update() 113 103 114 104 def pre_update(self, context): 115 # if self.need_sync and context.parent:116 # context.parent.sync_attributes()117 105 self.need_sync = False 118 106 self.update_size(self.subject.render(), context) … … 123 111 text_set_font(cr, font.FONT) 124 112 text_align(cr, 0, 0, self.subject.render() or '', align_x=1, align_y=1) 125 #cr.show_text(self.subject.render() or '')126 127 113 128 114 … … 134 120 FeatureItem.__init__(self, id) 135 121 self.need_sync = False 122 123 self.add_watch(UML.Operation.name) 124 self.add_watch(UML.Operation.visibility) 125 self.add_watch(UML.Operation.isAbstract) 126 self.add_watch(UML.Operation.taggedValue) 127 # Parameters 128 # TODO: Handle subject.returnResult[*] and subject.formalParameter[*] 129 self.add_watch(UML.Operation.isAbstract) 136 130 137 def on_subject_notify(self, pspec, notifiers=()):138 FeatureItem.on_subject_notify(self, pspec,139 ('name', 'visibility', 'isAbstract')140 + notifiers)141 142 # TODO: Handle subject.returnResult[*] and subject.formalParameter[*]143 131 144 132 def postload(self): 145 133 FeatureItem.postload(self) 146 134 self.need_sync = False 147 148 def on_subject_notify__name(self, subject, pspec):149 #log.debug('setting text %s' % self.subject.render() or '')150 self.request_update()151 152 on_subject_notify__isAbstract = on_subject_notify__name153 on_subject_notify__visibility = on_subject_notify__name154 on_subject_notify__taggedValue = on_subject_notify__name155 135 156 136 def pre_update(self, context): gaphor/trunk/gaphor/diagram/flow.py
r2073 r2120 37 37 NamedLine.__init__(self, id) 38 38 self._guard = self.add_text('guard.value', editable=True) 39 self.add_watch(UML.ControlFlow.guard) 40 self.add_watch(UML.LiteralSpecification.value) 41 39 42 40 43 def postload(self): … … 43 46 super(FlowItem, self).postload() 44 47 45 def on_subject_notify(self, pspec, notifiers = ()): 46 NamedLine.on_subject_notify(self, pspec, 47 ('guard', 'guard.value',) + notifiers) 48 if self.subject: 49 self.on_subject_notify__guard(self.subject) 50 self.on_subject_notify__guard_value(self.subject) 51 self.request_update() 52 53 54 def on_subject_notify__guard(self, subject, pspec=None): 55 if not subject.guard or not subject.guard.value: 56 self._guard.text = '' 57 self.request_update() 58 59 60 def on_subject_notify__guard_value(self, subject, pspec=None): 61 self.request_update() 48 49 def on_control_flow_guard(self, event): 50 element = event.element 51 subject = self.subject 52 if subject and (element is subject or element is subject.guard): 53 if not subject.guard or not subject.guard.value: 54 self._guard.text = '' 55 self.request_update() 62 56 63 57 … … 93 87 # set new value notification function to change activity edge 94 88 # connector name globally 95 vnf = self.on_subject_notify__value96 def f(subject, pspec):97 vnf(subject, pspec)98 if self.parent._opposite:99 self.parent._opposite._connector.subject.value = subject.value100 self.on_subject_notify__value = f89 #vnf = self.on_subject_notify__value 90 #def f(subject, pspec): 91 # vnf(subject, pspec) 92 # if self.parent._opposite: 93 # self.parent._opposite._connector.subject.value = subject.value 94 #self.on_subject_notify__value = f 101 95 102 96 gaphor/trunk/gaphor/diagram/klass.py
r2116 r2120 91 91 self._create_attribute) 92 92 93 93 94 def sync_operations(self): 94 95 """ … … 100 101 101 102 102 def on_subject_notify(self, pspec, notifiers=()): 103 #log.debug('Class.on_subject_notify(%s, %s)' % (pspec, notifiers)) 104 ClassifierItem.on_subject_notify(self, pspec, 105 ('ownedAttribute', 'ownedOperation') + notifiers) 106 # Create already existing attributes and operations: 107 if self.subject: 108 self.sync_attributes() 109 self.sync_operations() 110 self.request_update() 111 112 def on_subject_notify__ownedAttribute(self, subject, pspec=None): 113 """ 114 Called when the ownedAttribute property of our subject changes. 115 """ 116 #log.debug('on_subject_notify__ownedAttribute') 103 def on_class_owned_attribute(self, event): 117 104 self.sync_attributes() 118 105 119 def on_subject_notify__ownedOperation(self, subject, pspec=None): 120 """ 121 Called when the ownedOperation property of our subject changes. 122 """ 123 #log.debug('on_subject_notify__ownedOperation') 106 107 def on_class_owned_operation(self, event): 124 108 self.sync_operations() 109 125 110 126 111 def pre_update(self, context): gaphor/trunk/gaphor/diagram/nameditem.py
r2116 r2120 9 9 10 10 class NamedItem(ElementItem): 11 __namedelement__ = True12 11 13 12 __style__ = { … … 33 32 font=font.FONT_SMALL) 34 33 34 obj._name = obj.add_text('name', style={ 35 'text-align': self.style.name_align, 36 'text-padding': self.style.name_padding, 37 'text-outside': self.style.name_outside, 38 'text-align-str': self.style.name_align_str, 39 'text-align-group': 'stereotype', 40 }, editable=True) 41 35 42 # size of stereotype, namespace and name text 36 43 self._header_size = 0, 0 44 self.add_watch(UML.NamedElement.name, self.on_named_element_name) 37 45 self.add_watch(UML.NamedElement.namespace, self.on_named_element_namespace) 38 46 self.add_watch(UML.Namespace.name, self.on_named_element_namespace) … … 58 66 59 67 return self._from.text and namespace is not canvas.diagram.namespace 68 69 70 def on_named_element_name(self, event): 71 """ 72 """ 73 self._name.text = subject.name 74 self.request_update() 60 75 61 76 gaphor/trunk/gaphor/diagram/objectnode.py
r1925 r2120 49 49 visible=self._get_show_ordering) 50 50 51 self.add_watch(UML.ValueSpecification) 52 self.add_watch(UML.ValueSpecification.value) 53 self.add_watch(UML.ObjectNode.ordering) 54 51 55 52 56 def is_upper_bound_visible(self): … … 98 102 super(ObjectNodeItem, self).postload() 99 103 100 def on_subject_notify(self, pspec, notifiers = ()):101 """102 Detect subject changes. If subject is set then set upper bound text103 element subject.104 """105 NamedItem.on_subject_notify(self, pspec,106 ('upperBound', 'upperBound.value', 'ordering') + notifiers)107 104 105 def on_object_node_upper_bound(self, event): 106 element = self.element 108 107 subject = self.subject 109 if subject and not (subject.upperBound and subject.upperBound.value):110 self.set_upper_bound(DEFAULT_UPPER_BOUND)111 112 self.request_update()108 if subject and (element is subject or element is subject.upperBound): 109 if not (subject.upperBound and subject.upperBound.value): 110 self.set_upper_bound(DEFAULT_UPPER_BOUND) 111 self.request_update() 113 112 114 113 … … 146 145 147 146 148 def on_subject_notify__upperBound(self, subject, pspec=None):149 self.request_update()150 151 152 def on_subject_notify__upperBound_value(self, subject, pspec=None):153 self.request_update()154 155 156 def on_subject_notify__ordering(self, subject, pspec=None):157 self.request_update()158 159 160 147 161 148 # vim:sw=4:et:ai
