[wxPython] wxMenu wxMENU_TEAROFF

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 :frowning:
            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

Hi,

Mike C. Fletcher wrote:

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).

Because you're on Win2K.

Ok, increased verbosity: this is supported only by wxGTK (there's a
good reason for that: the concept of tearable menus is alien to
Windows). I hoped this is an opportunity to tell somebody to RTFM,
but the flag is not documented as it should be -- so, wait a couple
of hours for me to commit docs update, checkout documentation from
wxWindows CVS and *then* RTFM ;-))

bye,
Vaclav

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 tearoff style is only supported on wxGTK as there is native support for
it there. If MS had natvie support for it then you could do it in wxMSW
too, but for some reason MS doesn't think they are usefull...

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.

I just figured that the menu used by the main demo fram was enough, but if
you think it would be beneficial to have it there then maybe writing a
sample to plug into the demo instead of (or perhaps in addition to) doing a
cookbook recipie would be better.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!