Changeset 993

Show
Ignore:
Timestamp:
09/04/06 07:23:26 (2 years ago)
Author:
arjanmol
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/gaphor/diagram/classifier.py

    r990 r993  
    44import itertools 
    55 
    6 from gaphas.util import text_extents, text_center 
     6from gaphas.util import text_extents, text_center, text_set_font 
    77from gaphor import UML 
    88from gaphor.i18n import _ 
     
    4343 
    4444    def get_size(self): 
     45        """Get width, height of the compartment. pre_update should have 
     46        been called so widthand height have been calculated. 
     47        """ 
    4548        return self.width, self.height 
    4649 
    4750    def pre_update(self, context): 
     51        """Pre update, determine width and height of the compartment. 
     52        """ 
     53        self.width = self.height = 0 
    4854        cr = context.cairo 
    4955        for item in self: 
     
    5460            self.height = sum(map(lambda p: p[1], sizes)) 
    5561        self.width += 2 * self.MARGIN_X 
    56         self.height += 2*self.MARGIN_Y 
     62        self.height += 2 * self.MARGIN_Y 
    5763 
    5864    def update(self, context): 
     
    239245 
    240246            self.min_width = max(s_w, n_w, f_w) 
    241             self.min_height = 30 
    242  
    243             if self.stereotype: 
    244                 min_height += 10 
     247            self.min_height = 35 
    245248 
    246249            if sizes: 
    247                 width = max(map(lambda p: p[0], sizes)) 
    248  
    249                 height = sum(map(lambda p: p[1], sizes)) 
    250                 #height += len(self._compartments) * Compartment.MARGIN_Y * 2 
    251                 self.min_width = max(self.min_width, width) 
    252                 self.min_height += height 
     250                w = max(map(lambda p: p[0], sizes)) 
     251 
     252                h = sum(map(lambda p: p[1], sizes)) 
     253                self.min_width = max(self.min_width, w) 
     254                self.min_height += h 
     255            if self.width < self.min_width: 
     256                self.width = self.min_width 
     257            if self.height < self.min_height: 
     258                self.height = self.min_height 
    253259 
    254260    def pre_update_compartment_icon(self, context): 
     
    266272            self.pre_update_icon(context) 
    267273 
     274        super(ClassifierItem, self).pre_update(context) 
     275 
    268276    def update_compartment(self, context): 
    269277        """Update state for box-style presentation. 
     
    297305            self.update_icon(context) 
    298306 
    299         NamedItem.update(self, context) 
     307        super(ClassifierItem, self).update(context) 
    300308 
    301309    def draw_compartment(self, context): 
    302310        cr = context.cairo 
    303311        cr.rectangle(0, 0, self.width, self.height) 
     312        cr.stroke() 
    304313        y = 0 
    305314 
    306315        # draw stereotype 
     316        y += 10 
    307317        if self.stereotype: 
    308             y += 10 
     318            text_set_font(cr, self.FONT_NAME) 
    309319            text_center(cr, self.width / 2, y, self.stereotype) 
    310320 
    311321        # draw name 
    312322        y += 10 
     323        text_set_font(cr, self.FONT_FROM) 
    313324        text_center(cr, self.width / 2, y, self.subject.name) 
    314325 
     326        y += 10 
    315327        # draw 'from ... ' 
    316         if self.subject.namespace and self.canvas.diagram.namespace
    317             y += 10 
    318             text_center(cr, self.width / 2, y, 'from: ' + self.subject.namespace.name
    319  
    320         y += 10 
     328        if self._from
     329            text_set_font(cr, self.FONT_FROM) 
     330            text_center(cr, self.width / 2, y, self._from
     331 
     332        y += 5 
    321333        cr.translate(0, y) 
    322334 
     
    324336        for comp in self._compartments: 
    325337            cr.save() 
     338            cr.move_to(0, 0) 
     339            cr.line_to(self.width, 0) 
     340            cr.stroke() 
    326341            try: 
    327342                comp.draw(context) 
    328343            finally: 
    329344                cr.restore() 
     345            cr.translate(0, comp.height) 
    330346 
    331347    def draw(self, context): 
  • gaphor/branches/new-canvas/gaphor/diagram/nameditem.py

    r977 r993  
    181181    interface.implements(INamedItemView) 
    182182 
    183     NAME_FONT = 'sans bold 10' 
     183    FONT_NAME = 'sans bold 10' 
    184184 
    185185    #def __init__(self): 
    186186        #self._name = diacanvas.shape.Text() 
    187         #self._name.set_font_description(pango.FontDescription(self.NAME_FONT)) 
     187        #self._name.set_font_description(pango.FontDescription(self._FONT)) 
    188188        #self._name.set_alignment(pango.ALIGN_CENTER) 
    189189        #self._name.set_wrap_mode(diacanvas.shape.WRAP_NONE) 
  • gaphor/branches/new-canvas/gaphor/diagram/tests/test_class.py

    r990 r993  
    2525 
    2626        self.assertEqual((10, 10), klass._compartments[0].get_size()) 
    27         self.assertEqual(40, float(klass.min_height)) 
    28         self.assertEqual(20, float(klass.min_width)) 
     27        self.assertEqual(55, float(klass.min_height)) # 35 + 2 * 10 
     28        self.assertEqual(10, float(klass.min_width)) 
    2929 
    3030        attr = UML.create(UML.Property)