From 650b958217271ae7e479fe5a774bcb680ec577d7 Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 12 Dec 2021 14:54:47 +0100 Subject: [PATCH] display: Add convenient shorthand for win.request_properties() Now instead of this: win.request_properties(WindowProperties(title="Test")) You can directly do this: win.request_properties(title="Test") --- panda/src/display/graphicsWindow.h | 6 +++++- panda/src/display/graphicsWindow_ext.cxx | 17 +++++++++++++++++ panda/src/display/graphicsWindow_ext.h | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/panda/src/display/graphicsWindow.h b/panda/src/display/graphicsWindow.h index 3424ec710f..12047ceea6 100644 --- a/panda/src/display/graphicsWindow.h +++ b/panda/src/display/graphicsWindow.h @@ -55,7 +55,9 @@ PUBLISHED: const WindowProperties get_requested_properties() const; void clear_rejected_properties(); WindowProperties get_rejected_properties() const; - void request_properties(const WindowProperties &requested_properties); + + EXTENSION(void request_properties(PyObject *args, PyObject *kwds)); + INLINE bool is_closed() const; virtual bool is_active() const; INLINE bool is_fullscreen() const; @@ -100,6 +102,8 @@ PUBLISHED: virtual void close_ime(); public: + void request_properties(const WindowProperties &requested_properties); + virtual void add_window_proc( const GraphicsWindowProc* wnd_proc_object ){}; virtual void remove_window_proc( const GraphicsWindowProc* wnd_proc_object ){}; virtual void clear_window_procs(){}; diff --git a/panda/src/display/graphicsWindow_ext.cxx b/panda/src/display/graphicsWindow_ext.cxx index 7dbc05c8b2..f371672b85 100644 --- a/panda/src/display/graphicsWindow_ext.cxx +++ b/panda/src/display/graphicsWindow_ext.cxx @@ -12,9 +12,26 @@ */ #include "graphicsWindow_ext.h" +#include "windowProperties_ext.h" #ifdef HAVE_PYTHON +/** + * Convenient shorthand for requesting properties. + */ +void Extension:: +request_properties(PyObject *args, PyObject *kwds) { + extern struct Dtool_PyTypedObject Dtool_WindowProperties; + + WindowProperties props; + PyObject *py_props = DTool_CreatePyInstance((void *)&props, Dtool_WindowProperties, false, false); + + invoke_extension(&props).__init__(py_props, args, kwds); + + _this->request_properties(props); + Py_DECREF(py_props); +} + /** * Adds a python event handler to be called when a window event occurs. */ diff --git a/panda/src/display/graphicsWindow_ext.h b/panda/src/display/graphicsWindow_ext.h index 166e40f401..694098dc2b 100644 --- a/panda/src/display/graphicsWindow_ext.h +++ b/panda/src/display/graphicsWindow_ext.h @@ -30,6 +30,8 @@ template<> class Extension : public ExtensionBase { public: + void request_properties(PyObject *args, PyObject *kwds); + void add_python_event_handler(PyObject* handler, PyObject* name); void remove_python_event_handler(PyObject* name); };