Changeset 1116

Show
Ignore:
Timestamp:
01/11/07 06:26:48 (2 years ago)
Author:
arjanmol
Message:

workaround for classifier representation.
several fixes all over the place.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/gaphor/actions/itemactions.py

    r1087 r1116  
    917917        #log.debug('Action %s: %s' % (self.id, item.subject.name)) 
    918918 
    919         item.drawing_style = items.InterfaceItem.DRAW_ICON 
     919        item.drawing_style = item.DRAW_ICON 
    920920 
    921921register_action(FoldAction, 'ItemFocus') 
     
    932932        #log.debug('Action %s: %s' % (self.id, item.subject.name)) 
    933933 
    934         item.drawing_style = items.InterfaceItem.DRAW_COMPARTMENT 
     934        item.drawing_style = item.DRAW_COMPARTMENT 
    935935        # Make sure lines are updated properly: 
    936936        #item.canvas.update_now() 
     
    11621162        try: 
    11631163            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() 
    11661167        except NoFocusItemError: 
    11671168            pass 
  • gaphor/branches/new-canvas/gaphor/adapters/connectors.py

    r1115 r1116  
    733733              
    734734            # TODO: make element at head end update! 
     735            c1.request_update() 
    735736 
    736737            # Find all associations and determine if the properties on 
  • gaphor/branches/new-canvas/gaphor/adapters/editors.py

    r1104 r1116  
    6161    def update_text(self, text): 
    6262        self._item.subject.name = text 
     63        self._item.request_update() 
    6364 
    6465    def key_pressed(self, pos, key): 
  • gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py

    r1112 r1116  
    8383        cr.set_line_width(2) 
    8484        cr.stroke() 
    85          
     85 
    8686        super(ActivityFinalNodeItem, self).draw(context) 
    8787 
  • gaphor/branches/new-canvas/gaphor/diagram/classifier.py

    r1093 r1116  
    5858            vspacing = self.owner.style.compartment_vspacing 
    5959            self.height += vspacing * len(sizes) 
    60         margin = self.owner.style.compartment_margin 
    61         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] 
    6363 
    6464    def update(self, context): 
     
    6969    def draw(self, context): 
    7070        cr = context.cairo 
    71         margin = self.owner.style.compartment_margin 
     71        padding = self.owner.style.compartment_padding 
    7272        vspacing = self.owner.style.compartment_vspacing 
    73         cr.translate(margin[1], margin[0]) 
     73        cr.translate(padding[1], padding[0]) 
    7474        offset = 0 
    7575        for item in self: 
     
    117117        'min-size':           (100, 50), 
    118118        '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) 
    120121        'compartment-vspacing': 2, 
     122# Fix name, stereotype and from drawing! 
     123        'name-padding': (10, 10, 10, 10), 
     124        'stereotype-padding': (10, 10, 2, 10), 
    121125    } 
    122126    # Default size for small icons 
     
    262266        s_w = s_h = 0 
    263267        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] 
    266277 
    267278        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] 
    270284 
    271285        sizes = [comp.get_size() for comp in self._compartments] 
    272286        self.update_name_size(context) 
    273287        sizes.append(self.get_name_size()) 
     288        sizes.append((s_w, s_h)) 
     289        sizes.append((f_w, f_h)) 
    274290        self.min_width = max(s_w, n_w, f_w) 
    275291        self.min_height = 0 
     
    292308 
    293309    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) 
    297314 
    298315    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) 
    302320 
    303321    def update_icon(self, context): 
    304322        """ 
    305         """ 
    306         pass 
     323        Update state for icon-only presentation. 
     324        """ 
     325        super(ClassifierItem, self).update(context) 
    307326 
    308327    def get_icon_pos(self): 
     
    326345 
    327346        # draw stereotype 
    328         y += 10 
    329347        if self.stereotype: 
     348            padding = self.style.stereotype_padding 
     349            y += padding[0] 
    330350            text_set_font(cr, font.FONT) 
    331351            text_center(cr, width / 2, y, self.stereotype) 
     352            y += padding[2] 
    332353 
    333354        # 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) 
    335358        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 
    339362        # draw 'from ... ' 
    340363        if self._from: 
     364            padding = self.style.from_padding 
     365            y += padding[0] 
    341366            text_set_font(cr, font.FONT_SMALL) 
    342367            text_center(cr, width / 2, y, self._from) 
    343  
    344         y += 5 
     368            y += padding[2] 
     369 
    345370        cr.translate(0, y) 
    346371 
  • gaphor/branches/new-canvas/gaphor/diagram/elementitem.py

    r1115 r1116  
    1414    __style__ = { 
    1515        'min-size': (0, 0), 
     16        'stereotype-padding': (5, 10, 5, 10), 
    1617    } 
    1718 
  • gaphor/branches/new-canvas/gaphor/diagram/interface.py

    r1070 r1116  
    99from gaphor.diagram.dependency import DependencyItem 
    1010from gaphor.diagram.implementation import ImplementationItem 
    11 #from gaphor.diagram.interfaceicon import AssembledInterfaceIcon, \ 
    12 #    ProvidedInterfaceIcon, RequiredInterfaceIcon 
    1311from gaphor.diagram.klass import ClassItem 
    1412from gaphor.diagram.nameditem import NamedItem 
    1513from gaphor.diagram.rotatable import SimpleRotation 
     14from gaphor.diagram.style import ALIGN_TOP, ALIGN_BOTTOM, ALIGN_CENTER 
    1615 
    1716class 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 
    1919    representation is provided by ClassItem. These representations can be 
    2020    switched by using the Fold and Unfold actions. 
     
    3333        'name-outside': False, 
    3434        } 
     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 
    3546    RADIUS_PROVIDED = 10 
    3647    RADIUS_REQUIRED = 14 
     
    4253        self._draw_provided = False 
    4354 
    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() 
    4968 
     69    drawing_style = property(lambda self: self._drawing_style, set_drawing_style) 
    5070 
    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) 
    11676 
    11777    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. 
    11980        Unfolded means it's drawn like a classifier. 
    12081        """ 
    12182        return self.drawing_style == self.DRAW_ICON 
    12283 
    123   
    12484    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, 
    12687        assembled (wired) or dotted (minimal) look. 
    12788        """ 
     
    164125        super(InterfaceItem, self).draw(context) 
    165126 
    166     def on_glue(self, handle, wx, wy): 
    167         """Allow connect only to provided/required points in case 
    168         of interface icon. 
    169         In folded mode, only allow connections from Implementation and 
    170         Realization dependencies. 
    171         """ 
    172         if self.drawing_style == self.DRAW_ICON: 
    173             if d < 15: 
    174                 f = None 
    175                 if gives_provided(handle): 
    176                     f = self._icon.get_provided_pos_w 
    177                 elif gives_required(handle): 
    178                     f = self._icon.get_required_pos_w 
    179  
    180                 if f: 
    181                     p2 = f() 
    182                     p1 = p2 
    183         return d, p1 
    184  
    185  
    186127    def rotate(self, step = 1): 
    187128        """ 
  • gaphor/branches/new-canvas/gaphor/diagram/nameditem.py

    r1093 r1116  
    7676                    self.style.name_align, self.style.name_padding, 
    7777                    self.style.name_outside) 
    78  
    7978        super(NamedItem, self).update(context) 
    8079 
  • gaphor/branches/new-canvas/gaphor/diagram/style.py

    r1071 r1116  
    4141        setattr(self, name, value) 
    4242 
     43    def update(self, style): 
     44        for name, value in style.items(): 
     45            self.add(name, value) 
    4346 
    4447    def items(self): 
  • gaphor/branches/new-canvas/gaphor/diagram/tests/test_class.py

    r1005 r1116  
    8888        self.assertEqual('+ method()', edit.get_text()) 
    8989 
     90 
     91# vim:sw=4:et:ai