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 
register_textbox(py::module & m)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("callback", &TextBox::callback, D(TextBox, callback))
34         .def("setCallback", &TextBox::setCallback, D(TextBox, setCallback));
35 
36     py::enum_<TextBox::Alignment>(tbox, "Alignment", D(TextBox, Alignment))
37         .value("Left", TextBox::Alignment::Left)
38         .value("Center", TextBox::Alignment::Center)
39         .value("Right", TextBox::Alignment::Right);
40 
41     py::class_<Int64Box, TextBox, ref<Int64Box>, PyInt64Box>(m, "IntBox", D(IntBox))
42         .def(py::init<Widget *, int64_t>(), py::arg("parent"), py::arg("value") = (int64_t) 0, D(IntBox, IntBox))
43         .def("value", &Int64Box::value, D(IntBox, value))
44         .def("setValue", (void (Int64Box::*)(int64_t)) &Int64Box::setValue, D(IntBox, setValue))
45         .def("setCallback", (void (Int64Box::*)(const std::function<void(int64_t)>&))
46                 &Int64Box::setCallback, D(IntBox, setCallback))
47         .def("setValueIncrement", &Int64Box::setValueIncrement, D(IntBox, setValueIncrement))
48         .def("setMinValue", &Int64Box::setMinValue, D(IntBox, setMinValue))
49         .def("setMaxValue", &Int64Box::setMaxValue, D(IntBox, setMaxValue))
50         .def("setMinValue", &Int64Box::setMinMaxValues, D(IntBox, setMinMaxValues));
51 
52     py::class_<DoubleBox, TextBox, ref<DoubleBox>, PyDoubleBox>(m, "FloatBox", D(FloatBox))
53         .def(py::init<Widget *, double>(), py::arg("parent"), py::arg("value") = 0.0)
54         .def("value", &DoubleBox::value, D(FloatBox, value))
55         .def("setValue", (void (DoubleBox::*)(double)) &DoubleBox::setValue, D(FloatBox, setValue))
56         .def("setCallback", (void (DoubleBox::*)(const std::function<void(double)>&))
57                 &DoubleBox::setCallback, D(FloatBox, setCallback))
58         .def("setValueIncrement", &DoubleBox::setValueIncrement, D(FloatBox, setValueIncrement))
59         .def("setMinValue", &DoubleBox::setMinValue, D(FloatBox, setMinValue))
60         .def("setMaxValue", &DoubleBox::setMaxValue, D(FloatBox, setMaxValue))
61         .def("setMinValue", &DoubleBox::setMinMaxValues, D(FloatBox, setMinMaxValues));
62 }
63 
64 #endif
65