1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
8 #include "otk/display.hh"
15 #define _(str) gettext(str)
20 void python_init(char *argv0)
22 // start the python engine
23 Py_SetProgramName(argv0);
25 // prepend the openbox directories for python scripts to the sys path
26 PyRun_SimpleString("import sys");
27 PyRun_SimpleString("sys.path.insert(0, '" SCRIPTDIR "')");
28 PyRun_SimpleString(const_cast<char*>(("sys.path.insert(0, '" +
29 otk::expandTilde("~/.openbox/python") +
38 int python_exec(const std::string &path)
40 FILE *rcpyfd = fopen(path.c_str(), "r");
42 fprintf(stderr, _("Unabled to open python file %s\n"), path.c_str());
46 //PyRun_SimpleFile(rcpyfd, const_cast<char*>(path.c_str()));
48 PyObject *module = PyImport_AddModule("__main__");
50 PyObject *dict = PyModule_GetDict(module);
52 PyObject *result = PyRun_File(rcpyfd, const_cast<char*>(path.c_str()),
53 Py_file_input, dict, dict);
54 int ret = result == NULL ? 2 : 0;