The following is a little test for tear off menus in wxPython. I altered my
(fairly standard) menu building function to declare all of the menus as
having the tear off style. They don't seemed to be "tearable". Any ideas
why? (I'm on Win2K using wxPython 2.2.5 under python 1.5.2).
The malfunctioning code is below...
Incidentally, I notice that there is no explicit menu demo in the wxPython
demo. I will see about adding a cookbook entry for it when I get the
chance.
Enjoy yourselves,
Mike
8<_________ testtearoff.py _______
from wxPython.wx import *
class EditFrame (wxFrame):
menuData = [
("&File", [
("Choose Source File","", "OnChooseSource", None,None, FALSE),
("Reload Source File","", "OnReloadSource", None,None, FALSE),
("","","", None, None, FALSE),
("E&xit\t<Ctrl-F4>", "Exit Set Editor", "OnExit", None,
(wxACCEL_CTRL , WXK_F4 ), FALSE),
]),
("&View", [
("Routing Diagram","", "OnViewRoutingDiagram", None,None,
FALSE),
("Process Diagram","", "OnViewProcessDiagram", None,None,
FALSE),
("Dependencies","", "OnViewDependencies", None,None, FALSE),
("Animations","", "OnViewAnimations", None,None, FALSE),
]),
("&Actions", [
]),
]
def __init__ (
self, parent= NULL, id= -1, title= "Set SharedObject Editor",
pos = wxDefaultPosition, size = (550,400),
style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN , name = "frame",
engine = None,
):
wxFrame.__init__ (self, parent, id, title, pos, size, style, name)
self._buildMenus()
### Utility functions
def _buildMenus (self):
self.menu = menubar = wxMenuBar()
self.menumapping = {}
accelerators = []
for name, children in self.menuData:
# testing tearoff, doesn't seem to work
menu=wxMenu ( style = wxMENU_TEAROFF)
for text,description,method, ID, acceleratordata, checkable in
children:
if not text:
menu.AppendSeparator ()
else:
if ID is None:
ID =wxNewId()
item = wxMenuItem (menu,ID,text ,description, checkable)
if checkable:
self.menumapping [(name,text)] = item
menu.AppendItem ( item )
## menu.SetHelpString(ID, description)
if hasattr( self, method):
EVT_MENU(self, ID, getattr (self, method))
else:
print "unknown method", method
if acceleratordata:
accelerators.append ( acceleratordata+(ID,) )
menubar.Append (menu, name)
self.menumapping [name] = menu
self.SetAcceleratorTable( wxAcceleratorTable (accelerators))
self.SetMenuBar(menubar)
if __name__ == "__main__":
class DemoApp(wxApp):
def OnInit(self):
wxImage_AddHandler(wxJPEGHandler())
wxImage_AddHandler(wxPNGHandler())
wxImage_AddHandler(wxGIFHandler())
frame = EditFrame(NULL)
#frame = RulesPanel(NULL )
frame.Show(true)
self.SetTopWindow(frame)
return true
def test( ):
app = DemoApp(0)
app.MainLoop()
print 'Creating dialog'
test( )
···
__________________________________
Mike C. Fletcher
Designer, VR Plumber
http://members.home.com/mcfletch