Skip to content
14 changes: 7 additions & 7 deletions enable/constraints_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ def __components_items_changed(self, event):
"""
# Remove stale components from the map
for item in event.removed:
item.on_trait_change(
self._component_size_hint_changed,
item.observe(
self._handle_changed_component_size_hint,
"layout_size_hint",
remove=True,
)
Expand All @@ -267,8 +267,8 @@ def __components_changed(self, new):
"""
# Clear the component maps
for key, item in self._component_map.items():
item.on_trait_change(
self._component_size_hint_changed,
item.observe(
self._handle_changed_component_size_hint,
"layout_size_hint",
remove=True,
)
Expand All @@ -277,7 +277,7 @@ def __components_changed(self, new):
# Check the new components
self._check_and_add_components(new)

def _component_size_hint_changed(self):
def _handle_changed_component_size_hint(self, event):
""" Refresh the size hint contraints for a child component
"""
self.relayout()
Expand Down Expand Up @@ -369,8 +369,8 @@ def _check_and_add_components(self, components):
raise ValueError(msg)

self._component_map[key] = item
item.on_trait_change(
self._component_size_hint_changed, "layout_size_hint"
item.observe(
self._handle_changed_component_size_hint, "layout_size_hint"
)

# Update the layout
Expand Down
7 changes: 4 additions & 3 deletions enable/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ def _auto_size_changed(self, old, new):
else:
pass

def _window_resized(self, newsize):
def _window_resized(self, event):
newsize = event.new
if newsize is not None:
self.bounds = [newsize[0] - self.x, newsize[1] - self.y]

Expand All @@ -564,11 +565,11 @@ def _window_resized(self, newsize):
def _fit_window_changed(self, old, new):
if self._window is not None:
if not self.fit_window:
self._window.on_trait_change(
self._window.observe(
self._window_resized, "resized", remove=True
)
else:
self._window.on_trait_change(self._window_resized, "resized")
self._window.observe(self._window_resized, "resized")

def _bounds_changed(self, old, new):
# crappy... calling our parent's handler seems like a common traits
Expand Down
40 changes: 22 additions & 18 deletions enable/scrolled.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,22 +267,24 @@ def _view_position_changed_for_viewport_component(self):
def _view_position_items_changed_for_viewport_component(self):
self.update_from_viewport()

def _component_bounds_items_handler(self, object, event):
def _component_bounds_items_handler(self, event):
if event.added != event.removed:
self.update_bounds()

def _component_bounds_handler(self, object, name, old, new):
def _component_bounds_handler(self, event):
old = event.old
new = event.new
if old is None or new is None or old[0] != new[0] or old[1] != new[1]:
self.update_bounds()

def _component_changed(self, old, new):
if old is not None:
old.on_trait_change(
old.observe(
self._component_bounds_handler, "bounds", remove=True
)
old.on_trait_change(
old.observe(
self._component_bounds_items_handler,
"bounds_items",
"bounds:items",
remove=True,
)
if new is None:
Expand All @@ -291,9 +293,9 @@ def _component_changed(self, old, new):
if self.viewport_component:
self.viewport_component.component = new
new.container = self
new.on_trait_change(self._component_bounds_handler, "bounds")
new.on_trait_change(
self._component_bounds_items_handler, "bounds_items"
new.observe(self._component_bounds_handler, "bounds")
new.observe(
self._component_bounds_items_handler, "bounds:items"
)
self._layout_needed = True

Expand Down Expand Up @@ -421,11 +423,11 @@ def _do_layout(self):
)
v_pos = self.viewport_component.view_position
self._hsb.scroll_position = v_pos[0]
self._hsb.on_trait_change(
self._hsb.observe(
self._handle_horizontal_scroll, "scroll_position"
)
self._hsb.on_trait_change(
self._mouse_thumb_changed, "mouse_thumb"
self._hsb.observe(
self._handle_mouse_thumb, "mouse_thumb"
)
self.add(self._hsb)
else:
Expand Down Expand Up @@ -462,11 +464,11 @@ def _do_layout(self):
)
v_pos = self.viewport_component.view_position
self._vsb.scroll_position = v_pos[1]
self._vsb.on_trait_change(
self._vsb.observe(
self._handle_vertical_scroll, "scroll_position"
)
self._vsb.on_trait_change(
self._mouse_thumb_changed, "mouse_thumb"
self._vsb.observe(
self._handle_mouse_thumb, "mouse_thumb"
)
self.add(self._vsb)
else:
Expand Down Expand Up @@ -503,7 +505,8 @@ def _release_sb(self, sb):
sb.destroy()
return None

def _handle_horizontal_scroll(self, position):
def _handle_horizontal_scroll(self, event):
position = event.new
if self._sb_bounds_frozen:
self._hscroll_position_updated = True
return
Expand All @@ -519,7 +522,8 @@ def _handle_horizontal_scroll(self, position):
view_position=[position, viewport.view_position[1]]
)

def _handle_vertical_scroll(self, position):
def _handle_vertical_scroll(self, event):
position = event.new
if self._sb_bounds_frozen:
self._vscroll_position_updated = True
return
Expand All @@ -535,8 +539,8 @@ def _handle_vertical_scroll(self, position):
view_position=[viewport.view_position[0], position]
)

def _mouse_thumb_changed(self, object, attrname, event):
if event == "down" and not self.continuous_drag_update:
def _handle_mouse_thumb(self, event):
if event.new == "down" and not self.continuous_drag_update:
self.freeze_scroll_bounds()
else:
self.unfreeze_scroll_bounds()
Expand Down