Skip to content

Commit

Permalink
Fix size hint bug in relayout.
Browse files Browse the repository at this point in the history
Fix bug in wx layout timer.
  • Loading branch information
sccolbert committed Apr 2, 2013
1 parent b0f656a commit 963cee8
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 157 deletions.
35 changes: 0 additions & 35 deletions enaml/qt/qt_constraints_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ def relayout(self):
layout request is dropped.
"""
self.clear_size_hint_constraints()
parent = self.parent()
if isinstance(parent, QtConstraintsWidget):
parent.relayout()
Expand Down Expand Up @@ -155,40 +154,6 @@ def replace_constraints(self, old_cns, new_cns):
if isinstance(parent, QtConstraintsWidget):
parent.replace_constraints(old_cns, new_cns)

def clear_constraints(self, cns):
""" Clear the given constraints from the current layout system.
The default behavior of this method is to proxy the call up the
tree of ancestors until it is either handled by a subclass which
has reimplemented this method (see QtContainer), or the ancestor
is not an instance of QtConstraintsWidget, at which point the
request is dropped. This method will *not* trigger a relayout.
Parameters
----------
cns : list
The list of casuarius constraints to remove from the
current layout system.
"""
parent = self.parent()
if isinstance(parent, QtConstraintsWidget):
parent.clear_constraints(cns)

def clear_size_hint_constraints(self):
""" Clear the size hint constraints from the layout system.
"""
# Only the ancestors of a widget care about its size hint and
# will have added those constraints to a layout, so this method
# attempts to replace the size hint constraints for the widget
# starting with its parent.
parent = self.parent()
if isinstance(parent, QtConstraintsWidget):
cns = self.size_hint_cns
del self.size_hint_cns
parent.clear_constraints(cns)

def size_hint_updated(self):
""" Notify the layout system that the size hint has changed.
Expand Down
37 changes: 8 additions & 29 deletions enaml/qt/qt_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,9 @@ def relayout(self):
"""
if self._owns_layout:
item = self.widget_item
old_hint = item.sizeHint()
self.init_cns_layout()
self._refresh()
new_hint = item.sizeHint()
# If the size hint constraints are empty, it indicates that
# they were previously cleared. In this case, the layout
# system must be notified to rebuild its constraints, even
# if the numeric size hint hasn't changed.
if old_hint != new_hint or not self.size_hint_cns:
self.size_hint_updated()
with size_hint_guard(self):
self.init_cns_layout()
self._refresh()
else:
self._layout_owner.relayout()

Expand Down Expand Up @@ -238,23 +230,6 @@ def replace_constraints(self, old_cns, new_cns):
else:
self._layout_owner.replace_constraints(old_cns, new_cns)

def clear_constraints(self, cns):
""" Clear the given constraints from the current layout.
Parameters
----------
cns : list
The list of casuarius constraints to remove from the
current layout system.
"""
if self._owns_layout:
manager = self._layout_manager
if manager is not None:
manager.replace_constraints(cns, [])
else:
self._layout_owner.clear_constraints(cns)

def contents_margins(self):
""" Get the contents margins for the container.
Expand Down Expand Up @@ -436,9 +411,13 @@ def _generate_constraints(self, layout_table):
cns.extend(expand_constraints(d, d.layout_constraints()))

# The first element in a layout table item is its offset index
# which is not relevant to constraints generation.
# which is not relevant to constraints generation. The child
# size hint constraints are refreshed unconditionally. This
# accounts for the potential changes in the size hint of a
# widget between relayouts.
for _, updater in layout_table:
child = updater.item
del child.size_hint_cns
d = child.declaration
cns.extend(hard_constraints(d))
if isinstance(child, QtContainer):
Expand Down
9 changes: 0 additions & 9 deletions enaml/qt/qt_flow_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,3 @@ def replace_constraints(self, old_cns, new_cns):
"""
pass

def clear_constraints(self, cns):
""" A reimplemented QtConstraintsWidget layout method.
Constraints layout may not cross the boundary of a FlowArea,
so this method is no-op which stops the layout propagation.
"""
pass
9 changes: 0 additions & 9 deletions enaml/qt/qt_scroll_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,6 @@ def replace_constraints(self, old_cns, new_cns):
"""
pass

def clear_constraints(self, cns):
""" A reimplemented QtConstraintsWidget layout method.
Constraints layout may not cross the boundary of a ScrollArea,
so this method is no-op which stops the layout propagation.
"""
pass

