[Image-SIG] patch to build a Tcl PIL module

Matthias Klose doko@cs.tu-berlin.de
Sun, 28 Mar 1999 11:45:58 +0200 (MET DST)


The current (1.0b1) approach has the disadvantage that you have to
rebuild _tkinter to use Tkinter support. The following patch builds
the Tcl PIL module as a shared module

--- python-pil-0.3b2.orig/PIL/ImageTk.py
+++ python-pil-0.3b2/PIL/ImageTk.py
@@ -110,6 +110,7 @@
             block = image.new_block(self.__mode, im.size)
             image.convert2(block, image) # convert directly between buffers
 
+        self.__photo.tk.call("package", "require", "Pil")
         self.__photo.tk.call("PyImagingPhoto", self.__photo, block.id)
 
 
--- python-pil-0.3b2.orig/Tk/tkImaging.c
+++ python-pil-0.3b2/Tk/tkImaging.c
@@ -183,9 +183,22 @@
 }
 
 
+#ifdef PIL_MODULE
+int
+Pil_Init(Tcl_Interp* interp)
+{                                                                               
+    Tcl_CreateCommand(interp, "PyImagingPhoto", PyImagingPhoto,                 
+                      (ClientData) 0, (Tcl_CmdDeleteProc*) NULL);               
+    if (Tcl_PkgProvide(interp, "Pil", "1.0") != TCL_OK) {
+         return TCL_ERROR;
+    }
+    return TCL_OK;
+}                                                                               
+#else
 void
 TkImaging_Init(Tcl_Interp* interp)
 {
     Tcl_CreateCommand(interp, "PyImagingPhoto", PyImagingPhoto,
                       (ClientData) 0, (Tcl_CmdDeleteProc*) NULL);
 }
+#endif
--- python-pil-0.3b2.orig/Tk/Makefile
+++ python-pil-0.3b2/Tk/Makefile
@@ -0,0 +1,50 @@
+# The C compiler:
+CC = cc
+
+# Compiler options:
+COPTS = -O2 -fpic -DPIL_MODULE
+
+# Name for the shared lib:
+SH_LIB = PIL.so
+
+# Shared library linker command:
+SHLINK = cc -shared
+
+# Where to find tcl.h, tk.h
+INCLUDES =
+
+# Where to find libtcl.a, libtk.a
+LIBDIRS =
+
+# Libraries to link with (-ldl for Linux only?):
+LIBS = -ltk8.0 -ltcl8.0 -lm -lc -ldl
+
+TK_FLAGS =
+
+
+#### Shouldn't have to change anything beyond this point ####
+
+
+CFLAGS = $(COPTS) $(INCLUDES) $(TK_FLAGS)
+
+LFLAGS = $(LIBDIRS)
+
+all: shared pkgIndex.tcl
+
+shared: $(SH_LIB)
+
+tkImaging.o: tkImaging.c
+	$(CC) -c -I../libImaging $(CFLAGS) tkImaging.c
+
+
+$(SH_LIB): tkImaging.o
+	$(SHLINK) $(LFLAGS) $(LIBS) tkImaging.o -o $@
+
+pkgIndex.tcl: $(SH_LIB)
+	echo pkg_mkIndex . $(SH_LIB) | tclsh8.0
+
+clean:
+	-rm -f *.o *~ core pkgIndex.tcl
+
+realclean:
+	-rm -f *.o *~ core *.so pkgIndex.tcl