1#ifdef NANOGUI_PYTHON
2
3#include "python.h"
4
5DECLARE_WIDGET(Button);
6DECLARE_WIDGET(ToolButton);
7DECLARE_WIDGET(PopupButton);
8DECLARE_WIDGET(CheckBox);
9
10void register_button(py::module &m) {
11 py::class_<Button, Widget, ref<Button>, PyButton> button(m, "Button", D(Button));
12 button
13 .def(py::init<Widget *, const std::string &, int>(),
14 py::arg("parent"), py::arg("caption") = std::string("Untitled"), py::arg("icon") = 0, D(Button, Button))
15 .def("caption", &Button::caption, D(Button, caption))
16 .def("setCaption", &Button::setCaption, D(Button, setCaption))
17 .def("backgroundColor", &Button::backgroundColor, D(Button, backgroundColor))
18 .def("setBackgroundColor", &Button::setBackgroundColor, D(Button, setBackgroundColor))
19 .def("textColor", &Button::textColor, D(Button, textColor))
20 .def("setTextColor", &Button::setTextColor, D(Button, setTextColor))
21 .def("icon", &Button::icon, D(Button, icon))
22 .def("setIcon", &Button::setIcon, D(Button, setIcon))
23 .def("flags", &Button::flags, D(Button, flags))
24 .def("setFlags", &Button::setFlags, D(Button, setFlags))
25 .def("iconPosition", &Button::iconPosition, D(Button, iconPosition))
26 .def("setIconPosition", &Button::setIconPosition, D(Button, setIconPosition))
27 .def("pushed", &Button::pushed, D(Button, pushed))
28 .def("setPushed", &Button::setPushed, D(Button, setPushed))
29 .def("callback", &Button::callback, D(Button, callback))
30 .def("setCallback", &Button::setCallback, D(Button, setCallback))
31 .def("changeCallback", &Button::changeCallback, D(Button, changeCallback))
32 .def("setChangeCallback", &Button::setChangeCallback, D(Button, setChangeCallback))
33 .def("buttonGroup", &Button::buttonGroup, D(Button, buttonGroup))
34 .def("setButtonGroup", &Button::setButtonGroup, D(Button, setButtonGroup));
35
36 py::enum_<Button::IconPosition>(button, "IconPosition", D(Button, IconPosition))
37 .value("Left", Button::IconPosition::Left)
38 .value("LeftCentered", Button::IconPosition::LeftCentered)
39 .value("RightCentered", Button::IconPosition::RightCentered)
40 .value("Right", Button::IconPosition::Right);
41
42 py::enum_<Button::Flags>(button, "Flags", D(Button, Flags))
43 .value("NormalButton", Button::Flags::NormalButton)
44 .value("RadioButton", Button::Flags::RadioButton)
45 .value("ToggleButton", Button::Flags::ToggleButton)
46 .value("PopupButton", Button::Flags::PopupButton);
47
48 py::class_<ToolButton, Button, ref<ToolButton>, PyToolButton>(m, "ToolButton", D(ToolButton))
49 .def(py::init<Widget *,int, const std::string &>(),
50 py::arg("parent"), py::arg("icon"), py::arg("caption") = std::string(""),
51 D(ToolButton, ToolButton));
52
53 py::class_<PopupButton, Button, ref<PopupButton>, PyPopupButton> popupBtn(m, "PopupButton", D(PopupButton));
54 popupBtn
55 .def(py::init<Widget *, const std::string&, int>(),
56 py::arg("parent"), py::arg("caption") = std::string("Untitled"),
57 py::arg("buttonIcon") = 0, D(PopupButton, PopupButton))
58 .def("popup", (Popup*(PopupButton::*)(void)) &PopupButton::popup, D(PopupButton, popup))
59 .def("chevronIcon", &PopupButton::chevronIcon, D(PopupButton, chevronIcon))
60 .def("setChevronIcon", &PopupButton::setChevronIcon, D(PopupButton, setChevronIcon))
61 .def("side", &PopupButton::side, D(PopupButton, side))
62 .def("setSide", &PopupButton::setSide, D(PopupButton, setSide));
63
64 py::class_<CheckBox, Widget, ref<CheckBox>, PyCheckBox>(m, "CheckBox", D(CheckBox))
65 .def(py::init<Widget *, const std::string &>(), py::arg("parent"),
66 py::arg("caption") = std::string("Untitled"),
67 D(CheckBox, CheckBox))
68 .def(py::init<Widget *, const std::string &, const std::function<void(bool)>&>(),
69 py::arg("parent"), py::arg("caption"), py::arg("callback"),
70 D(CheckBox, CheckBox))
71 .def("caption", &CheckBox::caption, D(CheckBox, caption))
72 .def("setCaption", &CheckBox::setCaption, D(CheckBox, setCaption))
73 .def("checked", &CheckBox::checked, D(CheckBox, checked))
74 .def("setChecked", &CheckBox::setChecked, D(CheckBox, setChecked))
75 .def("pushed", &CheckBox::pushed, D(CheckBox, pushed))
76 .def("setPushed", &CheckBox::setPushed, D(CheckBox, setPushed))
77 .def("callback", &CheckBox::callback, D(CheckBox, callback))
78 .def("setCallback", &CheckBox::setCallback, D(CheckBox, setCallback));
79}
80
81#endif
82