]> Dogcows Code - chaz/openbox/blobdiff - src/python.cc
updated wrappers
[chaz/openbox] / src / python.cc
index 2e490d314e34d74e7e891001431b40819fbb40e1..040d70206d44f26c49103ae7f2c571ed3420d373 100644 (file)
@@ -6,12 +6,11 @@
 #include "python.hh"
 #include "bindings.hh"
 #include "otk/display.hh"
+#include "otk/util.hh"
 
 extern "C" {
 // The initializer in openbox_wrap.cc
 extern void init_openbox(void);
-// The initializer in otk_wrap.cc
-extern void init_otk(void);
 }
 
 namespace ob {
@@ -20,20 +19,22 @@ static PyObject *obdict = NULL;
 
 void python_init(char *argv0)
 {
+  // start the python engine
   Py_SetProgramName(argv0);
   Py_Initialize();
-  init_otk();
+  // initialize the C python module
   init_openbox();
-  PyRun_SimpleString("from _otk import *; from _openbox import *;");
+  // include the openbox directories for python scripts in the sys path
+  PyRun_SimpleString("import sys");
+  PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')");
+  PyRun_SimpleString(const_cast<char*>(((std::string)"sys.path.append('" +
+                                        otk::expandTilde("~/.openbox/python") +
+                                        "')").c_str()));
+  // import the otk and openbox modules into the main namespace
+  PyRun_SimpleString("from openbox import *;");
+  // set up convenience global variables
   PyRun_SimpleString("openbox = Openbox_instance()");
-  PyRun_SimpleString("display = OBDisplay_display()");
 
-  /* XXX
-     sys.path.append('stuff')
-     install the .py wrappers, and include their path with this, then import em
-     and ~/.openbox/python/ !!
-  */
-  
   // set up access to the python global variables
   PyObject *obmodule = PyImport_AddModule("__main__");
   obdict = PyModule_GetDict(obmodule);
@@ -143,6 +144,7 @@ PyObject *kbind(PyObject *keylist, ob::KeyContext context, PyObject *func)
     vectkeylist.push_back(PyString_AsString(str));
   }
 
+  (void)context; // XXX use this sometime!
   if (!ob::Openbox::instance->bindings()->addKey(vectkeylist, func)) {
     PyErr_SetString(PyExc_RuntimeError,"Unable to add binding.");
     return NULL;
This page took 0.022686 seconds and 4 git commands to generate.