Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 10 May 1996 14:16:16 -0500 (CDT)
From:      Soren Dayton <soren@ambiguity.i-2.com>
To:        freebsd-ports@freebsd.org, jkh@freebsd.org
Subject:   python with tcl 7.5 and Tk 4.1
Message-ID:  <199605101916.OAA10755@ambiguity.i-2.com>

next in thread | raw e-mail | index | archive | help
Reply-To: csdayton@midway.uchicago.edu

Hi

I got some stuff from ftp://ftp.python.org/pub/python/guido that seems to
allow one to build python with the most recent tcl/tk

Here are the diffs.

Soren Dayton


diff -rcP Python-1.3/Modules/tkiniter.c Python-1.3.work/Modules/tkiniter.c
*** Python-1.3/Modules/tkiniter.c	Wed Dec 31 18:00:00 1969
--- Python-1.3.work/Modules/tkiniter.c	Fri May 10 12:48:23 1996
***************
*** 0 ****
--- 1,72 ----
+ /* tkintermodule.c -- Interface to libtk.a and libtcl.a.
+    Copyright (C) 1994 Steen Lumholt */
+ 
+ #ifdef macintosh
+ #define MAC_TCL
+ #endif
+ 
+ #ifdef MAC_TCL
+ #define WITH_APPINIT
+ #endif
+ 
+ #ifndef PyInit_tkinter
+ #define PyInit_tkinter inittkinter
+ #endif
+ 
+ #include <tcl.h>
+ #include <tk.h>
+ 
+ void
+ PyInit_tkinter ()
+ {
+   static inited = 0;
+ 
+ #ifdef WITH_READLINE
+   extern int (*rl_event_hook) ();
+ #endif /* WITH_READLINE */
+   PyObject *m, *d, *v;
+ 
+   m = Py_InitModule ("tkinter", moduleMethods);
+ 
+   d = PyModule_GetDict (m);
+   Tkinter_TclError = Py_BuildValue ("s", "TclError");
+   PyDict_SetItemString (d, "TclError", Tkinter_TclError);
+ 
+   v = Py_BuildValue ("i", TK_READABLE);
+   PyDict_SetItemString (d, "READABLE", v);
+   v = Py_BuildValue ("i", TK_WRITABLE);
+   PyDict_SetItemString (d, "WRITABLE", v);
+   v = Py_BuildValue ("i", TK_EXCEPTION);
+   PyDict_SetItemString (d, "EXCEPTION", v);
+   v = Py_BuildValue ("i", TK_X_EVENTS);
+   PyDict_SetItemString (d, "X_EVENTS", v);
+   v = Py_BuildValue ("i", TK_FILE_EVENTS);
+   PyDict_SetItemString (d, "FILE_EVENTS", v);
+   v = Py_BuildValue ("i", TK_TIMER_EVENTS);
+   PyDict_SetItemString (d, "TIMER_EVENTS", v);
+   v = Py_BuildValue ("i", TK_IDLE_EVENTS);
+   PyDict_SetItemString (d, "IDLE_EVENTS", v);
+   v = Py_BuildValue ("i", TK_ALL_EVENTS);
+   PyDict_SetItemString (d, "ALL_EVENTS", v);
+   v = Py_BuildValue ("i", TK_DONT_WAIT);
+   PyDict_SetItemString (d, "DONT_WAIT", v);
+   v = Py_BuildValue ("s", TK_VERSION);
+   PyDict_SetItemString (d, "TK_VERSION", v);
+   v = Py_BuildValue ("s", TCL_VERSION);
+   PyDict_SetItemString (d, "TCL_VERSION", v);
+ 
+ #ifdef WITH_READLINE
+   rl_event_hook = EventHook;
+ #endif /* WITH_READLINE */
+ 
+   if (!inited)
+     {
+       inited = 1;
+       if (Py_AtExit (Tkinter_Cleanup) != 0)
+ 	fprintf(stderr,
+ 		"Tkinter: warning: cleanup procedure not registered\n");
+     }
+ 
+   if (PyErr_Occurred ())
+     Py_FatalError ("can't initialize module tkinter");
+ }
diff -rcP Python-1.3/Modules/tkintermodule.c Python-1.3.work/Modules/tkintermodule.c
*** Python-1.3/Modules/tkintermodule.c	Sat Sep 30 12:00:24 1995
--- Python-1.3.work/Modules/tkintermodule.c	Fri May 10 12:48:58 1996
***************
*** 1,18 ****
! /* tkintermodule.c -- Interface to libtk.a and libtcl.a.
     Copyright (C) 1994 Steen Lumholt */
  
  #include "Python.h"
  
