]> Dogcows Code - chaz/openbox/blobdiff - src/python.cc
watch for bad actions and contexts
[chaz/openbox] / src / python.cc
index 2a9a912a2b583bd457b9000bd99078a528bb92a6..a99416ae83899bc72ec3e4ec118321dbf9e18273 100644 (file)
@@ -26,12 +26,12 @@ void python_init(char *argv0)
   // initialize the C python module
   init_otk();
   init_ob();
-  // include the openbox directories for python scripts in the sys path
+  // prepend the openbox directories for python scripts to the sys path
   PyRun_SimpleString("import sys");
-  PyRun_SimpleString(const_cast<char*>(("sys.path.append('" +
+  PyRun_SimpleString("sys.path.insert(0, '" SCRIPTDIR "')");
+  PyRun_SimpleString(const_cast<char*>(("sys.path.insert(0, '" +
                                         otk::expandTilde("~/.openbox/python") +
                                         "')").c_str()));
-  PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')");
   PyRun_SimpleString("import ob; import otk; import config;");
   // set up convenience global variables
   PyRun_SimpleString("ob.openbox = ob.Openbox_instance()");
@@ -44,14 +44,14 @@ void python_init(char *argv0)
 
 void python_destroy()
 {
-  Py_DECREF(obdict);
+  Py_Finalize();
 }
 
 bool python_exec(const std::string &path)
 {
   FILE *rcpyfd = fopen(path.c_str(), "r");
   if (!rcpyfd) {
-    printf("failed to load python file %s\n", path.c_str());
+    printf("Failed to load python file %s\n", path.c_str());
     return false;
   }
   PyRun_SimpleFile(rcpyfd, const_cast<char*>(path.c_str()));
@@ -101,6 +101,14 @@ PyObject *mbind(const std::string &button, ob::MouseContext::MC context,
     PyErr_SetString(PyExc_TypeError, "Invalid callback function.");
     return NULL;
   }
+  if(context < 0 || context >= MouseContext::NUM_MOUSE_CONTEXT) {
+    PyErr_SetString(PyExc_ValueError, "Invalid MouseContext");
+    return NULL;
+  }
+  if(action < 0 || action >= MouseAction::NUM_MOUSE_ACTION) {
+    PyErr_SetString(PyExc_ValueError, "Invalid MouseAction");
+    return NULL;
+  }
   
   if (!ob::openbox->bindings()->addButton(button, context,
                                           action, func)) {
@@ -189,6 +197,7 @@ PyObject *kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func)
   Py_INCREF(Py_None); return Py_None;
 }
 
+/*
 PyObject *kunbind(PyObject *keylist, PyObject *func)
 {
   if (!PyList_Check(keylist)) {
@@ -217,6 +226,7 @@ PyObject *kunbind(PyObject *keylist, PyObject *func)
   }
   Py_INCREF(Py_None); return Py_None;
 }
+*/
 
 void kunbind_all()
 {
This page took 0.024479 seconds and 4 git commands to generate.