]> Dogcows Code - chaz/openbox/blob - src/python.cc
dont wrap pointerassassin
[chaz/openbox] / src / python.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #include "python.hh"
4 #include "openbox.hh"
5 #include "actions.hh"
6 #include "python.hh"
7 #include "bindings.hh"
8 #include "otk/display.hh"
9 #include "otk/util.hh"
10
11 extern "C" {
12 #include <Python.h>
13 }
14
15 namespace ob {
16
17 void python_init(char *argv0)
18 {
19 // start the python engine
20 Py_SetProgramName(argv0);
21 Py_Initialize();
22 // prepend the openbox directories for python scripts to the sys path
23 PyRun_SimpleString("import sys");
24 PyRun_SimpleString("sys.path.insert(0, '" SCRIPTDIR "')");
25 PyRun_SimpleString(const_cast<char*>(("sys.path.insert(0, '" +
26 otk::expandTilde("~/.openbox/python") +
27 "')").c_str()));
28 }
29
30 void python_destroy()
31 {
32 Py_Finalize();
33 }
34
35 bool python_exec(const std::string &path)
36 {
37 FILE *rcpyfd = fopen(path.c_str(), "r");
38 if (!rcpyfd) {
39 printf("Failed to load python file %s\n", path.c_str());
40 return false;
41 }
42 PyRun_SimpleFile(rcpyfd, const_cast<char*>(path.c_str()));
43 fclose(rcpyfd);
44 return true;
45 }
46
47 }
This page took 0.03764 seconds and 4 git commands to generate.