Issue 5159: Indicating packages to be loaded when a Tcl interpreter is created in tkinter (original) (raw)
Hi,
It seems to me that it would be useful to add something to indicate which packages should be loaded, and how they should be loaded, when a Tcl interpreter is created through Tkinter.Tk. Right now every extension has to add some boilerplate code to load a package before starting the use of extension, and this code tends to be very similar -- like this:
if not required_extension_loaded: extlib = os.environ.get('OPTIONAL_VAR_THAT_POINTS_TO_EXT') if extlib: master.tk.eval('global auto_path; ' 'lappend auto_path {%s}' % extlib) master.tk.call('package', 'require', 'Extlibname') required_extension_loaded = True
master is an instance of Tkinter.Tk which has to be created before this, of course. Some extensions do it in different places in their code, but tend to involve basically the same code.
The patch attached adds a new module in lib-tk named tkdeploader (not very nice eh) which handles these "indications". Each dependence to be loaded can define its own preloader callable, but the module adds a basic one, named basic_preloader, that should be enough for most situations. The patch also includes the changes necessary in Tkinter.py, just two lines.