[Image-SIG] Fix for use of tkImaging as a dynloadable command

David Ascher da@skivs.ski.org
Mon, 11 Jan 1999 13:42:23 -0800 (Pacific Standard Time)


Starting with PIL 1.0b1, I've managed to patch tkImaging so that it can be
loaded dynamically from an unmodified tk or _tkinter.  It's surprisingly
not too bad, once one has done it for Togl =).

The patches are very minor, but require changing the name of the init
function to Tkimaging_Init (that's a requirement of the dynloading of Tk
-- it has to be Upper_Init).  

That function should read:

int Tkimaging_Init(Tcl_Interp* interp)
{
   if (Tcl_PkgProvide(interp, "Tkimaging", "1.0") != TCL_OK) {
	return TCL_ERROR;
   }
   Tcl_CreateCommand(interp, "PyImagingPhoto", PyImagingPhoto,
                      (ClientData) NULL, (Tcl_CmdDeleteProc*) NULL);
   return TCL_OK;
}

I suppose one could have two entry points, but that seems gross.

and ImageTk.py should be modified to read:

in class PhotoImage, __init__, insert the indicated code:

	self.__mode = mode
	self.__size = size
#<<<
	# load the Tkimaging Tk extension in the master's interpreter
	# if it's isn't there already  DAA - Jan 99
	if kw.has_key('master'):
	    kw['master'].tk.call('package', 'require', 'Tkimaging')
	else:
	    if Tkinter._default_root is None:
		Tk().tk.call('package', 'require', 'Tkimaging')
	    else:
		Tkinter._default_root.tk.call('package', 'require', 
                                              'Tkimaging')
#>>>
	self.__photo = apply(Tkinter.PhotoImage, (), kw)

and then the usual stuff about actually getting the thing to a place in
which it's recognized as a package with:

../lib/tk8.0> mkdir tkImaging
../lib/tk8.0> cp <path>/tkImaging.dll tkImaging/tkImaging.dll
../lib/tk8.0> tclsh80.exe
% pkg_mkIndex tkImaging
% exit

[replacing tkImaging.dll with tkImaging.so on appropriate platforms]
[the case of the filenames might be important on unix, I don't know]

I haven't tested it very thoroughly, but it seems to work ok for me so
far.

I propose that these patches be added to PIL for future releases. Having
dynamically loaded extensions is a GoodThing(tm).

--david

PS: I have a .pyd of the PIL 1.0b1 with jpeg included if anyone is
    interested in avoiding the compilation process (and of course the
    tkImaging.dll mentioned above).  Also, you can have my VC5 directory
    if you want, but it'll require some tweaking depending on where you
    have other things.  Just email me.  [I use 1.5.2b1].

PPS: Fredrik -- FYI, I still have that problem with the Adobe CMYK file --
     is that just a difference of opinion among 'standards'?