[Pythonmac-SIG] Is the menu enabled?
Joseph J. Strout
joe@strout.net
Tue, 12 Oct 1999 09:51:06 -0700
At 12:23 PM -0400 10/12/99, James B. Wilkinson wrote:
>I see that the Menu module implements the GetMenuHandle() function, but I
>have no idea how to use it in Python. In C, I think I could use the handle
>to get to the MenuInfo record and look at the enableFlags. How to do that
>in Python is beyond me, and I don't know how to learn anything beyond what
>I've done: type "import Menu" and "dir(Menu)". That tells me that
>GetMenuHandle() is there, but not how to use it. Is there a good way to
>answer questions like this, or do you just have to know?
Go it a step further. Start with "inspect(Menu)" rather than
"dir(Menu)", as you'll have easy access to the docstrings for each
function this way. Then do "foo = GetMenuHandle()" (passing
whatever it needs passed to get this step to work), and then
"inspect(foo)", which will show you the methods and members of foo.
Now, foo is a resource object (resources and handles are the same
thing in MacPython, for some odd reason). You can get its data (it's
just a member, IIRC). That data is of the same format as documented
in your favorite toolbox reference (i.e., whatever a MenuHandle
refers to). You can use the struct module to unpack this and get
whatever you need out of it.
Cheers,
-- Joe
,------------------------------------------------------------------.
| Joseph J. Strout Biocomputing -- The Salk Institute |
| joe@strout.net http://www.strout.net |
`------------------------------------------------------------------'