[Pythonmac-SIG] _menustocheck questions

Corran Webster cwebster@nevada.edu
Fri, 4 Aug 2000 23:22:05 -0700


At 11:21 PM -0400 4/8/00, Gordon Worley wrote:
> At 10:50 PM -0700 8/3/2000, Corran Webster wrote:
> >  > def makeusermenus(self):
> >[...]
> >>       # These menu items need to be updated periodically;
> >>       #   any menu item not handled by the application should be here,
> >>       #   as should any with a "can_" handler.
> >>       self._menustocheck = [closeitem, saveitem, saveasitem,
> >>               undoitem, cutitem, copyitem, pasteitem,
> >>               clearitem, selallitem]
> >>

[snip]

> For example, let's consider selectall for a minute since I've thrown
> that out previously.  The callback for the menu is selectall, so
> domenu_selectall and can_selectall would be what we want to code.
> Now, we also want selectall in _menustocheck so that the
> can_selectall function won't have been written just to sit idlely.
>  From looking at other items in _menustocheck (like saveitem and
> copyitem), it seems that we would just append item to the callback
> name.  selectall, however, in _menustocheck is put in as selallitem,
> reporting a NameError if anything else is put there instead.  I don't
> see where this syntax is comming from, and thus can't add any more
> items into _menustocheck unless I get lucky and happen to guess the
> right thing to put there.  Maybe I'm just missing something basic
> here that everyone else has already figured out, but I just can't see
> why something like selallitem works while selectallitem doesn't
> (which extends to adding menu items to _menustocheck that have never
> been added to it by anyone else before).
>
> Consider one more final example, where I try to add add_item to
> _menustocheck.  All of my attempts has looked basically like this:
>
> self._menustocheck = [closeitem, ..., add_itemitem]
>
> which results in a NameError on the newly added item.  To be more
> direct, where do the names used in _menustocheck come from and how do
> they relate to the menuitems that they are connected to?

OK, I see what you're asking.  Sorry for missing the point in my previous
reply.

If you look in the code for makeusermenus() you will see the line

	selallitem = FrameWork.MenuItem(m, "Select all", "A", "selectall")

which is what creates the selectall menu.  The arguments are respectively,
the menu that the item is inserted into, the text of the menu, the command
key equivalent, and the callback.  It's the callback that you're after.  If
the callback is a string, then you have the options of using the "domenu_"
or "can_" methods in widgets.

However, when specifying the _menustocheck, you need to use the actual menu
item object, not the callback, ie. selallitem.  That's why you've been
getting name errors - you've been trying to add non-existent menu item
objects to the list.

To consider your second example, you could do it by adding the line

	add_itemitem = Framework.MenuItem(m, "Add Item", None, "additem")

in the appropriate place in makeusermenus, and changing

	self._menustocheck = [ ... stuff ..., add_itemitem]

finally, you'd add "domenu_additem" and possibly "can_additem" methods to
appropriate widget classes.

Hope this helps.

Regards,
Corran