1#ifdef NANOGUI_PYTHON
2
3#include "python.h"
4
5DECLARE_WIDGET(Widget);
6DECLARE_SCREEN(Screen);
7DECLARE_WIDGET(Window);
8
9void register_widget(py::module &m) {
10 py::class_<Widget, ref<Widget>, PyWidget>(m, "Widget", D(Widget))
11 .def(py::init<Widget *>(), D(Widget, Widget))
12 .def("parent", (Widget *(Widget::*)(void)) &Widget::parent, D(Widget, parent))
13 .def("setParent", &Widget::setParent, D(Widget, setParent))
14 .def("layout", (Layout *(Widget::*)(void)) &Widget::layout, D(Widget, layout))
15 .def("setLayout", &Widget::setLayout, D(Widget, setLayout))
16 .def("theme", (Theme *(Widget::*)(void)) &Widget::theme, D(Widget, theme))
17 .def("setTheme", &Widget::setTheme, D(Widget, setTheme))
18 .def("position", &Widget::position, D(Widget, position))
19 .def("setPosition", &Widget::setPosition, D(Widget, setPosition))
20 .def("absolutePosition", &Widget::absolutePosition, D(Widget, absolutePosition))
21 .def("size", &Widget::size, D(Widget, size))
22 .def("setSize", &Widget::setSize, D(Widget, setSize))
23 .def("width", &Widget::width, D(Widget, width))
24 .def("setWidth", &Widget::setWidth, D(Widget, setWidth))
25 .def("height", &Widget::height, D(Widget, height))
26 .def("setHeight", &Widget::setHeight, D(Widget, setHeight))
27 .def("fixedSize", &Widget::fixedSize, D(Widget, fixedSize))
28 .def("setFixedSize", &Widget::setFixedSize, D(Widget, setFixedSize))
29 .def("fixedWidth", &Widget::fixedWidth, D(Widget, fixedWidth))
30 .def("setFixedWidth", &Widget::setFixedWidth, D(Widget, setFixedWidth))
31 .def("fixedHeight", &Widget::fixedHeight, D(Widget, fixedHeight))
32 .def("setFixedHeight", &Widget::setFixedHeight, D(Widget, setFixedHeight))
33 .def("visible", &Widget::visible, D(Widget, visible))
34 .def("setVisible", &Widget::setVisible, D(Widget, setVisible))
35 .def("visibleRecursive", &Widget::visibleRecursive, D(Widget, visibleRecursive))
36 .def("children", (std::vector<Widget *>&(Widget::*)(void)) &Widget::children,
37 D(Widget, children), py::return_value_policy::reference)
38 .def("addChild", (void (Widget::*) (int, Widget *)) &Widget::addChild, D(Widget, addChild))
39 .def("addChild", (void (Widget::*) (Widget *)) &Widget::addChild, D(Widget, addChild, 2))
40 .def("childCount", &Widget::childCount, D(Widget, childCount))
41 .def("__len__", &Widget::childCount, D(Widget, childCount))
42 .def("__iter__", [](const Widget &w) {
43 return py::make_iterator(w.children().begin(), w.children().end());
44 }, py::keep_alive<0, 1>())
45 .def("childIndex", &Widget::childIndex, D(Widget, childIndex))
46 .def("__getitem__", (Widget* (Widget::*)(int)) &Widget::childAt, D(Widget, childAt))
47 .def("removeChild", (void(Widget::*)(int)) &Widget::removeChild, D(Widget, removeChild))
48 .def("removeChild", (void(Widget::*)(const Widget *)) &Widget::removeChild, D(Widget, removeChild, 2))
49 .def("__delitem__", (void(Widget::*)(int)) &Widget::removeChild, D(Widget, removeChild, 2))
50 .def("window", &Widget::window, D(Widget, window))
51 .def("setId", &Widget::setId, D(Widget, setId))
52 .def("id", &Widget::id, D(Widget, id))
53 .def("enabled", &Widget::enabled, D(Widget, enabled))
54 .def("setEnabled", &Widget::setEnabled, D(Widget, setEnabled))
55 .def("focused", &Widget::focused, D(Widget, focused))
56 .def("setFocused", &Widget::setFocused, D(Widget, setFocused))
57 .def("requestFocus", &Widget::requestFocus, D(Widget, requestFocus))
58 .def("tooltip", &Widget::tooltip, D(Widget, tooltip))
59 .def("setTooltip", &Widget::setTooltip, D(Widget, setTooltip))
60 .def("fontSize", &Widget::fontSize, D(Widget, fontSize))
61 .def("setFontSize", &Widget::setFontSize, D(Widget, setFontSize))
62 .def("hasFontSize", &Widget::hasFontSize, D(Widget, hasFontSize))
63 .def("cursor", &Widget::cursor, D(Widget, cursor))
64 .def("setCursor", &Widget::setCursor, D(Widget, setCursor))
65 .def("findWidget", &Widget::findWidget, D(Widget, findWidget))
66 .def("contains", &Widget::contains, D(Widget, contains))
67 .def("mouseButtonEvent", &Widget::mouseButtonEvent, py::arg("p"), py::arg("button"),
68 py::arg("down"), py::arg("modifiers"), D(Widget, mouseButtonEvent))
69 .def("mouseMotionEvent", &Widget::mouseMotionEvent, py::arg("p"), py::arg("rel"),
70 py::arg("button"), py::arg("modifiers"), D(Widget, mouseMotionEvent))
71 .def("mouseDragEvent", &Widget::mouseDragEvent, py::arg("p"), py::arg("rel"),
72 py::arg("button"), py::arg("modifiers"), D(Widget, mouseDragEvent))
73 .def("mouseEnterEvent", &Widget::mouseEnterEvent, py::arg("p"), py::arg("enter"),
74 D(Widget, mouseEnterEvent))
75 .def("scrollEvent", &Widget::scrollEvent, py::arg("p"), py::arg("rel"),
76 D(Widget, scrollEvent))
77 .def("focusEvent", &Widget::focusEvent, py::arg("focused"), D(Widget, focusEvent))
78 .def("keyboardEvent", &Widget::keyboardEvent, py::arg("key"), py::arg("scancode"),
79 py::arg("action"), py::arg("modifiers"), D(Widget, keyboardEvent))
80 .def("keyboardCharacterEvent", &Widget::keyboardCharacterEvent,
81 D(Widget, keyboardCharacterEvent))
82 .def("preferredSize", &Widget::preferredSize, D(Widget, preferredSize))
83 .def("performLayout", &Widget::performLayout, D(Widget, performLayout))
84 .def("draw", &Widget::draw, D(Widget, draw));
85
86 py::class_<Window, Widget, ref<Window>, PyWindow>(m, "Window", D(Window))
87 .def(py::init<Widget *, const std::string>(), py::arg("parent"),
88 py::arg("title") = std::string("Untitled"), D(Window, Window))
89 .def("title", &Window::title, D(Window, title))
90 .def("setTitle", &Window::setTitle, D(Window, setTitle))
91 .def("modal", &Window::modal, D(Window, modal))
92 .def("setModal", &Window::setModal, D(Window, setModal))
93 .def("dispose", &Window::dispose, D(Window, dispose))
94 .def("buttonPanel", &Window::buttonPanel, D(Window, buttonPanel))
95 .def("center", &Window::center, D(Window, center));
96
97 py::class_<Screen, Widget, ref<Screen>, PyScreen>(m, "Screen", D(Screen))
98 .def(py::init<const Vector2i &, const std::string &, bool, bool, int, int, int, int, int, unsigned int, unsigned int>(),
99 py::arg("size"), py::arg("caption"), py::arg("resizable") = true, py::arg("fullscreen") = false,
100 py::arg("colorBits") = 8, py::arg("alphaBits") = 8, py::arg("depthBits") = 24, py::arg("stencilBits") = 8,
101 py::arg("nSamples") = 0, py::arg("glMajor") = 3, py::arg("glMinor") = 3, D(Screen, Screen))
102 .def("caption", &Screen::caption, D(Screen, caption))
103 .def("setCaption", &Screen::setCaption, D(Screen, setCaption))
104 .def("background", &Screen::background, D(Screen, background))
105 .def("setBackground", &Screen::setBackground, D(Screen, setBackground))
106 .def("setVisible", &Screen::setVisible, D(Screen, setVisible))
107 .def("setSize", &Screen::setSize, D(Screen, setSize))
108 .def("performLayout", (void(Screen::*)(void)) &Screen::performLayout, D(Screen, performLayout))
109 .def("drawAll", &Screen::drawAll, D(Screen, drawAll))
110 .def("drawContents", &Screen::drawContents, D(Screen, drawContents))
111 .def("resizeEvent", &Screen::resizeEvent, py::arg("size"), D(Screen, resizeEvent))
112 .def("resizeCallback", &Screen::resizeCallback)
113 .def("setResizeCallback", &Screen::setResizeCallback)
114 .def("dropEvent", &Screen::dropEvent, D(Screen, dropEvent))
115 .def("mousePos", &Screen::mousePos, D(Screen, mousePos))
116 .def("pixelRatio", &Screen::pixelRatio, D(Screen, pixelRatio))
117 .def("glfwWindow", &Screen::glfwWindow, D(Screen, glfwWindow),
118 py::return_value_policy::reference)
119 .def("nvgContext", &Screen::nvgContext, D(Screen, nvgContext),
120 py::return_value_policy::reference);
121}
122#endif
123