Pillow/src/_imagingtk.c

80 lines
1.8 KiB
C
Raw Normal View History

2010-07-31 06:52:47 +04:00
/*
* The Python Imaging Library.
*
* tkinter hooks
*
* history:
2020-05-01 15:08:57 +03:00
* 99-07-26 fl created
* 99-08-15 fl moved to its own support module
2010-07-31 06:52:47 +04:00
*
* Copyright (c) Secret Labs AB 1999.
*
* See the README file for information on usage and redistribution.
*/
#include "Python.h"
#include "libImaging/Imaging.h"
2010-07-31 06:52:47 +04:00
2020-09-29 12:54:57 +03:00
#include "Tk/_tkmini.h"
2010-07-31 06:52:47 +04:00
/* must link with Tk/tkImaging.c */
2021-01-03 06:17:51 +03:00
extern void
TkImaging_Init(Tcl_Interp *interp);
extern int
load_tkinter_funcs(void);
2010-07-31 06:52:47 +04:00
/* copied from _tkinter.c (this isn't as bad as it may seem: for new
versions, we use _tkinter's interpaddr hook instead, and all older
versions use this structure layout) */
typedef struct {
2021-01-03 06:17:51 +03:00
PyObject_HEAD Tcl_Interp *interp;
2010-07-31 06:52:47 +04:00
} TkappObject;
2021-01-03 06:17:51 +03:00
static PyObject *
_tkinit(PyObject *self, PyObject *args) {
Tcl_Interp *interp;
2010-07-31 06:52:47 +04:00
2021-01-03 06:17:51 +03:00
PyObject *arg;
2010-07-31 06:52:47 +04:00
int is_interp;
2020-05-10 12:56:36 +03:00
if (!PyArg_ParseTuple(args, "Oi", &arg, &is_interp)) {
2010-07-31 06:52:47 +04:00
return NULL;
2020-05-10 12:56:36 +03:00
}
2010-07-31 06:52:47 +04:00
2020-05-10 12:56:36 +03:00
if (is_interp) {
2021-01-03 06:17:51 +03:00
interp = (Tcl_Interp *)PyLong_AsVoidPtr(arg);
2020-05-10 12:56:36 +03:00
} else {
2021-01-03 06:17:51 +03:00
TkappObject *app;
2020-05-01 15:08:57 +03:00
/* Do it the hard way. This will break if the TkappObject
layout changes */
2021-01-03 06:17:51 +03:00
app = (TkappObject *)PyLong_AsVoidPtr(arg);
2010-07-31 06:52:47 +04:00
interp = app->interp;
}
/* This will bomb if interp is invalid... */
TkImaging_Init(interp);
Py_INCREF(Py_None);
return Py_None;
}
static PyMethodDef functions[] = {
/* Tkinter interface stuff */
{"tkinit", (PyCFunction)_tkinit, 1},
{NULL, NULL} /* sentinel */
};
PyMODINIT_FUNC
PyInit__imagingtk(void) {
static PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
2021-01-03 06:17:51 +03:00
"_imagingtk", /* m_name */
NULL, /* m_doc */
-1, /* m_size */
functions, /* m_methods */
};
PyObject *m;
m = PyModule_Create(&module_def);
return (load_tkinter_funcs() == 0) ? m : NULL;
}