def _apply_toggle(self, root2, pinfos): for i, pinfo, cb in pinfos: id = root2.FindItem(pinfo["name"]) if id != wx.NOT_FOUND and not pinfo["toggle_menu"]: menu_RemoveItem(root2, pinfo["menu"]) elif id == wx.NOT_FOUND and pinfo["toggle_menu"]: menu_AppendItem(root2, pinfo["menu"])
def __init__(self, parent): super(layout_editor_popup, self).__init__(style=wx.WS_EX_PROCESS_UI_UPDATES) self.parent = parent self.mmi = [] m = [ "Split", "Merge", "Swap", "Distribute Horizontally", "Distribute Vertically", "Sort by Column", "Sort by Row", "Common Bottom Axis", "Common Left Axis", "Reset Common Axis", ] h = [ self.onSplit, self.onMerge, self.onSwap, self.onDistH, self.onDistV, self.onSortCol, self.onSortRow, self.onCommBtm, self.onCommLft, self.onResetCommon, ] for k in range(0, len(m)): key = m[k] if key == "---": self.AppendSeparator() continue mmi = wx.MenuItem(self, wx.ID_ANY, key) menu_AppendItem(self, mmi) self.Bind(wx.EVT_MENU, h[k], mmi) self.mmi.append(mmi)
def BuildPopUpMenu(base, menus, eventobj=None, xy=None, xydata=None): ''' base = wx.Menu menus = [(menu_string, func, icon_image)] special menu_string --- : separator '+' and '!' control submenu generation +...: goto deeper menu !...: end of current depth icon_image is not yet implemented... if eventobj is set to widget, events returned from the popup has the widget as eventobj ''' isTop = True ret = {} for m in menus: s = m[0] h = m[1] i = m[2] bmp = None if len(m) < 4 else m[3] id = wx.ID_ANY if len(m) < 5 else m[4] if s == '---': if not isTop: base.AppendSeparator() continue elif s[0] is '+': new_base = wx.Menu() menu_Append(base, id, s[1:], new_base) base = new_base isTop = True mmm = base elif s[0] is '!': base = base.GetParent() isTop = False else: isTop = False if s[0] is '-': mmi = wx.MenuItem(base, id, s[1:]) elif s[0] is '*': mmi = wx.MenuItem(base, id, s[1:], kind=wx.ITEM_CHECK) elif s[0] is '^': mmi = wx.MenuItem(base, id, s[1:], kind=wx.ITEM_CHECK) else: mmi = wx.MenuItem(base, id, s) if bmp is not None: mmi.SetBitmap(bmp) menu_AppendItem(base, mmi) if s[0] is '^': mmi.Check(True) if s[0] is '-': mmi.Enable(False) def func(evt, handler=h, obj=eventobj, extra=i, xy=xy, xydata=xydata): if obj is not None: evt.SetEventObject(obj) if extra is not None: evt.ExtraInfo = extra if xy is not None: evt.mpl_xy = xy else: evt.mpl_xy = (None, None) if xydata is not None: evt.mpl_xydata = xydata else: evt.mpl_xydata = (None, None) handler(evt) base.Bind(wx.EVT_MENU, func, mmi) mmm = mmi.GetMenu() if id != wx.ID_ANY: ret[id] = mmm return ret
def BuildPopUpMenu(base, menus, eventobj=None, xy = None, xydata = None): ''' base = wx.Menu menus = [(menu_string, func, icon_image)] special menu_string --- : separator '+' and '!' control submenu generation +...: goto deeper menu !...: end of current depth icon_image is not yet implemented... if eventobj is set to widget, events returned from the popup has the widget as eventobj ''' isTop = True ret = {} for m in menus: s = m[0] h = m[1] i = m[2] bmp = None if len(m) < 4 else m[3] id = wx.ID_ANY if len(m) < 5 else m[4] if s == '---': if not isTop: base.AppendSeparator() continue elif s[0] is '+': new_base=wx.Menu() menu_Append(base, id, s[1:], new_base) base=new_base isTop = True mmm = base elif s[0] is '!': base=base.GetParent() isTop = False else: isTop = False if s[0] is '-': mmi = wx.MenuItem(base, id, s[1:]) elif s[0] is '*': mmi = wx.MenuItem(base, id, s[1:],kind = wx.ITEM_CHECK) elif s[0] is '^': mmi = wx.MenuItem(base, id, s[1:],kind = wx.ITEM_CHECK) else: mmi = wx.MenuItem(base, id, s) if bmp is not None: mmi.SetBitmap(bmp) menu_AppendItem(base, mmi) if s[0] is '^': mmi.Check(True) if s[0] is '-': mmi.Enable(False) def func(evt, handler=h, obj = eventobj, extra=i, xy = xy, xydata=xydata): if obj is not None: evt.SetEventObject(obj) if extra is not None: evt.ExtraInfo=extra if xy is not None: evt.mpl_xy = xy else: evt.mpl_xy = (None, None) if xydata is not None: evt.mpl_xydata = xydata else: evt.mpl_xydata = (None, None) handler(evt) base.Bind(wx.EVT_MENU, func, mmi) mmm = mmi.GetMenu() if id != wx.ID_ANY: ret[id] = mmm return ret