- #ifdef macintosh
- #define MAC_TCL
- #endif
- 
- #ifdef MAC_TCL
- #define WITH_APPINIT
- #endif
- 
- #define PyInit_tkinter inittkinter
- 
  #include <tcl.h>
  #include <tk.h>
  
--- 1,8 ----
! /* _tkinter.c -- Interface to libtk.a and libtcl.a.
     Copyright (C) 1994 Steen Lumholt */
  
  #include "Python.h"
  
  #include <tcl.h>
  #include <tk.h>
  
***************
*** 24,35 ****
--- 14,44 ----
  #else
  extern int tk_NumMainWindows;
  #define Tk_GetNumMainWindows() (tk_NumMainWindows)
+ #define NEED_TKCREATEMAINWINDOW 1
  #endif
  
  #if TK_MAJOR_VERSION < 4
  extern struct { Tk_Window win; } *tkMainWindowList;
  #endif
  
+ #ifdef macintosh
+ 
+ /*
+ ** Additional cruft needed by Tcl/Tk on the Mac.
+ ** Unfortunately this changes with each beta.
+ ** This is for beta 2 of Tcl 7.5 and Tk 4.1.
+ */
+ 
+ #include <Events.h> /* For EventRecord */
+ 
+ typedef int (*TclMacConvertEventPtr) Py_PROTO((EventRecord *eventPtr));
+ void TclMacSetEventProc Py_PROTO((TclMacConvertEventPtr procPtr));
+ int TkMacConvertEvent Py_PROTO((EventRecord *eventPtr));
+ 
+ staticforward int PyMacConvertEvent Py_PROTO((EventRecord *eventPtr));
+ 
+ #endif /* macintosh */
+ 
  /**** Tkapp Object Declaration ****/
  
  staticforward PyTypeObject Tkapp_Type;
***************
*** 38,49 ****
--- 47,62 ----
    {
      PyObject_HEAD
      Tcl_Interp *interp;
+ #ifdef NEED_TKCREATEMAINWINDOW
      Tk_Window tkwin;
+ #endif
    }
  TkappObject;
  
  #define Tkapp_Check(v) ((v)->ob_type == &Tkapp_Type)
+ #ifdef NEED_TKCREATEMAINWINDOW
  #define Tkapp_Tkwin(v)  (((TkappObject *) (v))->tkwin)
+ #endif
  #define Tkapp_Interp(v) (((TkappObject *) (v))->interp)
  #define Tkapp_Result(v) (((TkappObject *) (v))->interp->result)
  
***************
*** 210,217 ****
  Tcl_AppInit (interp)
       Tcl_Interp *interp;
  {
!     Tk_Window main;
!     main = Tk_MainWindow(interp);
    if (Tcl_Init (interp) == TCL_ERROR) {
      fprintf(stderr, "Tcl_Init error: %s\n", interp->result);
      return TCL_ERROR;
--- 223,231 ----
  Tcl_AppInit (interp)
       Tcl_Interp *interp;
  {
!   Tk_Window main;
! 
!   main = Tk_MainWindow(interp);
    if (Tcl_Init (interp) == TCL_ERROR) {
      fprintf(stderr, "Tcl_Init error: %s\n", interp->result);
      return TCL_ERROR;
***************
*** 222,227 ****
--- 236,248 ----
    }
    return TCL_OK;
  }
+ 
+ char *
+ TkDefaultAppName()
+ {
+     return "Python";
+ }
+ 
  #endif /* !WITH_APPINIT */
  
  /* Initialize the Tk application; see the `main' function in
***************
*** 240,251 ****
--- 261,275 ----
      return NULL;
  
    v->interp = Tcl_CreateInterp ();
+ 
+ #ifdef NEED_TKCREATEMAINWINDOW
    v->tkwin = Tk_CreateMainWindow (v->interp, screenName, 
  				  baseName, className);
    if (v->tkwin == NULL)
      return (TkappObject *) Tkinter_Error ((PyObject *) v);
  
    Tk_GeometryRequest (v->tkwin, 200, 200);
+ #endif
  
    if (screenName != NULL)
      Tcl_SetVar2 (v->interp, "env", "DISPLAY", screenName, TCL_GLOBAL_ONLY);
***************
*** 843,849 ****
    /* ClientData is: (func, file) */
    data = Py_BuildValue ("(OO)", func, file);
  
!   Tk_CreateFileHandler (id, mask, FileHandler, (ClientData) data);
    /* XXX fileHandlerDict */
  
    Py_INCREF (Py_None);
--- 867,873 ----
    /* ClientData is: (func, file) */
    data = Py_BuildValue ("(OO)", func, file);
  
!   Tk_CreateFileHandler ((ClientData) id, mask, FileHandler, (ClientData) data);
    /* XXX fileHandlerDict */
  
    Py_INCREF (Py_None);
***************
*** 864,870 ****
    if (id < 0)
      return NULL;
  
!   Tk_DeleteFileHandler (id);
    /* XXX fileHandlerDict */
    Py_INCREF (Py_None);
    return Py_None;
--- 888,894 ----
    if (id < 0)
      return NULL;
  
!   Tk_DeleteFileHandler ((ClientData) id);
    /* XXX fileHandlerDict */
    Py_INCREF (Py_None);
    return Py_None;
***************
*** 1118,1124 ****
--- 1142,1150 ----
  Tkapp_Dealloc (self)
       PyObject *self;
  {
+ #ifdef NEED_TKCREATEMAINWINDOW
    Tk_DestroyWindow (Tkapp_Tkwin (self));
+ #endif
    Tcl_DeleteInterp (Tkapp_Interp (self));
    PyMem_DEL (self);
  }
***************
*** 1219,1225 ****
  }
  
  void
! PyInit_tkinter ()
  {
    static inited = 0;
  
--- 1245,1251 ----
  }
  
  void
! init_tkinter ()
  {
    static inited = 0;
  
***************
*** 1228,1234 ****
  #endif /* WITH_READLINE */
    PyObject *m, *d, *v;
  
!   m = Py_InitModule ("tkinter", moduleMethods);
  
    d = PyModule_GetDict (m);
    Tkinter_TclError = Py_BuildValue ("s", "TclError");
--- 1254,1260 ----
  #endif /* WITH_READLINE */
    PyObject *m, *d, *v;
  
!   m = Py_InitModule ("_tkinter", moduleMethods);
  
    d = PyModule_GetDict (m);
    Tkinter_TclError = Py_BuildValue ("s", "TclError");
***************
*** 1270,1279 ****
      }
  
    if (PyErr_Occurred ())
!     Py_FatalError ("can't initialize module tkinter");
  }
  
  #ifdef macintosh
  void
  panic(char * format, ...)
  {
--- 1296,1317 ----
      }
  
    if (PyErr_Occurred ())
