00001 # Copyright (C) 2008-2009 Mark Hanegraaff 00002 # 00003 # This program is free software: you can redistribute it and/or modify 00004 # it under the terms of the GNU General Public License as published by 00005 # the Free Software Foundation, either version 3 of the License, or 00006 # (at your option) any later version. 00007 # 00008 # This program is distributed in the hope that it will be useful, 00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 # GNU General Public License for more details. 00012 # 00013 # You should have received a copy of the GNU General Public License 00014 # along with this program. If not, see <http://www.gnu.org/licenses/>. 00015 00016 00017 import wx 00018 from objects.logic.common.globalStrings import globalStrings 00019 from mainFrameContainer import mainFrameContainer 00020 00021 00022 ## Menu bar class. 00023 # The menu bar is currently not used, but it can easily added to the main window during initialization/ 00024 # There is nothing in the menu bar which cannot be found in the toolbar 00025 class mainFrameMenuBar(mainFrameContainer): 00026 def __init__(self, mainFrm): 00027 self.mainFrame = mainFrm 00028 self.createMenuBar() 00029 00030 00031 """ 00032 Menubar related 00033 """ 00034 00035 ## Creates the menubar, and attached it to the parent. 00036 def createMenuBar(self): 00037 menuBar = wx.MenuBar() 00038 for eachMenuData in self.menuData(): 00039 menuLabel = eachMenuData[0] 00040 menuItems = eachMenuData[1] 00041 menuBar.Append(self.createMenu(menuItems), menuLabel) 00042 self.mainFrame.SetMenuBar(menuBar) 00043 00044 00045 ## Creates the menu item, given a dictionary containing the menu's properties 00046 # @param menuData Dictionary containing all menu items which are part of a menu 00047 # @return Menu wx.Menu, which is then attached to the menu bar 00048 def createMenu(self, menuData): 00049 menu = wx.Menu() 00050 for eachItem in menuData: 00051 if len(eachItem) == 2: 00052 label = eachItem[0] 00053 subMenu = self.createMenu(eachItem[1]) 00054 menu.AppendMenu(wx.NewId(), label, subMenu) 00055 else: 00056 self.createMenuItem(menu, *eachItem) 00057 return menu 00058 00059 00060 ## Creates a single menu item. This is basically a helper function used by "createMenu". 00061 # @param menu The wx.Menu object to which append this item. 00062 # @param label String label of the menu item 00063 # @param status I believe this indicates whether the item is enabled or not 00064 # @param handler Handler function which is invoked when this item is triggered 00065 # @param kind Additional Menu items descriptor. I forget what this does exactly. 00066 def createMenuItem(self, menu, label, status, handler, kind=wx.ITEM_NORMAL): 00067 if not label: 00068 menu.AppendSeparator() 00069 return 00070 menuItem = menu.Append(-1, label, status, kind) 00071 self.mainFrame.Bind(wx.EVT_MENU, handler, menuItem) 00072 00073 00074 ## Menu data hash. 00075 def menuData(self): 00076 return [("&File", ( 00077 ("", "", ""), 00078 ("&Exit", "Exit", self.mainFrame.handleExit) 00079 00080 ))] 00081
1.5.8