我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用wx.MenuItem()。
def OnRightDown(self,event): if IsNotWX4(): item = self.mainlist.HitTest(event.GetPosition())[0] else: item = self.mainlist.HitTest(event.GetPoint())[0] if item > -1: menu = wx.Menu() if IsNotWX4(): self.CurrentListItem = event.m_itemIndex else: self.CurrentListItem = event.GetIndex() itemup = wx.MenuItem(menu, wx.ID_UP, "Move up") itemdel = wx.MenuItem(menu, wx.ID_DELETE, "Delete") itemdown = wx.MenuItem(menu, wx.ID_DOWN, "Move Down") if IsNotWX4(): menu.AppendItem(itemup) menu.AppendItem(itemdel) menu.AppendItem(itemdown) else: menu.Append(itemup) menu.Append(itemdel) menu.Append(itemdown) self.Bind(wx.EVT_MENU, self.OnClickUp, itemup) self.Bind(wx.EVT_MENU, self.OnItemDel, itemdel) self.Bind(wx.EVT_MENU, self.OnClickDown, itemdown) if IsNotWX4(): x,y = event.GetPosition() else: x,y = event.GetPoint().Get() mx,my = self.hbox1.GetSize() x= 3*mx/4 self.PopupMenu( menu, (x,y))
def __init__(self, parent, title): wx.Frame.__init__(self, parent, -1, title, size=(550, 350)) self.SetBackgroundColour(wx.NamedColour("WHITE")) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.change_plot(0) self.canvas = FigureCanvas(self, -1, self.figure) self.sizer = wx.BoxSizer(wx.VERTICAL) self.add_buttonbar() self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.add_toolbar() # comment this out for no toolbar menuBar = wx.MenuBar() # File Menu menu = wx.Menu() menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample") menuBar.Append(menu, "&File") if IS_GTK or IS_WIN: # Equation Menu menu = wx.Menu() for i, (mt, func) in enumerate(functions): bm = mathtext_to_wxbitmap(mt) item = wx.MenuItem(menu, 1000 + i, "") item.SetBitmap(bm) menu.AppendItem(item) self.Bind(wx.EVT_MENU, self.OnChangePlot, item) menuBar.Append(menu, "&Functions") self.SetMenuBar(menuBar) self.SetSizer(self.sizer) self.Fit()
def create_menu_item(menu, label, image, func): item = wx.MenuItem(menu, -1, label) item.SetBitmap(img.get(image)) menu.Bind(wx.EVT_MENU, func, id=item.GetId()) menu.Append(item) return item
def create_menu_item(menu, label, image, func): item = wx.MenuItem(menu, -1, label) item.SetBitmap(img.get(image)) menu.Bind(wx.EVT_MENU, func, id=item.GetId()) menu.AppendItem(item) return item
def buildItem(parent, root, item): if item=='-': root.AppendSeparator() return sc = ShotcutManager.get(item.title) LanguageManager.add(item.title) title = LanguageManager.get(item.title) if sc==None else LanguageManager.get(item.title)+'\t'+sc mi = wx.MenuItem(root, -1, title) parent.Bind(wx.EVT_MENU, lambda x, p=item:p().start(), mi) root.Append(mi)
def menu_drop(parent, toolbar, datas, btn, e): menu = wx.Menu() for data in datas[1][1:]: item = wx.MenuItem(menu, wx.ID_ANY, data[0].title, wx.EmptyString, wx.ITEM_NORMAL ) menu.Append(item) parent.Bind(wx.EVT_MENU, lambda x,p=data[1]:add_tools(toolbar, p), item) parent.PopupMenu( menu ) menu.Destroy()
def setup(self): menubar = wx.MenuBar() filem = wx.Menu() helpm = wx.Menu() setm = wx.Menu() new = filem.Append(wx.ID_NEW, '&New Tournament') open_ = filem.Append(wx.ID_OPEN, '&Open Tournament') filem.AppendSeparator() self.Bind(wx.EVT_MENU, self.new_event, new) qmi = wx.MenuItem(filem, wx.ID_EXIT, '&Quit\tCtrl+W') filem.AppendItem(qmi) about = helpm.Append(wx.ID_ANY, '&About BP5000') options = setm.Append(wx.ID_ANY, '&Options') self.Bind(wx.EVT_MENU, self.quit_event, qmi) self.Bind(wx.EVT_MENU, self.load_event, open_) self.Bind(wx.EVT_MENU, self.about_event, about) self.Bind(wx.EVT_MENU, self.options_event, options) self.options = Options() menubar.Append(filem, '&File') menubar.Append(setm, '&Settings') menubar.Append(helpm, '&Help') self.SetMenuBar(menubar) p = wx.Panel(self) self.nb = fnb.FlatNotebook(p, agwStyle=fnb.FNB_X_ON_TAB) def pagechanged(event): col = wx.Colour(hash(self.nb.GetPage(event.GetSelection()).sname)) self.nb.SetActiveTabColour(col) if isinstance(self.nb.GetPage(event.GetSelection()), BracketPage): self.nb.GetPage(event.GetSelection()).updatebracketimg() self.nb.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, pagechanged) sz = wx.BoxSizer() sz.Add(self.nb, 1, wx.EXPAND) p.SetSizer(sz) self.Bind(wx.EVT_CLOSE, self.quit_event) self.SetSize((950, 650)) self.SetTitle('BP5000') self.Centre() self.Show(True)
def _create_menu(self): menubar = wx.MenuBar() file = wx.Menu() edit = wx.Menu() help = wx.Menu() file.Append(wx.ID_OPEN, '&Open', 'Open a schematic') file.Append(wx.ID_SAVE, '&Save', 'Save the schematic') file.AppendSeparator() file.Append(103, '&Export BOM as CSV', 'Export the BOM as CSV') file.AppendSeparator() # Create a new submenu for recent files recent = wx.Menu() file.AppendSubMenu(recent, 'Recent') self.filehistory.UseMenu(recent) self.filehistory.AddFilesToMenu() file.AppendSeparator() quit = wx.MenuItem(file, 105, '&Quit\tCtrl+Q', 'Quit the Application') file.AppendItem(quit) edit.Append(201, 'Consolidate Components', 'Consolidate duplicated components') menubar.Append(file, '&File') menubar.Append(edit, '&Edit') menubar.Append(help, '&Help') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, self.on_quit, id=105) self.Bind(wx.EVT_MENU, self.on_open, id=wx.ID_OPEN) self.Bind(wx.EVT_MENU, self.on_consolidate, id=201) self.Bind(wx.EVT_MENU, self.on_export, id=103) self.Bind(wx.EVT_MENU, self.on_save, id=wx.ID_SAVE) self.Bind(wx.EVT_MENU_RANGE, self.on_file_history, id=wx.ID_FILE1, id2=wx.ID_FILE9)
def create_menu_item(self, menu, label, func): """ Add a menu item to the systray icon menu. """ item = wx.MenuItem(menu, -1, label) menu.Bind(wx.EVT_MENU, func, id=item.GetId()) menu.AppendItem(item) return item
def __init__(self, controller_uid): UIViewBase.__init__(self, controller_uid) _UIM = UIManager() controller = _UIM.get(self._controller_uid) if controller.model.id == wx.ID_ANY: controller.model.id = _UIM.new_wx_id() try: wx.MenuItem.__init__(self, None, controller.model.id, controller.model.label, controller.model.help, controller.model.kind ) except Exception, e: print e.message raise e
def PostInit(self): log.debug('{}.PostInit started'.format(self.name)) _UIM = UIManager() controller = _UIM.get(self._controller_uid) parent_controller_uid = _UIM._getparentuid(self._controller_uid) parent_controller = _UIM.get(parent_controller_uid) if controller.model.pos == -1: # Appending - Not needed to declare pos controller.model.pos = parent_controller.view.GetMenuItemCount() if controller.model.pos > parent_controller.view.GetMenuItemCount(): # If pos was setted out of range for inserting in parent Menu msg = 'Invalid menu position for MenuItem with text={}. Position will be setting to {}'.format(controller.model.label, parent_controller.view.GetMenuItemCount()) log.warning(msg) controller.model.pos = parent_controller.view.GetMenuItemCount() log.debug('{}.PostInit ended'.format(self.name))
def Set_Context_Menu(self): # Context menu 1 self.Context_Menu = wx.Menu() C_Menu_Undo = wx.MenuItem(self.Context_Menu, wx.NewId(), '&Undo Ctrl+Z') self.Context_Menu.AppendItem(C_Menu_Undo) self.Context_Menu.Bind(wx.EVT_MENU, self.OnUndo, C_Menu_Undo) C_Menu_Undo.Enable(False) C_Menu_Redo = wx.MenuItem(self.Context_Menu, wx.NewId(), '&Redo Ctrl+Y') self.Context_Menu.AppendItem(C_Menu_Redo) self.Context_Menu.Bind(wx.EVT_MENU, self.OnRedo, C_Menu_Redo) C_Menu_Redo .Enable(False) self.Context_Menu.AppendSeparator() C_Menu_Cut = wx.MenuItem(self.Context_Menu, wx.NewId(), 'Cu&t Ctrl+X') self.Context_Menu.AppendItem(C_Menu_Cut) self.Context_Menu.Bind(wx.EVT_MENU, self.OnCut, C_Menu_Cut) C_Menu_Copy= wx.MenuItem(self.Context_Menu, wx.NewId(), '&Copy Ctrl+C') self.Context_Menu.AppendItem(C_Menu_Copy) self.Context_Menu.Bind(wx.EVT_MENU, self.OnCopy, C_Menu_Copy) C_Menu_Paste= wx.MenuItem(self.Context_Menu, wx.NewId(), '&Paste Ctrl+V ') self.Context_Menu.AppendItem(C_Menu_Paste) self.Context_Menu.Bind(wx.EVT_MENU, self.OnPaste, C_Menu_Paste) #C_Menu_Paste.Enable(False) C_Menu_Delete= wx.MenuItem(self.Context_Menu, wx.NewId(), '&Delete') self.Context_Menu.AppendItem(C_Menu_Delete) self.Context_Menu.Bind(wx.EVT_MENU, self.OnDelete, C_Menu_Delete) # End of Context Menu 1 #Menu 2(Add/Remove) self.Context_Menu2 = wx.Menu() self.C_Menu_Add = wx.MenuItem(self.Context_Menu2, 140, '&Add Row \n ') self.Context_Menu2.AppendItem(self.C_Menu_Add) self.Context_Menu2.Bind(wx.EVT_MENU, self.OnAddClick, self.C_Menu_Add) self.C_Menu_Add.Enable(False) self.C_Menu_Remove = wx.MenuItem(self.Context_Menu2, 141, '&Remove Row \n') self.Context_Menu2.AppendItem(self.C_Menu_Remove) self.Context_Menu2.Bind(wx.EVT_MENU, self.OnRemoveClick, self.C_Menu_Remove) self.C_Menu_Remove.Enable(False)