Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

FIX: properly destroy tasks actions

A few tasks-related actions did not properly dispose
of listeners to other object when they were destroyed.
  • Loading branch information...
commit d2328f09fa2d64aa9e71ef6ecfde9c10d0b62b03 1 parent 28e8de3
Pietro Berkes pberkes authored
22 pyface/tasks/action/dock_pane_toggle_group.py
View
@@ -1,13 +1,13 @@
# Enthought library imports.
from pyface.action.api import Action, ActionItem, Group
-from traits.api import Bool, Instance, List, Property, Unicode, on_trait_change
+from traits.api import Instance, List, Property, Unicode, on_trait_change
# Local imports.
from pyface.tasks.i_dock_pane import IDockPane
class DockPaneToggleAction(Action):
- """ An Action for toggling the visibily of a dock pane.
+ """ An Action for toggling the visibility of a dock pane.
"""
#### 'DockPaneToggleAction' interface #####################################
@@ -24,6 +24,14 @@ class DockPaneToggleAction(Action):
# 'Action' interface.
###########################################################################
+ def destroy(self):
+ super(DockPaneToggleAction, self).destroy()
+
+ # Make sure that we are not listening to changes to the pane anymore.
+ # In traits style, we will set the basic object to None and have the
+ # listener check that if it is still there.
+ self.dock_pane = None
+
def perform(self, event=None):
if self.dock_pane:
self.dock_pane.visible = not self.dock_pane.visible
@@ -33,18 +41,22 @@ def perform(self, event=None):
###########################################################################
def _get_name(self):
+ if self.dock_pane is None:
+ return 'DELETED DOCK TOGGLE'
return self.dock_pane.name
def _get_tooltip(self):
- return u'Toggles the visibilty of the %s pane.' % self.name
+ return u'Toggles the visibility of the %s pane.' % self.name
@on_trait_change('dock_pane.visible')
def _update_checked(self):
- self.checked = self.dock_pane.visible
+ if self.dock_pane:
+ self.checked = self.dock_pane.visible
@on_trait_change('dock_pane.closable')
def _update_visible(self):
- self.visible = self.dock_pane.closable
+ if self.dock_pane:
+ self.visible = self.dock_pane.closable
class DockPaneToggleGroup(Group):
15 pyface/tasks/action/listening_action.py
View
@@ -34,6 +34,21 @@ class ListeningAction(Action):
# 'Action' interface.
###########################################################################
+ def destroy(self):
+ """ Called when the action is no longer required.
+
+ Remove all the task listeners.
+
+ """
+
+ if self.object:
+ self.object.on_trait_change(
+ self._enabled_update, self.enabled_name, remove=True
+ )
+ self.object.on_trait_change(
+ self._visible_update, self.visible_name, remove=True
+ )
+
def perform(self, event=None):
""" Call the appropriate function.
"""
19 pyface/tasks/action/task_toggle_group.py
View
@@ -1,7 +1,6 @@
# Enthought library imports.
from pyface.action.api import Action, ActionItem, Group
-from traits.api import Any, Bool, List, Instance, Property, Unicode, \
- on_trait_change
+from traits.api import Any, List, Instance, Property, Unicode, on_trait_change
# Local imports.
from pyface.tasks.task import Task
@@ -26,6 +25,14 @@ class TaskToggleAction(Action):
# 'Action' interface.
###########################################################################
+ def destroy(self):
+ super(TaskToggleAction, self).destroy()
+
+ # Make sure that we are not listening to changes in the task anymore
+ # In traits style, we will set the basic object to None and have the
+ # listener check that if it is still there.
+ self.task = None
+
def perform(self, event=None):
window = self.task.window
window.activate_task(self.task)
@@ -35,6 +42,8 @@ def perform(self, event=None):
###########################################################################
def _get_name(self):
+ if self.task is None:
+ return 'DELETED TASK TOGGLE'
return self.task.name
def _get_tooltip(self):
@@ -42,8 +51,10 @@ def _get_tooltip(self):
@on_trait_change('task.window.active_task')
def _update_checked(self):
- window = self.task.window
- self.checked = window is not None and window.active_task == self.task
+ if self.task:
+ window = self.task.window
+ self.checked = (window is not None
+ and window.active_task == self.task)
class TaskToggleGroup(Group):
Please sign in to comment.
Something went wrong with that request. Please try again.