1 | #ifdef NANOGUI_PYTHON |
2 | |
3 | #include "python.h" |
4 | |
5 | typedef FloatBox<double> DoubleBox; |
6 | typedef IntBox<int64_t> Int64Box; |
7 | |
8 | DECLARE_WIDGET(TextBox); |
9 | DECLARE_WIDGET(DoubleBox); |
10 | DECLARE_WIDGET(Int64Box); |
11 | |
12 | void register_textbox(py::module &m) { |
13 | py::class_<TextBox, Widget, ref<TextBox>, PyTextBox> tbox(m, "TextBox" , D(TextBox)); |
14 | tbox |
15 | .def(py::init<Widget *, const std::string &>(), py::arg("parent" ), |
16 | py::arg("value" ) = std::string("Untitled" ), D(TextBox, TextBox)) |
17 | .def("editable" , &TextBox::editable, D(TextBox, editable)) |
18 | .def("setEditable" , &TextBox::setEditable, D(TextBox, setEditable)) |
19 | .def("spinnable" , &TextBox::spinnable, D(TextBox, spinnable)) |
20 | .def("setSpinnable" , &TextBox::setSpinnable, D(TextBox, setSpinnable)) |
21 | .def("value" , &TextBox::value, D(TextBox, value)) |
22 | .def("setValue" , &TextBox::setValue, D(TextBox, setValue)) |
23 | .def("defaultValue" , &TextBox::defaultValue, D(TextBox, defaultValue)) |
24 | .def("setDefaultValue" , &TextBox::setDefaultValue, D(TextBox, setDefaultValue)) |
25 | .def("alignment" , &TextBox::alignment, D(TextBox, alignment)) |
26 | .def("setAlignment" , &TextBox::setAlignment, D(TextBox, setAlignment)) |
27 | .def("units" , &TextBox::units, D(TextBox, units)) |
28 | .def("setUnits" , &TextBox::setUnits, D(TextBox, setUnits)) |
29 | .def("unitsImage" , &TextBox::unitsImage, D(TextBox, unitsImage)) |
30 | .def("setUnitsImage" , &TextBox::setUnitsImage, D(TextBox, setUnitsImage)) |
31 | .def("format" , &TextBox::format, D(TextBox, format)) |
32 | .def("setFormat" , &TextBox::setFormat, D(TextBox, setFormat)) |
33 | .def("placeholder" , &TextBox::placeholder, D(TextBox, placeholder)) |
34 | .def("setPlaceholder" , &TextBox::setPlaceholder, D(TextBox, setPlaceholder)) |
35 | .def("callback" , &TextBox::callback, D(TextBox, callback)) |
36 | .def("setCallback" , &TextBox::setCallback, D(TextBox, setCallback)); |
37 | |
38 | py::enum_<TextBox::Alignment>(tbox, "Alignment" , D(TextBox, Alignment)) |
39 | .value("Left" , TextBox::Alignment::Left) |
40 | .value("Center" , TextBox::Alignment::Center) |
41 | .value("Right" , TextBox::Alignment::Right); |
42 | |
43 | py::class_<Int64Box, TextBox, ref<Int64Box>, PyInt64Box>(m, "IntBox" , D(IntBox)) |
44 | .def(py::init<Widget *, int64_t>(), py::arg("parent" ), py::arg("value" ) = (int64_t) 0, D(IntBox, IntBox)) |
45 | .def("value" , &Int64Box::value, D(IntBox, value)) |
46 | .def("setValue" , (void (Int64Box::*)(int64_t)) &Int64Box::setValue, D(IntBox, setValue)) |
47 | .def("setCallback" , (void (Int64Box::*)(const std::function<void(int64_t)>&)) |
48 | &Int64Box::setCallback, D(IntBox, setCallback)) |
49 | .def("setValueIncrement" , &Int64Box::setValueIncrement, D(IntBox, setValueIncrement)) |
50 | .def("setMinValue" , &Int64Box::setMinValue, D(IntBox, setMinValue)) |
51 | .def("setMaxValue" , &Int64Box::setMaxValue, D(IntBox, setMaxValue)) |
52 | .def("setMinValue" , &Int64Box::setMinMaxValues, D(IntBox, setMinMaxValues)); |
53 | |
54 | py::class_<DoubleBox, TextBox, ref<DoubleBox>, PyDoubleBox>(m, "FloatBox" , D(FloatBox)) |
55 | .def(py::init<Widget *, double>(), py::arg("parent" ), py::arg("value" ) = 0.0) |
56 | .def("value" , &DoubleBox::value, D(FloatBox, value)) |
57 | .def("setValue" , (void (DoubleBox::*)(double)) &DoubleBox::setValue, D(FloatBox, setValue)) |
58 | .def("setCallback" , (void (DoubleBox::*)(const std::function<void(double)>&)) |
59 | &DoubleBox::setCallback, D(FloatBox, setCallback)) |
60 | .def("setValueIncrement" , &DoubleBox::setValueIncrement, D(FloatBox, setValueIncrement)) |
61 | .def("setMinValue" , &DoubleBox::setMinValue, D(FloatBox, setMinValue)) |
62 | .def("setMaxValue" , &DoubleBox::setMaxValue, D(FloatBox, setMaxValue)) |
63 | .def("setMinValue" , &DoubleBox::setMinMaxValues, D(FloatBox, setMinMaxValues)); |
64 | } |
65 | |
66 | #endif |
67 | |