1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "../src/kzsettings.h"
namespace py = pybind11;
using namespace pybind11::literals;
class KzPySettings {
KaZoe::KzSettings m_settings;
public:
KzPySettings();
std::string __repr__();
static void add_python_binding(pybind11::module &m);
KzSettingValue get(std::string key, std::string category, KzSettingValue def);
KzSettingValue set(std::string key, KzSettingValue value, std::string category);
};
KzPySettings::KzPySettings() {
py::module sys = py::module::import("sys");
py::list argv = sys.attr("argv");
m_settings.setId(argv[0].cast<std::string>());
}
KzSettingValue KzPySettings::get(std::string key, std::string category, KzSettingValue def) {
return m_settings.get(key, category, def);
}
KzSettingValue KzPySettings::set(std::string key, KzSettingValue value, std::string category) {
return m_settings.set(key, value, category);
}
std::string KzPySettings::__repr__() {
std::string result = "KaZoeSettings";
return result;
}
void KzPySettings::add_python_binding(pybind11::module &m)
{
py::class_<KzPySettings>(m, "KzSettings")
.def(py::init<>())
.def("get", [] (KzPySettings &m, std::string key, std::string category = "", KzSettingValue def = KzSettingValue()) {
return m.get(key, category, def);
},
py::arg("key"),
py::arg("category") = "",
py::arg("default") = KzSettingValue())
.def("set", [] (KzPySettings &m, std::string key, KzSettingValue value, std::string category = "") {
return m.set(key, value, category);
},
py::arg("key"),
py::arg("value"),
py::arg("category") = "")
.def("__repr__", &KzPySettings::__repr__);
}
PYBIND11_MODULE(KzSettings, m) {
m.doc() = R"pbdoc(
Python bindings for KzSettings
)pbdoc";
KzPySettings::add_python_binding(m);
}
|