Changeset 993
- Timestamp:
- 09/04/06 07:23:26 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/branches/new-canvas/gaphor/diagram/classifier.py
r990 r993 4 4 import itertools 5 5 6 from gaphas.util import text_extents, text_center 6 from gaphas.util import text_extents, text_center, text_set_font 7 7 from gaphor import UML 8 8 from gaphor.i18n import _ … … 43 43 44 44 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 """ 45 48 return self.width, self.height 46 49 47 50 def pre_update(self, context): 51 """Pre update, determine width and height of the compartment. 52 """ 53 self.width = self.height = 0 48 54 cr = context.cairo 49 55 for item in self: … … 54 60 self.height = sum(map(lambda p: p[1], sizes)) 55 61 self.width += 2 * self.MARGIN_X 56 self.height += 2 *self.MARGIN_Y62 self.height += 2 * self.MARGIN_Y 57 63 58 64 def update(self, context): … … 239 245 240 246 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 245 248 246 249 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 253 259 254 260 def pre_update_compartment_icon(self, context): … … 266 272 self.pre_update_icon(context) 267 273 274 super(ClassifierItem, self).pre_update(context) 275 268 276 def update_compartment(self, context): 269 277 """Update state for box-style presentation. … … 297 305 self.update_icon(context) 298 306 299 NamedItem.update(self,context)307 super(ClassifierItem, self).update(context) 300 308 301 309 def draw_compartment(self, context): 302 310 cr = context.cairo 303 311 cr.rectangle(0, 0, self.width, self.height) 312 cr.stroke() 304 313 y = 0 305 314 306 315 # draw stereotype 316 y += 10 307 317 if self.stereotype: 308 y += 10318 text_set_font(cr, self.FONT_NAME) 309 319 text_center(cr, self.width / 2, y, self.stereotype) 310 320 311 321 # draw name 312 322 y += 10 323 text_set_font(cr, self.FONT_FROM) 313 324 text_center(cr, self.width / 2, y, self.subject.name) 314 325 326 y += 10 315 327 # draw 'from ... ' 316 if self. subject.namespace and self.canvas.diagram.namespace:317 y += 10318 text_center(cr, self.width / 2, y, 'from: ' + self.subject.namespace.name)319 320 y += 10328 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 321 333 cr.translate(0, y) 322 334 … … 324 336 for comp in self._compartments: 325 337 cr.save() 338 cr.move_to(0, 0) 339 cr.line_to(self.width, 0) 340 cr.stroke() 326 341 try: 327 342 comp.draw(context) 328 343 finally: 329 344 cr.restore() 345 cr.translate(0, comp.height) 330 346 331 347 def draw(self, context): gaphor/branches/new-canvas/gaphor/diagram/nameditem.py
r977 r993 181 181 interface.implements(INamedItemView) 182 182 183 NAME_FONT= 'sans bold 10'183 FONT_NAME = 'sans bold 10' 184 184 185 185 #def __init__(self): 186 186 #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)) 188 188 #self._name.set_alignment(pango.ALIGN_CENTER) 189 189 #self._name.set_wrap_mode(diacanvas.shape.WRAP_NONE) gaphor/branches/new-canvas/gaphor/diagram/tests/test_class.py
r990 r993 25 25 26 26 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)) 29 29 30 30 attr = UML.create(UML.Property)
