1 | #ifdef NANOGUI_PYTHON |
2 | |
3 | #include "python.h" |
4 | |
5 | DECLARE_WIDGET(Label); |
6 | DECLARE_WIDGET(Popup); |
7 | DECLARE_WIDGET(MessageDialog); |
8 | DECLARE_WIDGET(VScrollPanel); |
9 | DECLARE_WIDGET(ComboBox); |
10 | DECLARE_WIDGET(ProgressBar); |
11 | DECLARE_WIDGET(Slider); |
12 | |
13 | void register_basics(py::module &m) { |
14 | py::class_<Label, Widget, ref<Label>, PyLabel>(m, "Label" , D(Label)) |
15 | .def(py::init<Widget *, const std::string &, const std::string &, int>(), |
16 | py::arg("parent" ), py::arg("caption" ), py::arg("font" ) = std::string("sans" ), |
17 | py::arg("fontSize" ) = -1, |
18 | D(Label, Label)) |
19 | .def("caption" , &Label::caption, D(Label, caption)) |
20 | .def("setCaption" , &Label::setCaption, D(Label, setCaption)) |
21 | .def("font" , &Label::font, D(Label, font)) |
22 | .def("setFont" , &Label::setFont, D(Label, setFont)) |
23 | .def("color" , &Label::color, D(Label, color)) |
24 | .def("setColor" , &Label::setColor, D(Label, setColor)); |
25 | |
26 | |
27 | py::class_<Popup, Window, ref<Popup>, PyPopup> (m, "Popup" , D(Popup)); |
28 | popup |
29 | .def(py::init<Widget *, Window *>(), py::arg("parent" ), py::arg("parentWindow" ), D(Popup, Popup)) |
30 | .def("anchorPos" , &Popup::anchorPos, D(Popup, anchorPos)) |
31 | .def("setAnchorPos" , &Popup::setAnchorPos, D(Popup, setAnchorPos)) |
32 | .def("anchorHeight" , &Popup::anchorHeight, D(Popup, anchorHeight)) |
33 | .def("setAnchorHeight" , &Popup::setAnchorHeight, D(Popup, setAnchorHeight)) |
34 | .def("parentWindow" , (Window*(Popup::*)(void)) &Popup::parentWindow, D(Popup, parentWindow)) |
35 | .def("side" , &Popup::side, D(Popup, side)) |
36 | .def("setSide" , &Popup::setSide, D(Popup, setSide)); |
37 | |
38 | py::enum_<Popup::Side>(popup, "Side" , D(Popup, Side)) |
39 | .value("Left" , Popup::Side::Left) |
40 | .value("Right" , Popup::Side::Right) |
41 | .export_values(); |
42 | |
43 | py::class_<MessageDialog, Window, ref<MessageDialog>, PyMessageDialog> mdlg(m, "MessageDialog" , D(MessageDialog)); |
44 | mdlg |
45 | .def(py::init<Widget *, MessageDialog::Type, const std::string&, |
46 | const std::string&, const std::string&, const std::string&, bool>(), |
47 | py::arg("parent" ), py::arg("type" ), py::arg("title" ) = std::string("Untitled" ), |
48 | py::arg("message" ) = std::string("Message" ), py::arg("buttonText" ) = std::string("OK" ), |
49 | py::arg("altButtonText" ) = std::string("Cancel" ), py::arg("altButton" ) = false, |
50 | D(MessageDialog, MessageDialog)) |
51 | .def("messageLabel" , (Label * (MessageDialog::*)()) &MessageDialog::messageLabel, D(MessageDialog, messageLabel)) |
52 | .def("callback" , &MessageDialog::callback, D(MessageDialog, callback)) |
53 | .def("setCallback" , &MessageDialog::setCallback, D(MessageDialog, setCallback)); |
54 | |
55 | py::enum_<MessageDialog::Type>(mdlg, "Type" , D(MessageDialog, Type)) |
56 | .value("Information" , MessageDialog::Type::Information) |
57 | .value("Question" , MessageDialog::Type::Question) |
58 | .value("Warning" , MessageDialog::Type::Warning); |
59 | |
60 | py::class_<VScrollPanel, Widget, ref<VScrollPanel>, PyVScrollPanel>(m, "VScrollPanel" , D(VScrollPanel)) |
61 | .def(py::init<Widget *>(), py::arg("parent" ), D(VScrollPanel, VScrollPanel)) |
62 | .def("scroll" , &VScrollPanel::scroll, D(VScrollPanel, scroll)) |
63 | .def("setScroll" , &VScrollPanel::setScroll, D(VScrollPanel, setScroll)); |
64 | |
65 | py::class_<ComboBox, Widget, ref<ComboBox>, PyComboBox>(m, "ComboBox" , D(ComboBox)) |
66 | .def(py::init<Widget *>(), py::arg("parent" ), D(ComboBox, ComboBox)) |
67 | .def(py::init<Widget *, const std::vector<std::string> &>(), |
68 | py::arg("parent" ), py::arg("items" )/*, D(ComboBox, ComboBox, 2)*/) |
69 | .def(py::init<Widget *, const std::vector<std::string> &, |
70 | const std::vector<std::string> &>(), |
71 | py::arg("parent" ), py::arg("items" ), py::arg("itemsShort" )/* ,D(ComboBox, ComboBox, 3)*/) |
72 | .def("callback" , &ComboBox::callback, D(ComboBox, callback)) |
73 | .def("setCallback" , &ComboBox::setCallback, D(ComboBox, setCallback)) |
74 | .def("selectedIndex" , &ComboBox::selectedIndex, D(ComboBox, selectedIndex)) |
75 | .def("setSelectedIndex" , &ComboBox::setSelectedIndex, D(ComboBox, setSelectedIndex)) |
76 | .def("setItems" , (void(ComboBox::*)(const std::vector<std::string>&)) &ComboBox::setItems, D(ComboBox, setItems)) |
77 | .def("setItems" , (void(ComboBox::*)(const std::vector<std::string>&, |
78 | const std::vector<std::string>&)) &ComboBox::setItems/*, D(ComboBox, setItems, 2)*/) |
79 | .def("items" , &ComboBox::items, D(ComboBox, items)) |
80 | .def("itemsShort" , &ComboBox::itemsShort, D(ComboBox, itemsShort)); |
81 | |
82 | py::class_<ProgressBar, Widget, ref<ProgressBar>, PyProgressBar>(m, "ProgressBar" , D(ProgressBar)) |
83 | .def(py::init<Widget *>(), py::arg("parent" ), D(ProgressBar, ProgressBar)) |
84 | .def("value" , &ProgressBar::value, D(ProgressBar, value)) |
85 | .def("setValue" , &ProgressBar::setValue, D(ProgressBar, setValue)); |
86 | |
87 | py::class_<Slider, Widget, ref<Slider>, PySlider>(m, "Slider" , D(Slider)) |
88 | .def(py::init<Widget *>(), py::arg("parent" ), D(Slider, Slider)) |
89 | .def("value" , &Slider::value, D(Slider, value)) |
90 | .def("setValue" , &Slider::setValue, D(Slider, setValue)) |
91 | .def("highlightColor" , &Slider::highlightColor, D(Slider, highlightColor)) |
92 | .def("setHighlightColor" , &Slider::setHighlightColor, D(Slider, setHighlightColor)) |
93 | .def("range" , &Slider::range, D(Slider, range)) |
94 | .def("setRange" , &Slider::setRange, D(Slider, setRange)) |
95 | .def("highlightedRange" , &Slider::highlightedRange, D(Slider, highlightedRange)) |
96 | .def("setHighlightedRange" , &Slider::setHighlightedRange, D(Slider, setHighlightedRange)) |
97 | .def("setCallback" , &Slider::setCallback, D(Slider, setCallback)) |
98 | .def("callback" , &Slider::callback, D(Slider, callback)) |
99 | .def("setFinalCallback" , &Slider::setFinalCallback, D(Slider, setFinalCallback)) |
100 | .def("finalCallback" , &Slider::finalCallback, D(Slider, finalCallback)); |
101 | } |
102 | #endif |
103 | |