# HG changeset patch # User phoku@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1251105628 0 # Node ID d8bcff5f7222b3e7599f3c3bf1dfa72c42256c9f # Parent e496e368185580fa371483644f450eede8fa6e6d PyChan: adaptLayout performance fix. diff -r e496e3681855 -r d8bcff5f7222 engine/extensions/pychan/widgets/layout.py --- a/engine/extensions/pychan/widgets/layout.py Fri Aug 21 23:54:39 2009 +0000 +++ b/engine/extensions/pychan/widgets/layout.py Mon Aug 24 09:20:28 2009 +0000 @@ -83,18 +83,23 @@ #print "SPACERS",self.spacer index = 0 + n = len(expandable_items) while used_space < available_space and expandable_items: - index = index % len(expandable_items) + index = index % n + delta = (available_space - used_space) / n + if delta == 0: + delta = 1 expander = expandable_items[index] old_width = expander.width - expander.width += 1 - if old_width == expander.width: + expander.width += delta + delta = expander.width - old_width + if delta == 0: expandable_items.pop(index) + n -= 1 else: - used_space += 1 + used_space += delta index += 1 - #print "AS/US - after",self,[o.width for o in expandable_items] #print "SPACERS",self.spacer self._applyWidth(spacers = self.spacer[:]) @@ -116,16 +121,22 @@ #print "AS/US - before",self,[o.height for o in expandable_items] index = 0 + n = len(expandable_items) while used_space < available_space and expandable_items: - index = index % len(expandable_items) + index = index % n + delta = (available_space - used_space) / n + if delta == 0: + delta = 1 expander = expandable_items[index] - old_width = expander.height - expander.height += 1 - if old_width == expander.height: + old_height = expander.height + expander.height += delta + delta = expander.height - old_height + if delta == 0: expandable_items.pop(index) + n -= 1 else: - used_space += 1 + used_space += delta index += 1 #print "AS/US - after",self,[o.height for o in expandable_items]