X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Fpython.cc;h=a99416ae83899bc72ec3e4ec118321dbf9e18273;hb=a5a712f9ae652e500c81b42db548d213bde4712e;hp=f95d4723772f0b89e4af3ad38a82cd26c1fcdea4;hpb=997f94cf8657201ea9d1f2497e4ec4f56342e22f;p=chaz%2Fopenbox diff --git a/src/python.cc b/src/python.cc index f95d4723..a99416ae 100644 --- a/src/python.cc +++ b/src/python.cc @@ -9,8 +9,9 @@ #include "otk/util.hh" extern "C" { -// The initializer in openbox_wrap.cc +// The initializer in openbox_wrap.cc / otk_wrap.cc extern void init_ob(void); +extern void init_otk(void); } namespace ob { @@ -23,17 +24,18 @@ void python_init(char *argv0) Py_SetProgramName(argv0); Py_Initialize(); // 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(("sys.path.append('" + + PyRun_SimpleString("sys.path.insert(0, '" SCRIPTDIR "')"); + PyRun_SimpleString(const_cast(("sys.path.insert(0, '" + otk::expandTilde("~/.openbox/python") + "')").c_str())); - PyRun_SimpleString("sys.path.append('" SCRIPTDIR "')"); - PyRun_SimpleString("import ob;"); + PyRun_SimpleString("import ob; import otk; import config;"); // set up convenience global variables PyRun_SimpleString("ob.openbox = ob.Openbox_instance()"); - PyRun_SimpleString("ob.display = ob.Display_instance()"); + PyRun_SimpleString("otk.display = otk.Display_instance()"); // set up access to the python global variables PyObject *obmodule = PyImport_AddModule("config"); @@ -42,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(path.c_str())); @@ -99,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)) { @@ -142,6 +152,21 @@ PyObject *kungrab() Py_INCREF(Py_None); return Py_None; } +PyObject *mgrab(int screen) +{ + if (!ob::openbox->bindings()->grabPointer(screen)) { + PyErr_SetString(PyExc_RuntimeError,"Unable to grab pointer."); + return NULL; + } + Py_INCREF(Py_None); return Py_None; +} + +PyObject *mungrab() +{ + ob::openbox->bindings()->ungrabPointer(); + Py_INCREF(Py_None); return Py_None; +} + PyObject *kbind(PyObject *keylist, ob::KeyContext::KC context, PyObject *func) { if (!PyCallable_Check(func)) { @@ -172,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)) { @@ -200,6 +226,7 @@ PyObject *kunbind(PyObject *keylist, PyObject *func) } Py_INCREF(Py_None); return Py_None; } +*/ void kunbind_all() {