Changeset 1059
- Timestamp:
- 11/02/06 20:30:28 (2 years ago)
- Files:
-
- gaphor/branches/new-canvas/gaphor/diagram/__init__.py (modified) (2 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/action.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py (modified) (3 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/align.py (deleted)
- gaphor/branches/new-canvas/gaphor/diagram/interface.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/nameditem.py (modified) (4 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/package.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/style.py (added)
- gaphor/branches/new-canvas/gaphor/diagram/tests/test_style.py (added)
- gaphor/branches/new-canvas/gaphor/diagram/usecase.py (modified) (1 diff)
- gaphor/branches/new-canvas/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/branches/new-canvas/gaphor/diagram/__init__.py
r1053 r1059 13 13 14 14 from gaphor.misc import uniqueid 15 from gaphor.diagram. align import ItemAlign15 from gaphor.diagram.style import Style 16 16 17 17 # Map UML elements to their (default) representation. … … 31 31 global _uml_to_item_map 32 32 _uml_to_item_map[element] = item 33 34 35 36 class Style(object):37 """38 Item style information. Style information is provided through object's39 attributes, i.e.::40 41 class InitialNodeItem42 __style__ = {43 'name-align': ('center', 'top'),44 }45 46 is translated to::47 48 >>> print style.name_align49 ('center', 'top')50 """51 def add(self, name, value):52 """53 Add style variable.54 55 Variable name can contain hyphens, which is converted to56 underscode, i.e. 'name-align' -> 'name_align'.57 58 @param name: style variable name59 @param value: style variable value60 """61 name = name.replace('-', '_')62 setattr(self, name, value)63 64 65 def items(self):66 """67 Return iterator of (name, value) style information items.68 """69 return self.__dict__.iteritems()70 33 71 34 gaphor/branches/new-canvas/gaphor/diagram/action.py
r1058 r1059 6 6 7 7 from gaphor import UML 8 from gaphor.diagram.nameditem import NamedItem, ALIGN_CENTER, ALIGN_MIDDLE 8 from gaphor.diagram.nameditem import NamedItem 9 from gaphor.diagram.style import ALIGN_CENTER, ALIGN_MIDDLE 9 10 from gaphas.util import text_align, text_extents 10 11 gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py
r1046 r1059 14 14 #from gaphor.diagram.groupable import GroupBase 15 15 from gaphor.diagram.nameditem import NamedItem 16 from gaphor.diagram.align import H_ALIGN_LEFT, H_ALIGN_RIGHT, V_ALIGN_BOTTOM17 16 18 17 … … 151 150 152 151 __uml__ = UML.DecisionNode 153 __s_align__ = H_ALIGN_LEFT152 #__s_align__ = H_ALIGN_LEFT 154 153 155 154 RADIUS = 15 … … 182 181 """ 183 182 __uml__ = UML.ForkNode 184 __s_valign__ = V_ALIGN_BOTTOM183 #__s_valign__ = V_ALIGN_BOTTOM 185 184 186 185 WIDTH = 6.0 gaphor/branches/new-canvas/gaphor/diagram/interface.py
r1011 r1059 6 6 from gaphas.item import NW, SE 7 7 from gaphor import UML 8 from gaphor.diagram.align import V_ALIGN_BOTTOM9 8 from gaphor.diagram.dependency import DependencyItem 10 9 from gaphor.diagram.implementation import ImplementationItem gaphor/branches/new-canvas/gaphor/diagram/nameditem.py
r1058 r1059 4 4 """ 5 5 6 # padding 7 PADDING_TOP, PADDING_RIGHT, PADDING_BOTTOM, PADDING_LEFT = range(4) 8 # horizontal align 9 ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT = range(3) 10 # vertical align 11 ALIGN_TOP, ALIGN_MIDDLE, ALIGN_BOTTOM = range(3) 12 6 from gaphas.util import text_extents 13 7 14 8 from gaphor.diagram.elementitem import ElementItem 15 from gaphas.util import text_align, text_extents 9 from gaphor.diagram.style import get_min_size, get_text_point, \ 10 ALIGN_CENTER, ALIGN_TOP 16 11 17 12 … … 44 39 self.width = self.min_width 45 40 self.height = self.min_height 41 self.name_x = 0 42 self.name_y = 0 46 43 47 44 48 45 def pre_update(self, context): 46 """ 47 Calculate minimal size of named item. 48 """ 49 cr = context.cairo 50 text = self.subject.name 51 if text: 52 width, height = text_extents(cr, text) 53 self.min_width, self.min_height = get_min_size(width, height, 54 self.style.name_padding) 55 super(NamedItem, self).pre_update(context) 56 57 58 def update(self, context): 49 59 """ 50 60 Calculate position of item's name. … … 54 64 if text: 55 65 width, height = text_extents(cr, text) 56 self.min_width, self.min_height = \ 57 get_min_size(width, height, self.style.name_padding) 58 super(NamedItem, self).pre_update(context) 66 self.name_x, self.name_y = get_text_point(text_extents(cr, text), 67 self.width, self.height, 68 self.style.name_align, self.style.name_padding, 69 self.style.name_outside) 70 super(NamedItem, self).update(context) 59 71 60 72 … … 67 79 text = self.subject.name 68 80 if text: 69 x, y = get_pos(cr, text, self.width, self.height, 70 self.style.name_align, self.style.name_padding, 71 self.style.name_outside) 72 cr.move_to(x, y) 81 cr.move_to(self.name_x, self.name_y) 73 82 cr.show_text(text) 74 83 super(NamedItem, self).draw(context) 75 76 77 78 79 def get_min_size(width, height, padding):80 """81 Get minimum size of an object using padding information.82 83 @param width: object width84 @param height: object height85 @param padding: padding information as a tuple86 (top, right, bottom, left)87 88 fixme: move this method outside the class some utility function to89 other package?90 """91 return width + padding[PADDING_LEFT] + padding[PADDING_RIGHT], \92 height + padding[PADDING_TOP] + padding[PADDING_BOTTOM]93 94 95 def get_pos(cr, text, width, height, align, padding, outside):96 """97 Calculate position of the text relative to containing box defined by98 tuple (0, 0, width, height). Text is aligned using align and padding99 information. It can be also placed outside the box if @C{outside}100 parameter is set to @C{True}.101 102 @param width: width of the containing box103 @param height: height of the containing box104 @param align: text align information (center, top, etc.)105 @param padding: text padding106 @param outside: should text be put outside containing box107 108 fixme: move this method outside the class some utility function to109 other package?110 """111 assert text112 113 x_bear, y_bear, w, h, x_adv, y_adv = cr.text_extents(text)114 115 halign, valign = align116 117 if outside:118 if halign == ALIGN_LEFT:119 x = -w - padding[PADDING_LEFT]120 elif halign == ALIGN_CENTER:121 x = (width - w) / 2122 elif halign == ALIGN_RIGHT:123 x = width + padding[PADDING_RIGHT]124 else:125 assert False126 127 if valign == ALIGN_TOP:128 y = -h - padding[PADDING_TOP]129 elif valign == ALIGN_MIDDLE:130 y = (height - h) / 2131 elif valign == ALIGN_BOTTOM:132 y = height + padding[PADDING_BOTTOM]133 else:134 assert False135 136 else:137 if halign == ALIGN_LEFT:138 x = padding[PADDING_LEFT]139 elif halign == ALIGN_CENTER:140 x = (width - w) / 2141 elif halign == ALIGN_RIGHT:142 x = width - w - padding[PADDING_RIGHT]143 else:144 assert False145 146 if valign == ALIGN_TOP:147 y = h + padding[PADDING_TOP]148 elif valign == ALIGN_MIDDLE:149 y = (height + h) / 2150 elif valign == ALIGN_BOTTOM:151 y = height - h - padding[PADDING_BOTTOM]152 else:153 assert False154 return x, y155 156 157 # maybe useful for align routines, we will see158 ###A### def update_name(self, affine):159 ###A### def set_st_pos(text, x, y, width, height):160 ###A### text.set_pos((x, y))161 ###A### text.set_max_width(width)162 ###A### text.set_max_height(height)163 ###A###164 ###A### nalign = self.n_align165 ###A### salign = self.s_align166 ###A###167 ###A### if self._has_stereotype:168 ###A### sw, sh = self.get_text_size(self._stereotype)169 ###A### nw, nh = self.get_text_size(self._name)170 ###A###171 ###A### width = max(sw, nw)172 ###A### height = sh + nh173 ###A###174 ###A### # set stereotype position175 ###A### sx, sy = salign.get_pos(self._stereotype, width, height, self.width, self.height)176 ###A### set_st_pos(self._stereotype, sx, sy, sw, sh)177 ###A###178 ###A### # place name below stereotype179 ###A### nx = sx + (sw - nw) / 2.0180 ###A### ny = sy + sh181 ###A### set_st_pos(self._name, nx, ny, nw, nh)182 ###A###183 ###A### # determine position and size of stereotype and name placed184 ###A### # together185 ###A### x = min(sx, nx)186 ###A### y = sy187 ###A###188 ###A### align = salign189 ###A### else:190 ###A### width, height = self.get_text_size(self._name)191 ###A### x, y = nalign.get_pos(self._name, width, height, self.width, self.height)192 ###A### set_st_pos(self._name, x, y, width, height)193 ###A###194 ###A### align = nalign195 ###A###196 ###A### if not align.outside:197 ###A### min_width, min_height = align.get_min_size(width, height)198 ###A### self.set(min_width = min_width, min_height = min_height)199 ###A###200 ###A### return align, x, y, width, height201 ###A###202 ###A### def on_update(self, affine):203 ###A### align, x, y, width, height = self.update_name(affine)204 ###A###205 ###A### ElementItem.on_update(self, affine)206 ###A###207 ###A### if align.outside:208 ###A### wx, hy = x + width, y + height209 ###A### self.set_bounds((min(0, x), min(0, y),210 ###A### max(self.width, wx), max(self.height, hy)))211 ###A###212 ###A### self.draw_border()213 ###A### self.expand_bounds(1.0)214 215 216 # vim:sw=4:etgaphor/branches/new-canvas/gaphor/diagram/package.py
r1058 r1059 15 15 } 16 16 __style__ = { 17 'name-padding': ( 35, 10, 5, 10),17 'name-padding': (25, 10, 5, 10), 18 18 } 19 19 20 20 TAB_X = 50 21 21 TAB_Y = 20 22 23 def __init__(self, id):24 NamedItem.__init__(self, id, 120, 60)25 26 22 27 23 def pre_update(self, context): gaphor/branches/new-canvas/gaphor/diagram/usecase.py
r1058 r1059 7 7 from gaphor import UML 8 8 from gaphor.diagram.classifier import ClassifierItem 9 from gaphor.diagram. nameditemimport ALIGN_CENTER, ALIGN_MIDDLE9 from gaphor.diagram.style import ALIGN_CENTER, ALIGN_MIDDLE 10 10 from gaphas.util import text_align, text_extents, path_ellipse 11 11 gaphor/branches/new-canvas/setup.py
r1049 r1059 25 25 'gaphor.diagram.tests.test_handletool', 26 26 'gaphor.diagram.tests.test_interfaces', 27 'gaphor.diagram.tests.test_style', 27 28 'gaphor.ui.tests.test_diagramtab', 28 29 'gaphor.ui.tests.test_mainwindow',
