AW: [Idle-dev] Extends an events

Matthias Barmeier barmeier@BARMEIER.COM
Thu, 2 Mar 2000 17:12:54 +0100


Hi,


What do you think about this:

Every menu item will register an a central "event manager". The event
manager will store the
menu items name like "File/Open..." as key in a dictionary. When registering
the calling extension
will transmit the callback for the default function to the event manager
too. The callback is stored
in an array attached to the dictionary.

The code is for reading only !! (not for running)

	evtmgr={}

	def menuRegisterCallback (itemName, defaultCallback, type=2): ## 2=default,
											  ## 1=call before default, 3=call after default
		if not evtmgr.has_key(itemName):
			evtmgr[itemName]=[]
		evtmgr[itemName].append((defaultCallback,type))
		evtmgr.sort(... for type ...)


When a menu item is selected a menu "driver function" is called that makes a
lookup in the evtmgr dictionary
and calls all callbacks (ordered by type) that are stored there in the
dictionary.

	def menuDriveEvent (itemName):
		results={}
		for calls,type in evtmgr[itemName]:
			## any callback can have some results the
			## should be passed and manipulated by the callbacks in the
			## chain.
			results=calls (itemName,results)

Usage?
Could happen like this:

To add the standard functionality :

	def openfile (itemName, params):
		if !params.has_key("defaultdir"):
			... use standard directory to open file dialog ...
		else:
			... use params["defaultdir"] ...

		... after selectting a file ...
		params["filename"]=the_filename
		return (params)

	menuRegisterCallback ("File/Open...", openfile, 2)

To intercept:

	def maintainRecentlist (itemName, params):
		addFileToRecentList (itemName)
		return (params)			## do nothing with the params

	menuRegisterCallback ("File/Open...", maintainRecentList, 3)


The Tcl/Tk menubutton callback must be redirected to the EventDriver but I
think
this could work. (after the hard work is done of course ;-) )

This is from scratch. My english is not good enough but I hope the code
will help to understand what I want to say.

What do you think does this make any sense to you ??

/*
    Dipl.-Inform. Matthias Barmeier        Tel: +49 (0)30 79 70 72 87
    Büro für Softwareentwicklung           Fax +49 (0)30 79 70 72 88
    Grunewaldstr. 18                       Email: barmeier@barmeier.com
    12165 Berlin                           WWW: <http://www.barmeier.com>
*/


> -----Ursprüngliche Nachricht-----
> Von: guido@CNRI.Reston.VA.US [mailto:guido@CNRI.Reston.VA.US]Im Auftrag
> von Guido van Rossum
> Gesendet: Donnerstag, 2. März 2000 15:04
> An: Matthias Barmeier
> Cc: idle-dev@python.org
> Betreff: Re: [Idle-dev] Extends an events
>
>
> > I thin over adding a "Recent files" list for the IDLE file menu.
> > My first thought was to use extend.py but I dont know how I can capture
> > the "Open event".
> >
> > Is this possible  with extend.py ???
> >
> > If this is not already possible to capture the menu events
> without changeing
> > the
> > IDLE Source I think this should be added.
> >
> > Such a feature is very usefull for file locking or check in / check out
> > mechanisms.
>
> To add Recent files, you would have to modify the "open" command.
>
> The menus are configurable by extensions, but capturing standard menus
> is not possible yet.  Can you suggest an architecture for that?
>
> --Guido van Rossum (home page: http://www.python.org/~guido/)