#--------------------------------------------------------------------------
# ProxyScrollArea API
#--------------------------------------------------------------------------
Expand Down
38 changes: 2 additions & 36 deletions enaml/wx/wx_constraints_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class wxLayoutTimer(wx.Timer):
"""
def __init__(self, owner):
super(wxLayoutTimer, self).__init__()
self.owner = owner

def Release(self):
Expand Down Expand Up @@ -112,7 +113,7 @@ def request_relayout(self):
if not self.layout_timer:
self.widget.Freeze()
self.layout_timer = wxLayoutTimer(self)
self.layout_timer.start(5, oneShot=True)
self.layout_timer.Start(1, oneShot=True)

def on_layout_triggered(self):
""" Handle the timeout even from the layout trigger timer.
Expand All @@ -139,7 +140,6 @@ def relayout(self):
layout request is dropped.
"""
self.clear_size_hint_constraints()
parent = self.parent()
if isinstance(parent, WxConstraintsWidget):
parent.relayout()
Expand Down Expand Up @@ -168,40 +168,6 @@ def replace_constraints(self, old_cns, new_cns):
if isinstance(parent, WxConstraintsWidget):
parent.replace_constraints(old_cns, new_cns)

def clear_constraints(self, cns):
""" Clear the given constraints from the current layout system.
The default behavior of this method is to proxy the call up the
tree of ancestors until it is either handled by a subclass which
has reimplemented this method (see WxContainer), or the ancestor
is not an instance of WxConstraintsWidget, at which point the
request is dropped. This method will *not* trigger a relayout.
Parameters
----------
cns : list
The list of casuarius constraints to remove from the
current layout system.
"""
parent = self.parent()
if isinstance(parent, WxConstraintsWidget):
parent.clear_constraints(cns)

def clear_size_hint_constraints(self):
""" Clear the size hint constraints from the layout system.
"""
# Only the ancestors of a widget care about its size hint and
# will have added those constraints to a layout, so this method
# attempts to replace the size hint constraints for the widget
# starting with its parent.
parent = self.parent()
if isinstance(parent, WxConstraintsWidget):
cns = self.size_hint_cns
del self.size_hint_cns
parent.clear_constraints(cns)

def size_hint_updated(self):
""" Notify the layout system that the size hint has changed.
Expand Down
39 changes: 9 additions & 30 deletions enaml/wx/wx_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,10 @@ def relayout(self):
"""
if self._owns_layout:
widget = self.widget
old_hint = widget.GetBestSize()
self.init_cns_layout()
if self._is_shown:
self._refresh()
new_hint = widget.GetBestSize()
# If the size hint constraints are empty, it indicates that
# they were previously cleared. In this case, the layout
# system must be notified to rebuild its constraints, even
# if the numeric size hint hasn't changed.
if old_hint != new_hint or not self.size_hint_cns:
self.size_hint_updated()
with size_hint_guard(self):
self.init_cns_layout()
if self._is_shown:
self._refresh()
else:
self._layout_owner.relayout()

Expand Down Expand Up @@ -251,23 +243,6 @@ def replace_constraints(self, old_cns, new_cns):
else:
self._layout_owner.replace_constraints(old_cns, new_cns)

def clear_constraints(self, cns):
""" Clear the given constraints from the current layout.
Parameters
----------
cns : list
The list of casuarius constraints to remove from the
current layout system.
"""
if self._owns_layout:
manager = self._layout_manager
if manager is not None:
manager.replace_constraints(cns, [])
else:
self._layout_owner.clear_constraints(cns)

def contents_margins(self):
""" Get the contents margins for the container.
Expand Down Expand Up @@ -447,9 +422,13 @@ def _generate_constraints(self, layout_table):
cns.extend(expand_constraints(d, d.layout_constraints()))

# The first element in a layout table item is its offset index
# which is not relevant to constraints generation.
# which is not relevant to constraints generation. The child
# size hint constraints are refreshed unconditionally. This
# accounts for the potential changes in the size hint of a
# widget between relayouts.
for _, updater in layout_table:
child = updater.item
del child.size_hint_cns
d = child.declaration
cns.extend(hard_constraints(d))
if isinstance(child, WxContainer):
Expand Down
9 changes: 0 additions & 9 deletions enaml/wx/wx_scroll_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,6 @@ def replace_constraints(self, old_cns, new_cns):
"""
pass

def clear_constraints(self, cns):
""" A reimplemented WxConstraintsWidget layout method.
Constraints layout may not cross the boundary of a ScrollArea,
so this method is no-op which stops the layout propagation.
"""
pass

#--------------------------------------------------------------------------
# ProxyScrollArea API
#--------------------------------------------------------------------------
Expand Down

0 comments on commit 963cee8

Please sign in to comment.