]> Dogcows Code - chaz/openbox/blob - src/config.cc
rm debug print
[chaz/openbox] / src / config.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #include "config.h"
4
5 #include "config.hh"
6
7 extern "C" {
8 #include <Python.h>
9 }
10
11 namespace ob {
12
13 static PyObject *obdict = NULL;
14
15 bool python_get_long(const char *name, long *value)
16 {
17 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
18 if (!(val && PyInt_Check(val))) return false;
19
20 *value = PyInt_AsLong(val);
21 return true;
22 }
23
24 bool python_get_string(const char *name, otk::ustring *value)
25 {
26 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
27 if (!(val && PyString_Check(val))) return false;
28
29 *value = PyString_AsString(val);
30 return true;
31 }
32
33 bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value)
34 {
35 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
36 if (!(val && PyList_Check(val))) return false;
37
38 value->clear();
39
40 for (int i = 0, end = PyList_Size(val); i < end; ++i) {
41 PyObject *str = PyList_GetItem(val, i);
42 if (PyString_Check(str))
43 value->push_back(PyString_AsString(str));
44 }
45 return true;
46 }
47
48 Config::Config()
49 {
50 PyRun_SimpleString("import config;");
51 // set up access to the python global variables
52 PyObject *obmodule = PyImport_AddModule("config");
53 obdict = PyModule_GetDict(obmodule);
54
55 std::vector<otk::ustring> names;
56 python_get_stringlist("DESKTOP_NAMES", &names);
57
58 python_get_string("THEME", &theme);
59
60 if (!python_get_string("TITLEBAR_LAYOUT", &titlebar_layout))
61 titlebar_layout = "NTIMC";
62
63 if (!python_get_long("DOUBLE_CLICK_DELAY", &double_click_delay))
64 double_click_delay = 300;
65 if (!python_get_long("DRAG_THRESHOLD", &drag_threshold))
66 drag_threshold = 3;
67 if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&num_desktops))
68 num_desktops = 1;
69 }
70
71 }
This page took 0.036492 seconds and 4 git commands to generate.