Changeset 2120

Show
Ignore:
Timestamp:
09/12/07 12:12:34 (1 year ago)
Author:
arj..@yirdis.nl
Message:

Changed diagramitems to use the new notification system.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/diagram/__init__.py

    r1998 r2120  
    3333 
    3434 
    35 def namedelement(f): 
    36     """ 
    37     Decorator for named items constructors. Injects name text element into 
    38     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 wrapper 
    54  
    55  
    56 def nd_subject(f): 
    57     """ 
    58     Named item subject notification decorator. Updates subject notification 
    59     with subject's name notification. 
    60     """ 
    61     def wrapper(obj, pspec, notifiers=()): 
    62         notifiers = ('name',) + notifiers 
    63         f(obj, pspec, notifiers) 
    64         if obj.subject: 
    65             obj.on_subject_notify__name(obj.subject) 
    66         obj.request_update() 
    67     return wrapper 
    68  
    69  
    70 def nd_subject_name(f): 
    71     """ 
    72     Named item subject name notification decorator. Updates text of name text 
    73     element. 
    74     """ 
    75     def wrapper(obj, subject, pspec=None): 
    76         obj._name.text = subject.name 
    77         obj.request_update() 
    78         f(obj, subject, pspec) 
    79          
    80     return wrapper 
    81  
    82  
    8335class DiagramItemMeta(type): 
    8436    """ 
     
    9648        self.map_uml_class(data) 
    9749        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 appropriate 
    104         decorators and notification methods. 
    105         """ 
    106         if '__namedelement__' in data and data['__namedelement__']: 
    107  
    108             cls = self 
    109  
    110             # inject or decorate notification methods 
    111             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 constructor 
    122             self.__init__ = namedelement(self.__init__) 
    12350 
    12451 
  • gaphor/trunk/gaphor/diagram/activitynodes.py

    r2010 r2120  
    184184    Representation of fork and join node. 
    185185    """ 
    186     __namedelement__ = True 
    187186 
    188187    element_factory = inject('element_factory') 
     
    216215            style=self.STYLE_TOP, 
    217216            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) 
    218229 
    219230 
     
    319330 
    320331 
    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): 
    328337        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() 
    339344 
    340345 
     
    357362 
    358363 
    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  
    367364def is_join_node(subject): 
    368365    """ 
  • gaphor/trunk/gaphor/diagram/comment.py

    r1747 r2120  
    2121        self.height = 50 
    2222        self.width = 100 
     23        self.add_watch(UML.Comment.body) 
    2324 
    2425    def edit(self): 
    2526        #self.start_editing(self._body) 
    2627        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() 
    3728 
    3829    # DiaCanvasItem callbacks: 
  • gaphor/trunk/gaphor/diagram/diagramitem.py

    r2116 r2120  
    409409            if handler: 
    410410                handler(event) 
    411             elif self.subject
     411            elif self.subject and self.subject is event.element
    412412                log.debug('on_element_changed') 
    413413                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, pi 
     1    """ 
     2    Basic functionality for canvas line based items on a diagram. 
     3    """ 
     4 
     5    from math import atan2, pi 
    66 
    77import gaphas 
     
    185185 
    186186class NamedLine(DiagramLine): 
    187     __namedelement__ = True 
    188187 
    189188    __style__ = { 
     
    194193    } 
    195194 
     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() 
    196210 
    197211 
  • gaphor/trunk/gaphor/diagram/extension.py

    r1413 r2120  
    2121    def __init__(self, id=None): 
    2222        NamedLine.__init__(self, id) 
     23        self.add_watch(UML.Extension.ownedEnd) 
    2324 
    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() 
    3025 
    3126    def draw_head(self, context): 
  • gaphor/trunk/gaphor/diagram/feature.py

    r2090 r2120  
    5757        self.width, self.height = text_extents(cr, text) 
    5858 
    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 '' 
    6363 
    6464    def point(self, x, y): 
     
    7474        self.need_sync = False 
    7575 
    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) 
    8986 
    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() 
    9492 
    95     on_subject_notify__isDerived = on_subject_notify__name 
    96     on_subject_notify__visibility = on_subject_notify__name 
    97     on_subject_notify__lowerValue_value = on_subject_notify__name 
    98     on_subject_notify__upperValue_value = on_subject_notify__name 
    99     on_subject_notify__defaultValue_value = on_subject_notify__name 
    100     on_subject_notify__typeValue_value = on_subject_notify__name 
    101     on_subject_notify__taggedValue = on_subject_notify__name 
    10293 
    103     def on_subject_notify__association(self, subject, pspec): 
     94    def on_property_association(self, event): 
    10495        """ 
    10596        Make sure we update the attribute compartment (in case 
     
    10798        an association. 
    10899        """ 
    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() 
    113103 
    114104    def pre_update(self, context): 
    115 #        if self.need_sync and context.parent: 
    116 #            context.parent.sync_attributes() 
    117105        self.need_sync = False 
    118106        self.update_size(self.subject.render(), context) 
     
    123111        text_set_font(cr, font.FONT) 
    124112        text_align(cr, 0, 0, self.subject.render() or '', align_x=1, align_y=1) 
    125         #cr.show_text(self.subject.render() or '') 
    126  
    127113 
    128114 
     
    134120        FeatureItem.__init__(self, id) 
    135121        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) 
    136130 
    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[*] 
    143131 
    144132    def postload(self): 
    145133        FeatureItem.postload(self) 
    146134        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__name 
    153     on_subject_notify__visibility = on_subject_notify__name 
    154     on_subject_notify__taggedValue = on_subject_notify__name 
    155135 
    156136    def pre_update(self, context): 
  • gaphor/trunk/gaphor/diagram/flow.py

    r2073 r2120  
    3737        NamedLine.__init__(self, id) 
    3838        self._guard = self.add_text('guard.value', editable=True) 
     39        self.add_watch(UML.ControlFlow.guard) 
     40        self.add_watch(UML.LiteralSpecification.value) 
     41 
    3942 
    4043    def postload(self): 
     
    4346        super(FlowItem, self).postload() 
    4447 
    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() 
    6256 
    6357 
     
    9387        # set new value notification function to change activity edge 
    9488        # connector name globally 
    95         vnf = self.on_subject_notify__value 
    96         def f(subject, pspec): 
    97             vnf(subject, pspec) 
    98             if self.parent._opposite: 
    99                 self.parent._opposite._connector.subject.value = subject.value 
    100         self.on_subject_notify__value = f 
     89        #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 
    10195 
    10296 
  • gaphor/trunk/gaphor/diagram/klass.py

    r2116 r2120  
    9191                           self._create_attribute) 
    9292 
     93 
    9394    def sync_operations(self): 
    9495        """ 
     
    100101 
    101102 
    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): 
    117104        self.sync_attributes() 
    118105 
    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): 
    124108        self.sync_operations() 
     109 
    125110 
    126111    def pre_update(self, context): 
  • gaphor/trunk/gaphor/diagram/nameditem.py

    r2116 r2120  
    99 
    1010class NamedItem(ElementItem): 
    11     __namedelement__ = True 
    1211 
    1312    __style__ = { 
     
    3332                font=font.FONT_SMALL) 
    3433 
     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 
    3542        # size of stereotype, namespace and name text 
    3643        self._header_size = 0, 0 
     44        self.add_watch(UML.NamedElement.name, self.on_named_element_name) 
    3745        self.add_watch(UML.NamedElement.namespace, self.on_named_element_namespace) 
    3846        self.add_watch(UML.Namespace.name, self.on_named_element_namespace) 
     
    5866 
    5967        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() 
    6075 
    6176 
  • gaphor/trunk/gaphor/diagram/objectnode.py

    r1925 r2120  
    4949            visible=self._get_show_ordering) 
    5050 
     51        self.add_watch(UML.ValueSpecification) 
     52        self.add_watch(UML.ValueSpecification.value) 
     53        self.add_watch(UML.ObjectNode.ordering) 
     54 
    5155 
    5256    def is_upper_bound_visible(self): 
     
    98102        super(ObjectNodeItem, self).postload() 
    99103 
    100     def on_subject_notify(self, pspec, notifiers = ()): 
    101         """ 
    102         Detect subject changes. If subject is set then set upper bound text 
    103         element subject. 
    104         """ 
    105         NamedItem.on_subject_notify(self, pspec, 
    106                 ('upperBound', 'upperBound.value', 'ordering') + notifiers) 
    107104 
     105    def on_object_node_upper_bound(self, event): 
     106        element = self.element 
    108107        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() 
    113112 
    114113 
     
    146145 
    147146 
    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  
    160147 
    161148# vim:sw=4:et:ai