Hello,
I'm fairly new to wxPython.
I already read a lot in the wiki but wasn't able
to find an answer to my question.
In case I overlooked it please apologize.
My question is whether it is considered to be save what I'm doing.
class ContextMenu(wx.Menu):
def __init__(self, list_of_contextmenu_entries):
super(ContextMenu, self).__init__()
def create_menu_item(self, k, v):
if k == '-':
self.AppendSeparator()
else:
if type(v) is list:
menu = wx.Menu()
self.AppendSubMenu(menu, k)
for k2, v2 in v:
create_menu_item(menu, k2,v2)
else:
item = wx.MenuItem(self, wx.NewId(), k)
self.AppendItem(item)
self.Bind(wx.EVT_MENU, v, item)
for k,v in list_of_contextmenu_entries:
create_menu_item(self, k, v)
Within constructor I create a context menu with a recursive function create_menu_item.
As you see, I overwrite the self with menu (wx.Menu) once it has to create a submenu.
I guess this is a bit of a hack but it seems to work without problems.
Attached a sample program.
My configuration
ChaletOS (linux) and wxPython 3.0.2.0
Thank you very much
Claudia