def __init__(self, parent, title): wxFrame.__init__(self, parent, wxID_ANY, title, size=(200, 100), style=wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE) filemenu = wxMenu() filemenu.AppendSeparator() filemenu.Append(ID_EXIT, "E&xit\tCtrl+Q", " Terminate the program") helpmenu = wxMenu() helpmenu.Append(ID_ABOUT, "&About", " Information about this program") menuBar = wxMenuBar() menuBar.Append(filemenu, "&File") menuBar.Append(helpmenu, "&Help") self.SetMenuBar(menuBar) self.SetSize((800, 600)) self.Show(True) EVT_MENU(self, ID_EXIT, self.OnExit) EVT_MENU(self, ID_ABOUT, self.OnAbout) EVT_CLOSE(self, self.OnExit)
def format_popup(self,pos): menu = wx.wxMenu() menu.Append(500, 'Change Text', 'Change Text') wx.EVT_MENU(self, 500, self.OnText) menu.Append(600, 'Change Font', 'Change Text Font') wx.EVT_MENU(self, 600, self.OnFont) #print 'fp:',self.text menu.UpdateUI() self.PopupMenuXY(menu,pos[0],pos[1])
def __init__(self,parent,title): wxFrame.__init__(self,parent,wxID_ANY, title, size = ( 200,100), style=wxDEFAULT_FRAME_STYLE|wxNO_FULL_REPAINT_ON_RESIZE) filemenu= wxMenu() filemenu.AppendSeparator() filemenu.Append(ID_EXIT,"E&xit\tCtrl+Q"," Terminate the program") helpmenu = wxMenu() helpmenu.Append(ID_ABOUT, "&About"," Information about this program") menuBar = wxMenuBar() menuBar.Append(filemenu,"&File") menuBar.Append(helpmenu,"&Help") self.SetMenuBar(menuBar) self.SetSize((800, 600)) self.Show(True) EVT_MENU(self, ID_EXIT, self.OnExit) EVT_MENU(self, ID_ABOUT, self.OnAbout) EVT_CLOSE(self, self.OnExit)
def __init__(self, parent=wx.NULL, id = -1, title = '', pos=wx.wxPyDefaultPosition, size=default_size,visible=1): wx.wxFrame.__init__(self, parent, id, title,pos,size) # Now Create the menu bar and items self.mainmenu = wx.wxMenuBar() menu = wx.wxMenu() menu.Append(200, '&Save As...', 'Save plot to image file') wx.EVT_MENU(self, 200, self.file_save_as) menu.Append(203, '&Print...', 'Print the current plot') wx.EVT_MENU(self, 203, self.file_print) menu.Append(204, 'Print Pre&view', 'Preview the current plot') wx.EVT_MENU(self, 204, self.file_preview) menu.Append(205, 'Close', 'Close plot') wx.EVT_MENU(self, 205, self.file_close) self.mainmenu.Append(menu, '&File') menu = wx.wxMenu() menu.Append(self.TITLE_TEXT, '&Graph Title', 'Title for plot') wx.EVT_MENU(self,self.TITLE_TEXT,self.title) menu.Append(self.X_TEXT, '&X Title', 'Title for X axis') wx.EVT_MENU(self,self.X_TEXT,self.title) menu.Append(self.Y_TEXT, '&Y Title', 'Title for Y axis') wx.EVT_MENU(self,self.Y_TEXT,self.title) self.mainmenu.Append(menu, '&Titles') #menu = wx.wxMenu() #menu.Append(300, '&Profile', 'Check the hot spots in the program') #wx.EVT_MENU(self,300,self.OnProfile) #self.mainmenu.Append(menu, '&Utility') self.SetMenuBar(self.mainmenu) # A status bar to tell people what's happening self.CreateStatusBar(1) self.print_data = wx.wxPrintData() self.print_data.SetPaperId(wx.wxPAPER_LETTER) self.client = plot_canvas(self) if visible: self.Show(1) self.Raise() self.SetFocus()
def __init__ ( self, desc, owner, popup = FALSE, window = None ): self.owner = owner if window is None: window = owner self.window = window self.indirect = getattr( owner, 'call_menu', None ) self.names = {} self.desc = desc.split( '\n' ) self.index = 0 self.keys = [] if popup: self.menu = menu = wx.wxMenu() self.parse( menu, -1 ) else: self.menu = menu = wx.wxMenuBar() self.parse( menu, -1 ) window.SetMenuBar( menu ) if len( self.keys ) > 0: window.SetAcceleratorTable( wx.wxAcceleratorTable( self.keys ) )
def parse ( self, menu, indent ): while TRUE: # Make sure we have not reached the end of the menu description yet: if self.index >= len( self.desc ): return # Get the next menu description line and check its indentation: dline = self.desc[ self.index ] line = dline.lstrip() indented = len( dline ) - len( line ) if indented <= indent: return # Indicate that the current line has been processed: self.index += 1 # Check for a blank or comment line: if (line == '') or (line[0:1] == '#'): continue # Check for a menu separator: if line[0:1] == '-': menu.AppendSeparator() continue # Allocate a new menu ID: MakeMenu.cur_id += 1 cur_id = MakeMenu.cur_id # Extract the help string (if any): help = '' match = help_pat.search( line ) if match: help = ' ' + match.group(2).strip() line = match.group(1) + match.group(3) # Check for a menu item: col = line.find( ':' ) if col >= 0: handler = line[ col + 1: ].strip() if handler != '': if self.indirect: self.indirect( cur_id, handler ) handler = self.indirect else: try: exec('def handler(event,self=self.owner):\n %s\n' % handler) except: handler = null_handler else: try: exec_('def handler(event,self=self.owner):\n%s\n' % (self.get_body(indented), ), _globs_=globals()) except: handler = null_handler wx.EVT_MENU( self.window, cur_id, handler ) not_checked = checked = disabled = FALSE line = line[ : col ] match = options_pat.search( line ) if match: line = match.group(1) + match.group(3) not_checked, checked, disabled, name = option_check( '~/-', match.group(2).strip() ) if name != '': self.names[ name ] = cur_id setattr( self.owner, name, MakeMenuItem( self, cur_id ) ) label = line.strip() col = label.find( '|' ) if col >= 0: key = label[ col + 1: ].strip() label = '%s%s%s' % ( label[ : col ].strip(), '\t', key ) key = key.upper() flag = wx.wxACCEL_NORMAL col = key.find( '-' ) if col >= 0: flag = { 'CTRL': wx.wxACCEL_CTRL, 'SHIFT': wx.wxACCEL_SHIFT, 'ALT': wx.wxACCEL_ALT }.get( key[ : col ].strip(), wx.wxACCEL_CTRL ) key = key[ col + 1: ].strip() code = key_map.get( key, None ) if code is None: code = ord( key ) self.keys.append( wx.wxAcceleratorEntry( flag, code, cur_id ) ) menu.Append( cur_id, label, help, not_checked or checked ) if checked: menu.Check( cur_id, TRUE ) if disabled: menu.Enable( cur_id, FALSE ) continue # Else must be the start of a sub menu: submenu = wx.wxMenu() label = line.strip() # Recursively parse the sub-menu: self.parse( submenu, indented ) # Add the menu to its parent: try: menu.AppendMenu( cur_id, label, submenu, help ) except: # Handle the case where 'menu' is really a 'MenuBar' (which does # not understand 'MenuAppend'): menu.Append( submenu, label )
def format_popup(self,pos): menu = wx.wxMenu() menu.Append(500, 'Auto Zoom', 'Auto Zoom') wx.EVT_MENU(self, 500, self.on_auto_zoom) menu.UpdateUI() self.PopupMenuXY(menu,pos[0],pos[1])
def __init__(self, parent, hiddenDirs, hiddenFiles, statusBar, itemFunc, showHiddenFunc, sortType=1, sortReverse=0): #style = wxLC_REPORT #style = wxLC_ICON | wxLC_ALIGN_LEFT #style = wxLC_SMALL_ICON | wxLC_ALIGN_LEFT style = wxLC_LIST style = style | wxLC_EDIT_LABELS | wxNO_BORDER | wxSUNKEN_BORDER | wxTAB_TRAVERSAL wxListCtrl.__init__(self, parent, style=style) # this creates cyclic dependency (points to ancestor through bound method) # but the enclosing wxNotebook breaks the cycle when necessary self.itemFunc = itemFunc self.showHiddenFunc = showHiddenFunc self.statusBar = statusBar self.hiddenDirs = hiddenDirs self.hiddenFiles = hiddenFiles self.sortType = sortType self.sortReverse = sortReverse self.currentPath = None self.history = PathHistory() self.beginEditName = "" # popup menu id's self.popNew = wxNewId() self.popView = wxNewId() self.popOpen = wxNewId() self.popEdit = wxNewId() self.popOpenWith = wxNewId() self.popCopy = wxNewId() self.popCut = wxNewId() self.popPaste = wxNewId() self.popEject = wxNewId() self.popMount = wxNewId() self.popUnmount = wxNewId() self.popProps = wxNewId() self.popMoveCopy = wxNewId() client = wxART_TOOLBAR self.imageList = wxImageList(16, 16) self.imageIDs = {} for name in ("FOLDER", "FOLDER_LINK", "NORMAL_FILE", "LINK"): d = TheArtProvider.GetBitmap(getattr(TheArtProvider, name), client, (16, 16)) self.imageIDs[name] = self.imageList.Add(d) self.SetImageList(self.imageList, wxIMAGE_LIST_SMALL) self.fsMenu = FSMenu("", self) self.popMenu = wxMenu() popMenu = self.popMenu for menuItem in ( (self.popNew, "&New item"), (), (self.popView, "&View"), (self.popOpen, "&Open"), (self.popEdit, "&Edit"), (self.popOpenWith, "Open &with"), (), (self.popCopy, "&Copy"), (self.popCut, "C&ut"), (self.popPaste, "&Paste"), (), (self.popEject, "E&ject"), (self.popMount, "&Mount"), (self.popUnmount, "Unmoun&t"), (self.popProps, "P&roperties"), (), ): if len(menuItem) < 1: popMenu.AppendSeparator() continue mid = menuItem[0] txt = menuItem[1] popMenu.Append(mid, txt) popMenu.Enable(mid, false) EVT_MENU(self, mid, self.OnPopup) popMenu.Enable(self.popProps, true) popMenu.AppendMenu(self.popMoveCopy, "Move/Copy To", self.fsMenu) self.selectionTracker = SelectionTracker() # these two methods are called for each entry that changes selection (including user GUI # actions such as Shift+LeftClick) and so they should not do much work EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemSelected) EVT_LIST_ITEM_DESELECTED(self, self.GetId(), self.OnItemDeSelected) EVT_LIST_ITEM_ACTIVATED(self, self.GetId(), self.OnActivated) EVT_LIST_ITEM_RIGHT_CLICK(self, self.GetId(), self.OnRightClick) EVT_LIST_BEGIN_LABEL_EDIT(self, self.GetId(), self.OnBeginEdit) EVT_LIST_END_LABEL_EDIT(self, self.GetId(), self.OnEndEdit) #EVT_LIST_KEY_DOWN(self, self.GetId(), self.OnKeyDown) #EVT_LIST_ITEM_FOCUSED(self, self.GetId(), self.OnKeyDown) # not implemented #txtCtrl = self.GetEditControl() # wx's popups occur on UP not DOWN event #EVT_RIGHT_DOWN(self, self.OnRightClick) # this process right click outside of any item #FIXME: learn to interact with normal list event processing EVT_RIGHT_UP(self, self.OnRightClick) self.UpdateStatusBar("", "", 1) EVT_IDLE(self, self.OnIdle)
def OnRightClick(self, event): position = event.GetPosition() #print self.HitTest(position) #-> 10 #event.Skip() #how to get focus? sel = self.GetSelection() curPage = self.GetPage(sel) sortMenu = wxMenu() for menuItem in ((self.menuSname, "&Name", curPage.SORT_NAME), (self.menuSdate, "&Date", curPage.SORT_DATE), (self.menuSsize, "&Size", curPage.SORT_SIZE), (self.menuStype, "&Type", curPage.SORT_TYPE), (self.menuSiname, "&Name (case-insensitive)", curPage.SORT_NAME_INSENSITIVE), (self.menuSnone, "&Unsorted", curPage.SORT_NONE)): id, txt, c = menuItem sortMenu.Append(id, txt, "", wxITEM_RADIO) if curPage.GetSortType() == c: sortMenu.Check(id, true) else: sortMenu.Check(id, false) EVT_MENU(self, id, lambda e, self=self, c=c: self.GetPage( self.GetSelection()).SetSortType(c)) # add "reverse" check sortMenu.AppendSeparator() mid = self.menuSreverse c = curPage.GetSortType() t = curPage.GetSortType(1) sortMenu.Append(mid, "&Reverse order", "Sort in reversed order", wxITEM_CHECK) if t: sortMenu.Check(mid, true) t = 0 else: sortMenu.Check(mid, false) t = 1 EVT_MENU(self, mid, lambda e, s=self, c=c, t=t: s.GetPage(s.GetSelection()). SetSortType(c, t)) dirsMenu = wxMenu() for menuItem in ((self.menuDfirst, "&First"), (self.menuDfirst, "&Last"), (self.menuDfirst, "&Mixed")): mid = menuItem[0] txt = menuItem[1] dirsMenu.Append(mid, txt, "", wxITEM_RADIO) popMenu = wxMenu() for menuItem in ((self.menuDup, "&Clone tab"), (self.menuDel, "&Delete tab"), (), (self.menuSort, "&Sort by ...", sortMenu), (self.menuDirs, "D&irectories are ...", dirsMenu), (self.menuHiddenDirs, "Hidden di&rectories", "Toggle view of hidden directories", wxITEM_CHECK), (self.menuHiddenFiles, "Hidden &files", "Toggle view of hidden files", wxITEM_CHECK)): if len(menuItem) < 2: popMenu.AppendSeparator() continue mid = menuItem[0] txt = menuItem[1] if len(menuItem) == 2: popMenu.Append(mid, txt) elif len(menuItem) == 3: subMenu = menuItem[2] popMenu.AppendMenu(mid, txt, subMenu) else: tip = menuItem[2] type_ = menuItem[3] popMenu.Append(mid, txt, tip, type_) if self.GetPageCount() < 2: popMenu.Enable(self.menuDel, false) if curPage.GetShowHidden(): popMenu.Check(self.menuHiddenDirs, true) if curPage.GetShowHiddenFiles(): popMenu.Check(self.menuHiddenFiles, true) EVT_MENU(self, self.menuDup, self.OnDuplicate) EVT_MENU(self, self.menuDel, lambda e, self=self: self.DeletePage(self.GetSelection())) EVT_MENU(self, self.menuHiddenDirs, lambda e, self=self: self.GetPage(self.GetSelection()). ToggleShowHidden()) EVT_MENU(self, self.menuHiddenFiles, lambda e, self=self: self.GetPage(self.GetSelection()). ToggleShowHiddenFiles()) self.PopupMenu(popMenu, position)
def setupMenus(self): self.newId = wxNewId() self.openId = wxNewId() self.viewId = wxNewId() self.editId = wxNewId() self.openWithId = wxNewId() self.propertiesId = wxNewId() self.deleteId = wxNewId() self.exitId = wxNewId() self.cutId = wxNewId() self.copyId = wxNewId() self.pasteId = wxNewId() self.pasteLinkId = wxNewId() self.moveToDirId = wxNewId() self.copyToDirId = wxNewId() self.selectAllId = wxNewId() self.deselectAllId = wxNewId() self.invertSelectionId = wxNewId() self.refreshId = wxNewId() self.addBookmarkId = wxNewId() self.manageBookmarkId = wxNewId() self.goUpId = wxNewId() self.goBackId = wxNewId() self.goForwardId = wxNewId() self.goHomeId = wxNewId() self.mountId = wxNewId() self.umountId = wxNewId() self.aboutId = wxNewId() filemenu = wxMenu() filemenu.Append(self.newId, "&New item\tCtrl-N", " New item") filemenu.Append(self.viewId, "&View\tF3", " View selected items") filemenu.Append(self.openId, "&Open\tCtrl-O", " Open selected items") filemenu.Append(self.editId, "&Edit\tF4", " Edit selected items") filemenu.Append(self.openWithId, "Open &with\tCtrl-W", " Open selected items with ...") filemenu.AppendSeparator() filemenu.Append(self.propertiesId, "P&roperties\tCtrl-P", " Show properties of selected items") filemenu.Append(self.deleteId, "&Delete\tDELETE", self.deleteStr) filemenu.AppendSeparator() filemenu.Append(self.exitId, "E&xit\tCtrl-Q", " Terminate the program") editmenu = wxMenu() editmenu.Append(self.copyId, "&Copy\tCtrl-C", self.copyStr) editmenu.Append(self.cutId, "C&ut\tCtrl-X", self.cutStr) editmenu.Append(self.pasteId, "&Paste\tCtrl-V", self.pasteStr) editmenu.Append(self.pasteLinkId, "Paste &link\tCtrl-L", " Paste symbolic link") editmenu.AppendSeparator() editmenu.Append(self.moveToDirId, "&Move to directory\tCtrl-M", " Move to different direcotry") editmenu.Append(self.copyToDirId, "Cop&y to directory\tCtrl-N", " Copy to different direcotry") editmenu.AppendSeparator() editmenu.Append(self.selectAllId, "&Select all\tCtrl-A", " Select all items") editmenu.Append(self.deselectAllId, "&Deselect all\tCtrl-Z", " Deselect all items") editmenu.Append(self.invertSelectionId, "&Invert selection\tCtrl-I", " Invert selection") viewmenu = wxMenu() viewmenu.Append(self.refreshId, "&Refresh\tCtrl-R", self.refreshStr) viewmenu.AppendSeparator() go__menu = wxMenu() go__menu.Append(self.goUpId, "&Up", self.goUpStr) go__menu.Append(self.goBackId, "&Back\tALT-LEFT", self.goBackStr) go__menu.Append(self.goForwardId, "&Forward\tALT-RIGHT", self.goForwardStr) go__menu.Append(self.goHomeId, "&Home\tALT-HOME", self.goHomeStr) bookmenu = wxMenu() bookmenu.Append(self.addBookmarkId, "&Add\tCtrl-D", " Add bookmark") bookmenu.Append(self.manageBookmarkId, "&Manage", " Manage bookmarks") toolmenu = wxMenu() toolmenu.Append(self.mountId, "&Options", " Mount device") helpmenu = wxMenu() helpmenu.Append(self.aboutId, "&About", " Information about this program") # Creating the menubar. menuBar = wxMenuBar(wxMB_DOCKABLE) menuBar.Append(filemenu, "&File") menuBar.Append(editmenu, "&Edit") menuBar.Append(viewmenu, "&View") menuBar.Append(go__menu, "&Go") menuBar.Append(bookmenu, "&Bookmarks") menuBar.Append(toolmenu, "&Tools") menuBar.Append(helpmenu, "&Help") self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content. # attach events to menus EVT_MENU(self, self.deleteId, lambda e, self=self: self.ntbook.DeleteItems(e)) EVT_MENU(self, self.propertiesId, lambda e, self=self: self.ntbook.Properties()) EVT_MENU(self, self.newId, lambda e, self=self: self.ntbook.NewItem()) EVT_MENU(self, self.goUpId, lambda e, self=self: self.ntbook.HistoryGo(e, 0)) EVT_MENU(self, self.goBackId, lambda e, self=self: self.ntbook.HistoryGo(e, -1)) EVT_MENU(self, self.goForwardId, lambda e, self=self: self.ntbook.HistoryGo(e, +1)) EVT_MENU(self, self.goHomeId, lambda e, self=self: self.ntbook.GoHome()) EVT_MENU(self, self.refreshId, lambda e, self=self: self.ntbook.Refresh()) EVT_MENU(self, self.copyId, lambda e, self=self: self.ntbook.CopyCutPaste(0)) EVT_MENU(self, self.cutId, lambda e, self=self: self.ntbook.CopyCutPaste(1)) EVT_MENU(self, self.pasteId, lambda e, self=self: self.ntbook.CopyCutPaste(2)) EVT_MENU(self, self.selectAllId, lambda e, self=self: self.ntbook.SelectItems(1)) EVT_MENU(self, self.deselectAllId, lambda e, self=self: self.ntbook.SelectItems(0)) EVT_MENU(self, self.invertSelectionId, lambda e, self=self: self.ntbook.SelectItems(-1)) EVT_MENU(self, self.aboutId, self.OnAbout) EVT_MENU(self, self.exitId, self.OnExit)
def OnRightClick(self, event): position = event.GetPosition() #print self.HitTest(position) #-> 10 #event.Skip() #how to get focus? sel = self.GetSelection() curPage = self.GetPage(sel) sortMenu = wxMenu() for menuItem in ( (self.menuSname, "&Name", curPage.SORT_NAME), (self.menuSdate, "&Date", curPage.SORT_DATE), (self.menuSsize, "&Size", curPage.SORT_SIZE), (self.menuStype, "&Type", curPage.SORT_TYPE), (self.menuSiname, "&Name (case-insensitive)", curPage.SORT_NAME_INSENSITIVE), (self.menuSnone, "&Unsorted", curPage.SORT_NONE)): id, txt, c = menuItem sortMenu.Append(id, txt, "", wxITEM_RADIO) if curPage.GetSortType() == c: sortMenu.Check(id, true) else: sortMenu.Check(id, false) EVT_MENU(self, id, lambda e,self=self,c=c:self.GetPage(self.GetSelection()).SetSortType(c)) # add "reverse" check sortMenu.AppendSeparator() mid = self.menuSreverse c = curPage.GetSortType() t = curPage.GetSortType(1) sortMenu.Append(mid, "&Reverse order", "Sort in reversed order", wxITEM_CHECK) if t: sortMenu.Check(mid, true) t = 0 else: sortMenu.Check(mid, false) t = 1 EVT_MENU(self, mid, lambda e,s=self,c=c, t=t:s.GetPage(s.GetSelection()).SetSortType(c, t)) dirsMenu = wxMenu() for menuItem in ( (self.menuDfirst, "&First"), (self.menuDfirst, "&Last"), (self.menuDfirst, "&Mixed")): mid = menuItem[0] txt = menuItem[1] dirsMenu.Append(mid, txt, "", wxITEM_RADIO) popMenu = wxMenu() for menuItem in ((self.menuDup, "&Clone tab"), (self.menuDel, "&Delete tab"), (), (self.menuSort, "&Sort by ...", sortMenu), (self.menuDirs, "D&irectories are ...", dirsMenu), (self.menuHiddenDirs, "Hidden di&rectories", "Toggle view of hidden directories", wxITEM_CHECK), (self.menuHiddenFiles, "Hidden &files", "Toggle view of hidden files", wxITEM_CHECK)): if len(menuItem) < 2: popMenu.AppendSeparator() continue mid = menuItem[0] txt = menuItem[1] if len(menuItem) == 2: popMenu.Append(mid, txt) elif len(menuItem) == 3: subMenu = menuItem[2] popMenu.AppendMenu(mid, txt, subMenu) else: tip = menuItem[2] type_ = menuItem[3] popMenu.Append(mid, txt, tip, type_) if self.GetPageCount() < 2: popMenu.Enable(self.menuDel, false) if curPage.GetShowHidden(): popMenu.Check(self.menuHiddenDirs, true) if curPage.GetShowHiddenFiles(): popMenu.Check(self.menuHiddenFiles, true) EVT_MENU(self, self.menuDup, self.OnDuplicate) EVT_MENU(self, self.menuDel, lambda e, self=self: self.DeletePage(self.GetSelection())) EVT_MENU(self, self.menuHiddenDirs, lambda e, self=self: self.GetPage(self.GetSelection()).ToggleShowHidden()) EVT_MENU(self, self.menuHiddenFiles, lambda e, self=self: self.GetPage(self.GetSelection()).ToggleShowHiddenFiles()) self.PopupMenu(popMenu, position)