1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
15 static PyObject *obdict = NULL;
17 bool python_get_long(const char *name, long *value)
19 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
20 if (!(val && PyInt_Check(val))) return false;
22 *value = PyInt_AsLong(val);
26 bool python_get_string(const char *name, otk::ustring *value)
28 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
29 if (!(val && PyString_Check(val))) return false;
31 std::string temp(PyString_AsString(val), PyString_Size(val));
36 bool python_get_stringlist(const char *name, std::vector<otk::ustring> *value)
38 PyObject *val = PyDict_GetItemString(obdict, const_cast<char*>(name));
39 if (!(val && PyList_Check(val))) return false;
43 for (int i = 0, end = PyList_Size(val); i < end; ++i) {
44 PyObject *str = PyList_GetItem(val, i);
45 if (PyString_Check(str))
46 value->push_back(PyString_AsString(str));
53 PyRun_SimpleString("import config;");
54 // set up access to the python global variables
55 PyObject *obmodule = PyImport_AddModule("config");
56 obdict = PyModule_GetDict(obmodule);
58 std::vector<otk::ustring> names;
59 python_get_stringlist("DESKTOP_NAMES", &names);
61 python_get_string("THEME", &theme);
63 if (!python_get_string("TITLEBAR_LAYOUT", &titlebar_layout))
64 titlebar_layout = "NTIMC";
66 if (!python_get_long("DOUBLE_CLICK_DELAY", &double_click_delay))
67 double_click_delay = 300;
68 if (!python_get_long("DRAG_THRESHOLD", &drag_threshold))
70 if (!python_get_long("NUMBER_OF_DESKTOPS", (long*)&num_desktops))
75 if (python_get_string("DEFAULT_ICON", &s) && s.bytes() > 2 &&
76 python_get_long("DEFAULT_ICON_WIDTH", &w) &&
77 python_get_long("DEFAULT_ICON_HEIGHT", &h) &&
78 (unsigned)(w * h) == s.bytes() / sizeof(unsigned long)) {
79 default_icon = new unsigned long[s.bytes() / sizeof(unsigned long) + 2];
82 memcpy(default_icon + 2, s.data(), s.bytes());
87 icon_length = s.bytes();
92 if (default_icon) delete [] default_icon;