On 1-Mar-07, at 5:36 AM, Amrit Jassal wrote: > I have a static dock menu created with Interface Builder (cocoa). > Works great. > I now have a requirement to add/remove items for this menu at run- > time or enable/disable menu items at run-time. > > I cannot find a way to get a handle to the dock menu at run-time to > get at the menu items that I want to enable/disable. Can I somehow > get a reference to menu objects (NSMenu) at run-time?
Sure, there are several ways. Your menu should already be hooked up to the NSApplication outlet dockMenu in Interface Builder. In theory you should be able to get a reference using NSApp().dockMenu(), but that doesn't appear to work. You could subclass NSApplication to add another outlet that behaves normally and gives you access to the menu. You could probably extract the menu from the Nib file, but that's beyond what I can explain in an email. > Or I cannot wire up the menu using IB and need to create the menu > at run-time myself? That's certainly an option. I'm not sure why the dockMenu outlet is not exposed in the API. There is an (undocumented) NSApp ().setDockMenu_(my_menu) call in AppKit, but no corresponding .dockMenu() unfortunately. You can either use the setDockMenu, or if your application delegate returns a menu from applicationDockMenu_(application) that menu will be used, over-riding any menu set in Interface Builder. HTH --Dethe You need to lay out the user interface components visually, by hand, with total control over where they go. Automated LayoutManagers don’t cut it. A corollary of this is that you can’t move a UI layout from one platform to another and have the computer make everything fit. Computers don’t lay out interfaces by themselves any better than they can translate French to English by themselves. -- Jens Alfke _______________________________________________ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig