PLplot  5.9.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plplot_widgetmodule.c
Go to the documentation of this file.
1 // C code to create dynamically loaded library to implement plplot_widget module
2 
3 #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
4 #include <Python.h>
5 #include <arrayobject.h>
6 #include "plplot.h"
7 #include "plplotP.h"
8 
9 #ifdef ENABLE_tk
10 #include <tcl.h>
11 #endif
12 
13 #define TRY( E ) if ( !( E ) ) return NULL
14 
15 #ifdef ENABLE_tk
16 static char doc_Pltk_init[] = "Initialize the Pltk Tcl extension.";
17 
18 //--------------------------------------------------------------------------
19 // A python module method for initializing the PLtk extension. This method
20 // must be called from python with a single argument, which is the address of
21 // the Tcl interpreter into which the Pltk extension is to be injected.
22 //--------------------------------------------------------------------------
23 
24 static PyObject *pl_Pltk_init( PyObject * PL_UNUSED( self ), PyObject *args )
25 {
26  printf( "in pl_Pltk_init()\n" );
27  long x = 0;
28 
29  TRY( PyArg_ParseTuple( args, "l", &x ) );
30 
31  if ( !x )
32  {
33  printf( "Something went wrong...\n" );
34  Py_INCREF( Py_None );
35  return Py_None;
36  }
37 
38  Tcl_Interp *interp = (Tcl_Interp *) x;
39 
40  printf( "Tcl_Interp * = %ld \n", x );
41 
42  if ( Pltk_Init( interp ) == TCL_ERROR )
43  {
44  printf( "Initizlization of Pltk Tcl extension failed!\n" );
45  return NULL;
46  }
47 
48  printf( "plframe has been installed into the Tcl interpreter.\n" );
49 
50  Py_INCREF( Py_None );
51  return Py_None;
52 }
53 
54 #endif
55 
56 //--------------------------------------------------------------------------
57 
58 static PyMethodDef plplot_widget_methods[] = {
59 #ifdef ENABLE_tk
60  { "Pltk_init", pl_Pltk_init, METH_VARARGS, doc_Pltk_init },
61 #endif
62 
63  { NULL, NULL, 0, NULL }
64 };
65 
66 PLDLLIMPEXP_PLPLOT_WIDGETMODULE void initplplot_widget( void )
67 {
68  PyObject *m;
69  PyObject *d;
70 
71  import_array();
72 
73  // Create the module and add the functions
74  m = Py_InitModule( "plplot_widget", plplot_widget_methods );
75  d = PyModule_GetDict( m );
76 
77  // Check for errors
78  if ( PyErr_Occurred() )
79  Py_FatalError( "plplot_widget module initialization failed" );
80 }