Найти - Пользователи
Полная версия: Добавить один wx.MenuItem в несколько wx.Menu
Начало » GUI » Добавить один wx.MenuItem в несколько wx.Menu
1
alexdup
Добрый день, собственно, сабж.

Я пробовал, но не получается.
1. Я добавил wx.MenuItem в wx.Menu
2. Я добавил тот же wx.MenuItem в другое wx.Menu
MenuItem из п. 2 работает, а из п. 1 - нет. Если пропустить п. 2, то п. 1 работает.
hellslade
код?
alexdup
Прошу, господа, код:

        # ================ MENU EDIT =======================================

self.menuEdit=wx.Menu()
self.menuBar.Append(self.menuEdit, "&Edit")

def AppendItem(parent, name, itemid, title, descr, handler=None):
self.__dict__[name]=wx.MenuItem(None, itemid, title, descr)
if handler: self.Bind(wx.EVT_MENU, handler, id=itemid)
if parent: parent.AppendItem(self.__dict__[name])
return self.__dict__[name]


AppendItem(self.menuEdit, "menuUndo", wx.ID_UNDO, "Undo", "")
AppendItem(self.menuEdit, "menuRedo", wx.ID_REDO, "Redo", "")
self.menuEdit.AppendSeparator()
AppendItem(self.menuEdit, "menuNewIndividual", ID_NEWINDIVIDUAL, "New individual", "", self.OnMenuNewIndividual)
AppendItem(self.menuEdit, "menuNewFamily", ID_NEWFAMILY, "New family", "", self.OnMenuNewFamily)
AppendItem(self.menuEdit, "menuNewPedigree", ID_NEWPEDIGREE, "New pedigree link", "", self.OnMenuNewPedigree)
AppendItem(self.menuEdit, "menuNewMate", ID_NEWMATE, "New mate", "", self.OnMenuNewMate)
AppendItem(self.menuEdit, "menuNewChild", ID_NEWCHILD, "New child", "", self.OnMenuNewChild)
AppendItem(self.menuEdit, "menuNewPicture", ID_NEWPICTURE, "New picture", "", self.OnMenuNewPicture)
AppendItem(self.menuEdit, "menuNewText", ID_NEWTEXT, "New text", "", self.OnMenuNewText)

self.menuEdit.AppendSeparator()
self.menuSize=wx.Menu()
self.menuEdit.AppendMenu(-1, "Element size", self.menuSize)
AppendItem(self.menuSize, "menuSizeSmall", ID_SIZESMALL, "Small", "", self.OnMenuSizeSmall)
AppendItem(self.menuSize, "menuSizeMedium", ID_SIZEMEDIUM, "Medium", "", self.OnMenuSizeMedium)
AppendItem(self.menuSize, "menuSizeLarge", ID_SIZELARGE, "Large", "", self.OnMenuSizeLarge)
AppendItem(self.menuEdit, "menuProperties", wx.ID_PROPERTIES, "Properties...", "", self.OnMenuProperties)
self.menuEdit.AppendSeparator()
AppendItem(self.menuEdit, "menuDelete", wx.ID_DELETE, "Delete", "", self.OnMenuDelete)


# ================ POPUP WINDOWS =====================================

# popup on the white area
self.popupNone=wx.Menu()
self.popupNone.AppendItem(self.menuUndo)
self.popupNone.AppendItem(self.menuRedo)
self.popupNone.AppendSeparator()
self.popupNone.AppendItem(self.menuNewIndividual)

# popup on multiple selection
self.popupMultiple=wx.Menu()
self.popupMultiple.AppendMenu(ID_SIZE, "Element size", self.menuSize)
self.popupMultiple.AppendSeparator()
self.popupMultiple.AppendItem(self.menuDelete)
Все это находится в __init__ фрейма.
hellslade
Создание пункта меню без указания родителя…Какая версия wx у вас? Если этот метод поправить, то на моей 2.8.7.1 все работает.
def AppendItem(parent, name, itemid, title, descr, handler=None):
self.__dict__[name]=wx.MenuItem(None, itemid, title, descr)
if handler: self.Bind(wx.EVT_MENU, handler, id=itemid)
if parent: parent.AppendItem(self.__dict__[name])
return self.__dict__[name]
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB