From 6dc0946ce4042ab720fad6de75cfb68d703fb8d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 May 2025 19:25:50 +0200 Subject: [PATCH] python: make it possible to specify application Configuration as kwargs. So it can be done in a single expression, like in C++. Originally I thought I'd make the Application constructor itself take kwargs, combined from Configuration and GLConfiguration, but this would be annoying to implement and annoying to use because it wouldn't be possible to perform the usual pattern of try_create(), fail, set different parameter, create(). --- src/python/magnum/platform/application.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/python/magnum/platform/application.h b/src/python/magnum/platform/application.h index 55a8a80..2a9f386 100644 --- a/src/python/magnum/platform/application.h +++ b/src/python/magnum/platform/application.h @@ -38,7 +38,19 @@ namespace magnum { namespace platform { template void configuration(py::class_& c) { c - .def(py::init()) + .def(py::init([](const std::string& title, const Vector2i& size, typename T::WindowFlag windowFlags) { + return T{} + .setTitle(title) + .setSize(size) + .setWindowFlags(windowFlags); + }), "Constructor", + #if PYBIND11_VERSION_MAJOR*100 + PYBIND11_VERSION_MINOR >= 206 + py::kw_only{}, /* new in pybind11 2.6 */ + #endif + /** @todo drop std::string in favor of our own string caster */ + py::arg("title") = std::string{T{}.title()}, + py::arg("size") = T{}.size(), + py::arg("window_flags") = typename T::WindowFlag(typename std::underlying_type::type(T{}.windowFlags()))) .def_property("title", /** @todo drop std::string in favor of our own string caster */ [](T& self) -> std::string { @@ -64,7 +76,7 @@ template void configuration(py::class_& c) { template void application(py::class_& c) { py::class_ glConfiguration{c, "GLConfiguration", "OpenGL context configuration"}; glConfiguration - .def(py::init()); + .def(py::init(), "Constructor"); /** @todo others */ c