~glitter-team/glitter/trunk

« back to all changes in this revision

Viewing changes to glitter/box.py

  • Committer: Jan Jokela
  • Date: 2009-05-12 17:08:05 UTC
  • mto: (38.2.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: jan@jan-laptop-20090512170805-jw2qtp149hj5i4v6
(glitter/tests/*) Added and improved a bunch of tests; (glitter/data/themes/nublo/styles/label.json) Fixes in label widget style; (glitter/box.py) Layout code fixes

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        
41
41
        for key, value in props:
42
42
            if key == 'spacing':
43
 
                self.spacing = value
 
43
                self._spacing = value
44
44
            elif key == 'alignment':
45
 
                self.alignment = value
 
45
                self._alignment = value
46
46
                
47
47
    def _update_layout(self):
48
48
        """ Update layout """
92
92
        """
93
93
        
94
94
        self._spacing = value
 
95
        self._update_layout()
95
96
                
96
97
    spacing = property(get_spacing, set_spacing)
97
98
        
107
108
        """
108
109
        
109
110
        self._alignment = value
 
111
        self._update_layout()
110
112
        
111
113
    alignment = property(get_alignment, set_alignment)
112
114
        
134
136
        fixed_width_children = []
135
137
        # For fixed width children and layouting
136
138
        if len(self.packed_children) > 0:
 
139
            # Reserved width for spacing between 
137
140
            reserved_width = self.spacing * (len(self.packed_children) - 1) * \
138
141
              self.get_widthu()
139
142
        else:
140
143
            reserved_width = 0.0
141
144
        
142
145
        # Discover fixed width children and update the reserved height
143
 
        for child in self.packed_children:         
 
146
        for child in self.packed_children:     
144
147
            if child.size_ratio > 0 or \
145
148
              (child.minimum_width > 0 and child.natural_width == 0):
146
149
                fixed_width_children.append(child)
162
165
        # Position all children
163
166
        current_x = 0.0
164
167
        for child in self.packed_children:
165
 
            current_x += child.get_widthu() * child.h_offset
 
168
            if child not in fixed_width_children:
 
169
                offset_width = var_child_width * child.h_offset
 
170
            else:
 
171
                offset_width = child.h_offset * child.get_widthu()
 
172
            current_x += offset_width
166
173
            if self.get_widthu() > 0:
167
174
                child.natural_x = current_x / self.get_widthu()
168
175
                if child not in fixed_width_children:
169
 
                    child.natural_width = var_child_width / self.get_widthu()
 
176
                    child.natural_width = (var_child_width - 2 * offset_width) \
 
177
                    / self.get_widthu()
170
178
            child._update_layout()
171
179
            current_x += child.get_widthu()
172
180
            current_x += child.get_widthu() * child.h_offset
230
238
        # Position all children
231
239
        current_y = 0.0
232
240
        for child in self.packed_children:
233
 
            current_y += child.get_heightu() * child.v_offset
 
241
            if child not in fixed_height_children:
 
242
                offset_height = var_child_height * child.v_offset
 
243
            else:
 
244
                offset_height = child.v_offset * child.get_heightu()
 
245
            current_y += offset_height
234
246
            if self.get_heightu() > 0:
235
247
                child.natural_y = current_y / self.get_heightu()
236
248
                if child not in fixed_height_children:
237
 
                    child.natural_height = var_child_height / self.get_heightu()
 
249
                    child.natural_height = (var_child_height - 2 * offset_height) \
 
250
                    / self.get_heightu()
238
251
            child._update_layout()
239
252
            current_y += child.get_heightu()
240
253
            current_y += child.get_heightu() * child.v_offset