[Pythonmac-SIG] disabling menus in FrameWork/W?
Thu, 04 Mar 1999 22:38:11 +0100
Recently, Just van Rossum <firstname.lastname@example.org> said:
> Ah, with W, you can define a method can_close(), which should return true
> or false:
> def can_close(self, menuitem):
> return 0
> This should do nicely, together with your Wwindows.py patch.
> With FrameWork, I forgot...
FrameWork sort-of has two opinions on how menus should be
enabled. Originally it provided no help with enabling/disabling menus
and you had to do it all yourself. Then Just contributed the domenu_*
automatic routing of menus to the frontmost window, but apparently the
canmenu_ stuff got lost somewhere along the way.
It should be easy to add in, just call the appropriate canmenu_XXX()
method of either the window or application (if it exists) in
fixmenudimstate(). I'll gladly accept these fixes, of course:-)
The real way to do this, IMNSHO, is to add an extra level of
abstraction. In a framework-derived module I use (that isn't fit to be
shared, unfortunately) I map menuitems to abstract thnigs called
"commands", and each window has a dictionary mapping commands to
callbacks. There's such a dictionary for the application too (and even
for other things like window groups and
currently-active-widget). Windows can now easily disable commands by
removing entries in the dictionary when the command has to be
disabled. Moreover, not only menus map to commands, but buttons can
too (as in toolbars), or appleevents (and you can even address them to
specific windows or other objects). The extra indirection also allows
you to easily play with menubar layout: moving entries from one menu
to another have no impact on the rest of the application. And before
we go into the eventloop, if we know that something in the command
structure has possibly changed, we simply run along the menus and
disable each one for which the command-dict hierarchy currently
doesn't have an entry.
Jack Jansen | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm