How to re-enable a menubar?

Hi:

(Python 2.5 on Suse 9.1 Linux 2.6.x with wxPython 2.8.6.0)

I used pywrap to run the code shown below so I could muck with the running objects.

Then at the pywrap command line I entered:

>>> app.frame.menubar.Disable()
True

At which point the menubar greyed out, as expected.

Ok, now how to get it enabled again? The docs here:

http://www.wxpython.org/docs/api/wx.MenuBar-class.html

Indicate that an id is needed to pass to the Enable() method of a wx.Menubar. Actually the docs are a bit confusing. It says:

"Enable(self, id, enable)," then it says:

Parameters:
     enable
                (type=bool)

What is the id parameter and why isn't it described?

So I tried this (among other things, none of which worked):

>>> app.frame.menubar.GetId()
-202
>>> app.frame.menubar.Enable(-202, True)
Traceback (most recent call last):
   File "<input>", line 1, in <module>
   File "/usr/lib/python2.5/site-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 11151, in Enable
     return _core_.MenuBar_Enable(*args, **kwargs)
PyAssertionError: C++ assertion "item" failed at ../src/common/menucmn.cpp(1072) in Enable(): attempt to enable an item which doesn't exist

So what is the id required by the enable method, and how to get it? What is the -203? Is that the wx.ID for the menubar? If so, why isn't it accepted by the Enable() method?

Thanks for input.

···

--------------------------------------------------------------------
#!/usr/bin/env python

import wx

class MyFrame(wx.Frame):
     def __init__(self, parent):
         wx.Frame.__init__(self, parent, -1, "Test Frame",
                 size=(640,480))
         self.menubar = wx.MenuBar()
         menu = wx.Menu()
         self.menubar.Append(menu, "&File")
         self.SetMenuBar(self.menubar)

class MyApp(wx.App):
     def OnInit(self):
         self.frame = MyFrame(None)
         self.frame.Show(True)
         return True

if __name__ == "__main__":
     app = MyApp()
     app.MainLoop()
--------------------------------------------------------------------

Good day!

--
_____________________
Christopher R. Carlen
crobc@bogus-remove-me.sbcglobal.net
SuSE 9.1 Linux 2.6.5

Chris Carlen wrote:

Hi:

(Python 2.5 on Suse 9.1 Linux 2.6.x with wxPython 2.8.6.0)

I used pywrap to run the code shown below so I could muck with the running objects.

Then at the pywrap command line I entered:

>>> app.frame.menubar.Disable()
True

At which point the menubar greyed out, as expected.

Ok, now how to get it enabled again? The docs here:

Looks like wxMenubar is inheriting the Disable method from wxWindow, but the base class Enable method is being hidden by an implementation in the wxMenuBar class. Try this to invoke the base class version instead:

wx.Window.Enable(app.frame.menubar)

BTW, I don't think that the other platforms will support disabling the whole menu bar this way. You'll probably be better off dis/enabling each top level menu item using EnableTop.

···

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

Robin Dunn wrote:

Chris Carlen wrote:

>>> app.frame.menubar.Disable()
True
Ok, now how to get it enabled again?

Looks like wxMenubar is inheriting the Disable method from wxWindow, but the base class Enable method is being hidden by an implementation in the wxMenuBar class. Try this to invoke the base class version instead:

wx.Window.Enable(app.frame.menubar)

Thank you for your response!

Yeah, that certainly works.

What then is the purpose of wx.Menubar.Enable(self, id, enable) ?

Oh, I see that it takes IDs of the menu items. Ok, so I can use it to dis/enable menu items.

So only the documentation remains confusing as the Method Summary at:
http://www.wxpython.org/docs/api/wx.MenuBar-class.html
says:
"bool Enable(self, enable)"
But down below in "Instance Method Details" says:
"Enable(self, id, enable) ...
     Parameters:
         enable
                    (type=bool)
     Returns:
         bool
     Overrides:
         wx.Window.Enable (inherited documentation)

Eek! Is this documentation totally machine generated? At least it gives the clue that the base class Enable() is overriden. But the multiple contradictions in the parameters is confusing.

BTW, I don't think that the other platforms will support disabling the whole menu bar this way. You'll probably be better off dis/enabling each top level menu item using EnableTop.

Yeah, it was an accident that I tried the menubar.Disable thing. I was just wandering the docs and playing with pywrap to get used to things, and trying to solve a problem with a code in the "wxPython in Action" book.

Once I figure out how to get pywrap to work on that blasted Windows I'll see about this...

Good day!

···

--
_____________________
Christopher R. Carlen
crobc@bogus-remove-me.sbcglobal.net
SuSE 9.1 Linux 2.6.5

Chris Carlen wrote:

So only the documentation remains confusing as the Method Summary at:
http://www.wxpython.org/docs/api/wx.MenuBar-class.html
says:
"bool Enable(self, enable)"
But down below in "Instance Method Details" says:
"Enable(self, id, enable) ...
    Parameters:
        enable
                   (type=bool)
    Returns:
        bool
    Overrides:
        wx.Window.Enable (inherited documentation)

Eek! Is this documentation totally machine generated? At least it gives the clue that the base class Enable() is overriden. But the multiple contradictions in the parameters is confusing.

Yes, I recently noticed another place where inheritance was causing the docs tool to get confused.

···

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