mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 19:45:56 +03:00
RF: try finding tkinter in Python rather than C
Use imported module to find tkinter. Should find tkinter module for all available versions of PyPy that have tkinter compiled, as well as CPython.
This commit is contained in:
parent
6968c0c712
commit
4bc75e4088
20
PIL/_tkinter_finder.py
Normal file
20
PIL/_tkinter_finder.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
""" Find compiled module linking to Tcl / Tk libraries
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
|
||||||
|
if sys.version_info[0] > 2:
|
||||||
|
from tkinter import _tkinter as tk
|
||||||
|
else:
|
||||||
|
from Tkinter import tkinter as tk
|
||||||
|
|
||||||
|
if hasattr(sys, 'pypy_find_executable'):
|
||||||
|
# Tested with packages at https://bitbucket.org/pypy/pypy/downloads.
|
||||||
|
# PyPies 1.6, 2.0 do not have tkinter built in. PyPy3-2.3.1 gives an
|
||||||
|
# OSError trying to import tkinter. Otherwise:
|
||||||
|
try: # PyPy 5.1, 4.0.0, 2.6.1, 2.6.0
|
||||||
|
TKINTER_LIB = tk.tklib_cffi.__file__
|
||||||
|
except AttributeError:
|
||||||
|
# PyPy3 2.4, 2.1-beta1; PyPy 2.5.1, 2.5.0, 2.4.0, 2.3, 2.2, 2.1
|
||||||
|
TKINTER_LIB = tk.tkffi.verifier.modulefilename
|
||||||
|
else:
|
||||||
|
TKINTER_LIB = tk.__file__
|
|
@ -223,13 +223,7 @@ TkImaging_Init(Tcl_Interp* interp)
|
||||||
* Functions to fill global Tcl / Tk function pointers by dynamic loading
|
* Functions to fill global Tcl / Tk function pointers by dynamic loading
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03000000
|
#define TKINTER_FINDER "PIL._tkinter_finder"
|
||||||
#define TKINTER_PKG "tkinter"
|
|
||||||
#define TKINTER_MOD "_tkinter"
|
|
||||||
#else
|
|
||||||
#define TKINTER_PKG "Tkinter"
|
|
||||||
#define TKINTER_MOD "tkinter"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
|
||||||
|
|
||||||
|
@ -245,6 +239,12 @@ TkImaging_Init(Tcl_Interp* interp)
|
||||||
#include <psapi.h>
|
#include <psapi.h>
|
||||||
/* Must be linked with 'psapi' library */
|
/* Must be linked with 'psapi' library */
|
||||||
|
|
||||||
|
#if PY_VERSION_HEX >= 0x03000000
|
||||||
|
#define TKINTER_PKG "tkinter"
|
||||||
|
#else
|
||||||
|
#define TKINTER_PKG "Tkinter"
|
||||||
|
#endif
|
||||||
|
|
||||||
FARPROC _dfunc(HMODULE lib_handle, const char *func_name)
|
FARPROC _dfunc(HMODULE lib_handle, const char *func_name)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -438,17 +438,13 @@ int load_tkinter_funcs(void)
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
void *tkinter_lib;
|
void *tkinter_lib;
|
||||||
char *tkinter_libname;
|
char *tkinter_libname;
|
||||||
PyObject *pModule = NULL, *pSubmodule = NULL, *pString = NULL;
|
PyObject *pModule = NULL, *pString = NULL;
|
||||||
|
|
||||||
pModule = PyImport_ImportModule(TKINTER_PKG);
|
pModule = PyImport_ImportModule(TKINTER_FINDER);
|
||||||
if (pModule == NULL) {
|
if (pModule == NULL) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
pSubmodule = PyObject_GetAttrString(pModule, TKINTER_MOD);
|
pString = PyObject_GetAttrString(pModule, "TKINTER_LIB");
|
||||||
if (pSubmodule == NULL) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
pString = PyObject_GetAttrString(pSubmodule, "__file__");
|
|
||||||
if (pString == NULL) {
|
if (pString == NULL) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -467,7 +463,6 @@ int load_tkinter_funcs(void)
|
||||||
dlclose(tkinter_lib);
|
dlclose(tkinter_lib);
|
||||||
exit:
|
exit:
|
||||||
Py_XDECREF(pModule);
|
Py_XDECREF(pModule);
|
||||||
Py_XDECREF(pSubmodule);
|
|
||||||
Py_XDECREF(pString);
|
Py_XDECREF(pString);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user