Skip to content

Commit

Permalink
Fixed improper menu disposal, leading to segfaults under certain circ…
Browse files Browse the repository at this point in the history
…umstances.

This is implemented in the wx backend, but was inexplicably missing here.
  • Loading branch information
epatters committed Apr 12, 2011
1 parent 0ad1d91 commit 8085548
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions enthought/pyface/ui/qt4/action/action_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(self, parent, menu, item, controller):
else:
self.control = menu.addAction(action.image.create_icon(),
action.name, self._qt4_on_triggered, action.accelerator)
menu.menu_items.append(self)

self.control.setToolTip(action.tooltip)
self.control.setWhatsThis(action.description)
Expand Down Expand Up @@ -103,6 +104,17 @@ def __init__(self, parent, menu, item, controller):
self.controller = controller
controller.add_to_menu(self)

def dispose(self):
action = self.item.action
action.on_trait_change(self._on_action_enabled_changed, 'enabled',
remove=True)
action.on_trait_change(self._on_action_visible_changed, 'visible',
remove=True)
action.on_trait_change(self._on_action_checked_changed, 'checked',
remove=True)
action.on_trait_change(self._on_action_name_changed, 'name',
remove=True)

###########################################################################
# Private interface.
###########################################################################
Expand Down
13 changes: 13 additions & 0 deletions enthought/pyface/ui/qt4/action/menu_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def __init__(self, manager, parent, controller):
# The controller.
self._controller = controller

# List of menu items
self.menu_items = []

# Create the menu structure.
self.refresh()

Expand All @@ -104,6 +107,16 @@ def __init__(self, manager, parent, controller):
# '_Menu' interface.
###########################################################################

def clear(self):
""" Clears the items from the menu. """

for item in self.menu_items:
item.dispose()

self.menu_items = []

super(_Menu, self).clear()

def is_empty(self):
""" Is the menu empty? """

Expand Down

0 comments on commit 8085548

Please sign in to comment.