Changeset 1070

Show
Ignore:
Timestamp:
11/08/06 23:51:20 (2 years ago)
Author:
arjanmol
Message:

Make interface folding work. Added some more style information

Files:

Legend:

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

    r1056 r1070  
    911911        #log.debug('Action %s: %s' % (self.id, item.subject.name)) 
    912912 
    913         item.set_property('drawing-style', items.InterfaceItem.DRAW_ICON) 
     913        item.drawing_style = items.InterfaceItem.DRAW_ICON 
    914914 
    915915register_action(FoldAction, 'ItemFocus') 
     
    926926        #log.debug('Action %s: %s' % (self.id, item.subject.name)) 
    927927 
    928         item.set_property('drawing-style', items.InterfaceItem.DRAW_COMPARTMENT) 
     928        item.drawing_style = items.InterfaceItem.DRAW_COMPARTMENT 
    929929        # 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() 
    932932 
    933933register_action(UnfoldAction, 'ItemFocus') 
     
    10031003    def create_missing_relationships(self, item, diagram, item_type): 
    10041004        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()
    10061006            if not other_item.subject: 
    10071007                continue 
     
    10381038    @undoable 
    10391039    def execute(self): 
     1040        # TODO: AJM: disabled action 
     1041        return 
    10401042        diagram_tab = self._window.get_current_diagram_tab() 
    10411043        diagram = diagram_tab.get_diagram() 
  • gaphor/branches/new-canvas/gaphor/diagram/classifier.py

    r1044 r1070  
    1818    A compartment has a line on top and a list of FeatureItems. 
    1919    """ 
    20  
    21     MARGIN_X = 5  
    22     MARGIN_Y = 5 
    2320 
    2421    def __init__(self, name, owner): 
     
    5956            self.width = max(map(lambda p: p[0], sizes)) 
    6057            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] 
    6361 
    6462    def update(self, context): 
     
    6967    def draw(self, context): 
    7068        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]) 
    7271        for item in self: 
    7372            cr.save() 
     
    108107    DRAW_ICON = 3 
    109108 
     109    __style__ = { 
     110        'icon-size': (20, 20), 
     111        'compartment-margin': (5, 5, 5, 5), # (top, right, bottom, left) 
     112        } 
    110113    # Default size for small icons 
    111114    ICON_WIDTH    = 15 
     
    248251            comp.pre_update(context) 
    249252 
    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) 
    272274 
    273275    def pre_update_compartment_icon(self, context): 
     
    275277 
    276278    def pre_update_icon(self, context): 
    277         pass 
     279        super(ClassifierItem, self).pre_update(context) 
    278280 
    279281    def update_compartment(self, context): 
     
    288290 
    289291    def update_icon(self, context): 
    290         """Update state to draw as one big icon. 
     292        """ 
    291293        """ 
    292294        pass 
  • gaphor/branches/new-canvas/gaphor/diagram/diagramitem.py

    r1068 r1070  
    8282            print self, 'subject =', self.subject 
    8383        else: 
    84             #log.debug('Setting unknown property "%s" -> "%s"' % (name, value)) 
     84            log.debug('Setting unknown property "%s" -> "%s"' % (name, value)) 
    8585            try: 
    86                 setattr(self, name, eval(value)) 
     86                setattr(self, name.replace('-', '_'), eval(value)) 
    8787            except: 
    8888                log.warning('%s has no property named %s (value %s)' % (self, name, value)) 
  • gaphor/branches/new-canvas/gaphor/diagram/interface.py

    r1059 r1070  
    44 
    55import itertools 
     6from math import pi 
    67from gaphas.item import NW, SE 
    78from gaphor import UML 
     
    2627    __uml__        = UML.Interface 
    2728    __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        } 
    2935    RADIUS_PROVIDED = 10 
    3036    RADIUS_REQUIRED = 14 
     
    116122 
    117123  
    118     def update_icon(self, context): 
     124    def pre_update_icon(self, context): 
    119125        """Figure out if this interface represents a required, provided, 
    120126        assembled (wired) or dotted (minimal) look. 
    121127        """ 
     128        for h in self._handles: h.movable = False 
     129        self.style.name_outside = True 
     130 
    122131        h_nw = self._handles[NW] 
    123         cx, xy = h_nw.x + self.width/2, h_nw.y + self.height/2 
     132        cx, cy = h_nw.x + self.width/2, h_nw.y + self.height/2 
    124133        self._draw_required = self._draw_provided = False 
    125134        for item, handle in self.canvas.get_connected_items(self): 
     
    128137            elif gives_provided(handle): 
    129138                self._draw_provided = True 
    130         radius = RADIUS_PROVIDED 
     139        radius = self.RADIUS_PROVIDED 
     140        self.style.icon_size = self.style.icon_size_provided 
    131141        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 
    135148        h_se = self._handles[SE] 
    136         h_se.x, h_se.y = cx + radius, cy + radius 
    137  
     149        #h_se.x, h_se.y = cx + radius, cy + radius 
     150        super(InterfaceItem, self).pre_update(context) 
    138151 
    139152    def draw_icon(self, context): 
     
    142155        cx, cy = h_nw.x + self.width/2, h_nw.y + self.height/2 
    143156        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) 
    146159            cr.stroke() 
    147160        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) 
    150163            cr.stroke() 
     164        super(InterfaceItem, self).draw(context) 
    151165 
    152166    def on_glue(self, handle, wx, wy):