AGW FlatMenu not destroyed properly

Hi all,

I’m using wxpython 2.8.12.1 and AGW 0.9.1 on Windows 7 64bits.

I’d like to dynamically generate a context menu based on the class named FlatMenu each time a button is clicked like the following way :

“”"

import wx

from wx.lib.agw.flatmenu import FlatMenu

class MyWidget(wx.Frame) :

def init(self, *args, **kwargs) :

super(MyWidget, self).init(*args, **kwargs)

self.Bind(wx.EVT_BUTTON, self.OnButtonClicked)

def OnButtonClicked(self, event) :

context_menu = FlatMenu()

append menu options

popup the context menu

position = wx.GetMousePosition()

context_menu.Popup(position)

“”"

It seems the context menu is not destroyed when the application is outside of the function scope. So each time OnButtonClicked is triggerred, a new FlatMenu is created and stored in main frame list of children. This results on a kind of memory leak as my application crash when too many menus are created.

Somebody knows how to properly generate a context menu based on FlatMenu ?

Regards,

Thierry BRIZZI.

Thierry Brizzi wrote:

Hi all,

I'm using wxpython 2.8.12.1 and AGW 0.9.1 on Windows 7 64bits.

I'd like to dynamically generate a context menu based on the class named
FlatMenu each time a button is clicked like the following way :

"""
import wx
from wx.lib.agw.flatmenu import FlatMenu

class MyWidget(wx.Frame) :

def __init__(self, *args, **kwargs) :
super(MyWidget, self).__init__(*args, **kwargs)

....

self.Bind(wx.EVT_BUTTON, self.OnButtonClicked)
...

def OnButtonClicked(self, event) :
context_menu = FlatMenu()
# append menu options
...

# popup the context menu
position = wx.GetMousePosition()
context_menu.Popup(position)
"""

It seems the context menu is not destroyed when the application is
outside of the function scope. So each time OnButtonClicked is
triggerred, a new FlatMenu is created and stored in main frame list of
children. This results on a kind of memory leak as my application crash
when too many menus are created.

Somebody knows how to properly generate a context menu based on FlatMenu ?

Have you tried calling the menu's Destroy method when you are done with it?

···

--
Robin Dunn
Software Craftsman

Hi Robin,

In fact this method has been overloaded to destroy / remove a specific menu item but not the menu itself. So It is necessary to call the Destroy method of the base class to have the expected behavior.

I’ve thought about destroying the menu after the user make a choice or dismiss. As method PopupMenu is only compatible with wx.Menu, I need to stop in the OnButtonClicked method after the Popup function until the user makes a choice.

···

Le vendredi 22 février 2013 02:49:34 UTC+1, Robin Dunn a écrit :

Thierry Brizzi wrote:

Hi all,

I’m using wxpython 2.8.12.1 and AGW 0.9.1 on Windows 7 64bits.

I’d like to dynamically generate a context menu based on the class named

FlatMenu each time a button is clicked like the following way :

“”"

import wx

from wx.lib.agw.flatmenu import FlatMenu

class MyWidget(wx.Frame) :

def init(self, *args, **kwargs) :

super(MyWidget, self).init(*args, **kwargs)

self.Bind(wx.EVT_BUTTON, self.OnButtonClicked)

def OnButtonClicked(self, event) :

context_menu = FlatMenu()

append menu options

popup the context menu

position = wx.GetMousePosition()

context_menu.Popup(position)

“”"

It seems the context menu is not destroyed when the application is

outside of the function scope. So each time OnButtonClicked is

triggerred, a new FlatMenu is created and stored in main frame list of

children. This results on a kind of memory leak as my application crash

when too many menus are created.

Somebody knows how to properly generate a context menu based on FlatMenu ?

Have you tried calling the menu’s Destroy method when you are done with it?


Robin Dunn

Software Craftsman

http://wxPython.org