diff --git a/pyface/tasks/action/dock_pane_toggle_group.py b/pyface/tasks/action/dock_pane_toggle_group.py index 0bb3edd54..4fd2dcf52 100644 --- a/pyface/tasks/action/dock_pane_toggle_group.py +++ b/pyface/tasks/action/dock_pane_toggle_group.py @@ -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): diff --git a/pyface/tasks/action/listening_action.py b/pyface/tasks/action/listening_action.py index 04ff76678..a891a8d70 100644 --- a/pyface/tasks/action/listening_action.py +++ b/pyface/tasks/action/listening_action.py @@ -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. """ diff --git a/pyface/tasks/action/task_toggle_group.py b/pyface/tasks/action/task_toggle_group.py index 00d7b94f1..fe3a3f58a 100644 --- a/pyface/tasks/action/task_toggle_group.py +++ b/pyface/tasks/action/task_toggle_group.py @@ -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):