Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix destruction of tasks actions #66

Merged
merged 3 commits into from

3 participants

@pberkes
Owner

A few tasks-related actions did not properly dispose of listeners to other object when they were destroyed.

pberkes added some commits
@pberkes pberkes FIX: properly destroy tasks actions
A few tasks-related actions did not properly dispose
of listeners to other object when they were destroyed.
d2328f0
@pberkes pberkes Doc correction. 1946227
@rkern
Owner

LGTM

pyface/tasks/action/task_toggle_group.py
@@ -35,6 +42,8 @@ def perform(self, event=None):
###########################################################################
def _get_name(self):
+ if self.task is None:
+ return 'DELETED TASK TOGGLE'
@itziakos Owner

I think that here it should return Undefined

@pberkes Owner
pberkes added a note

Good point, but name is a Unicode trait, and Undefined is not unicode...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@pberkes pberkes Default name of toggle group actions is 'UNDEFINED'.
Set name toggle group actions to 'UNDEFINED' when the
corresponding object (task or dock pane) is None. This
is slightly better than 'DELETED' as there might be other
reasons why the object is None.
da07be8
@itziakos itziakos merged commit a163e55 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 14, 2012
  1. @pberkes

    FIX: properly destroy tasks actions

    pberkes authored
    A few tasks-related actions did not properly dispose
    of listeners to other object when they were destroyed.
  2. @pberkes

    Doc correction.

    pberkes authored
  3. @pberkes

    Default name of toggle group actions is 'UNDEFINED'.

    pberkes authored
    Set name toggle group actions to 'UNDEFINED' when the
    corresponding object (task or dock pane) is None. This
    is slightly better than 'DELETED' as there might be other
    reasons why the object is None.
This page is out of date. Refresh to see the latest.
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).
Something went wrong with that request. Please try again.