Skip to content
Browse files

Merge pull request #66 from enthought/fix-tasks-actions

Fix destruction of tasks actions
  • Loading branch information...
2 parents 1f25334 + da07be8 commit a163e554be6fde6e21c6e62d5cc4777629c8f5b0 @itziakos itziakos committed
View
22 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 'UNDEFINED'
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):
View
15 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.
"""
View
19 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 'UNDEFINED'
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):
View
4 pyface/tasks/topological_sort.py
@@ -12,8 +12,8 @@ def before_after_sort(items):
The sort is topological. If an item does not specify a 'before' or 'after',
it is placed after the preceding item.
- If a cycle is found in the dependecies, a warning is logged and the order of
- the items is undefined.
+ If a cycle is found in the dependencies, a warning is logged and the order
+ of the items is undefined.
"""
# Handle a degenerate case for which the logic below will fail (because
# prev_item will not be set).

0 comments on commit a163e55

Please sign in to comment.
Something went wrong with that request. Please try again.