!     Py_FatalError ("can't initialize module _tkinter");
! #ifdef macintosh
!   TclMacSetEventProc(PyMacConvertEvent);
! #if GENERATINGCFM
!   mac_addlibresources();
! #endif /* GENERATINGCFM */
! #endif /* macintosh */
  }
  
+ 
  #ifdef macintosh
+ 
+ /*
+ ** Anyone who embeds Tcl/Tk on the Mac must define panic().
+ */
+ 
  void
  panic(char * format, ...)
  {
***************
*** 1289,1292 ****
      Py_FatalError("Tcl/Tk panic");
  }
  
! #endif
--- 1327,1390 ----
      Py_FatalError("Tcl/Tk panic");
  }
  
! /*
! ** Pass events to SIOUX before passing them to Tk.
! */
! 
! static int
! PyMacConvertEvent(eventPtr)
!     EventRecord *eventPtr;
! {
!   if (SIOUXHandleOneEvent(eventPtr))
!     return 0; /* Nothing happened to the Tcl event queue */
!   return TkMacConvertEvent(eventPtr);
! }
! 
! #if GENERATINGCFM
! 
! /*
! ** Additional Mac specific code for dealing with shared libraries.
! */
! 
! #include <Resources.h>
! #include <CodeFragments.h>
! 
! static int loaded_from_shlib = 0;
! static FSSpec library_fss;
! 
! /*
! ** If this module is dynamically loaded the following routine should
! ** be the init routine. It takes care of adding the shared library to
! ** the resource-file chain, so that the tk routines can find their
! ** resources.
! */
! OSErr pascal
! init_tkinter_shlib(InitBlockPtr data)
! {
! 	if ( data == nil ) return noErr;
! 	if ( data->fragLocator.where == kOnDiskFlat ) {
! 		library_fss = *data->fragLocator.u.onDisk.fileSpec;
! 		loaded_from_shlib = 1;
! 	} else if ( data->fragLocator.where == kOnDiskSegmented ) {
! 		library_fss = *data->fragLocator.u.inSegs.fileSpec;
! 		loaded_from_shlib = 1;
! 	}
! 	return noErr;
! }
! 
! /*
! ** Insert the library resources into the search path. Put them after
! ** the resources from the application. Again, we ignore errors.
! */
! static
! mac_addlibresources()
! {
! 	if ( !loaded_from_shlib ) 
! 		return;
! 	(void)FSpOpenResFile(&library_fss, fsRdPerm);
! }
! 
! #endif /* GENERATINGCFM */
! #endif /* macintosh */
! 
! #include "tkiniter.c"



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605101916.OAA10755>