diff --git a/python/src/RenderWindow.cpp b/python/src/RenderWindow.cpp index 598efd877..ad35f934e 100644 --- a/python/src/RenderWindow.cpp +++ b/python/src/RenderWindow.cpp @@ -244,11 +244,13 @@ PyTypeObject PySfRenderWindowType = { Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ "Simple wrapper for sf.Window that allows easy 2D rendering.\n\ Default constructor : sf.RenderWindow()\n\ -Other constructor : sf.RenderWindow(Mode, Title, Style::Resize|Style::Close, Params = WindowSettings())\n\ -Parameters:\n\ +Construct a new window : sf.RenderWindow(Mode, Title, Style::Resize|Style::Close, Params = WindowSettings())\n\ Mode : Video mode to use\n\ Title : Title of the window\n\ WindowStyle : Window style (Resize | Close by default)\n\ + Params : Creation parameters (see default constructor for default values)\n\ +Construct the window from an existing control : sf.RenderWindow(Handle, Params)\n\ + Handle : handle of the control (long integer)\n\ Params : Creation parameters (see default constructor for default values)", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ diff --git a/python/src/Window.cpp b/python/src/Window.cpp index 481eaf42b..bed8e7026 100644 --- a/python/src/Window.cpp +++ b/python/src/Window.cpp @@ -48,11 +48,29 @@ PySfWindow_dealloc(PySfWindow* self) static PyObject * PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ +{ + long Handle; + PySfWindowSettings *Params=NULL; PySfWindow *self; self = (PySfWindow *)type->tp_alloc(type, 0); - if (self != NULL) - self->obj = new sf::Window(); + if (self != NULL) + { + if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfWindowSettingsType, &Params)) + { + if (Params) + { + PySfWindowSettingsUpdate(Params); + self->obj = new sf::Window((sf::WindowHandle)Handle, *(Params->obj)); + } + else + self->obj = new sf::Window((sf::WindowHandle)Handle); + } + else + { + PyErr_Clear(); + self->obj = new sf::Window(); + } + } return (PyObject *)self; } @@ -99,7 +117,6 @@ PySfWindow_GetEvent(PySfWindow *self, PyObject *args) } - PyObject* PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds) { @@ -109,7 +126,7 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds) unsigned long WindowStyle = sf::Style::Resize | sf::Style::Close; PySfWindowSettings *Params=NULL; - const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL}; + const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL}; if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!:Window.Create", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &Params)) return NULL; @@ -131,9 +148,17 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds) static int PySfWindow_init(PySfWindow *self, PyObject *args, PyObject *kwds) { - if (args != NULL) + long Handle; + PySfWindowSettings *Params; + + if (args != NULL) + { + if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfWindowSettingsType, &Params)) + return 0; + PyErr_Clear(); if (PySfWindow_Create(self, args, kwds) == NULL) - return -1; + return -1; + } return 0; } @@ -344,7 +369,9 @@ Construct a new window : sf.Window(Mode, Title, sf.Style.Resize | sf.Style.Close Title : Title of the window\n\ WindowStyle : Window style (Resize | Close by default)\n\ Params : Creation parameters (see default constructor for default values)\n\ -", /* tp_doc */ +Construct the window from an existing control : sf.Window(Handle, Params)\n\ + Handle : Platform-specific handle of the control\n\ + Params : Creation parameters (see default constructor for default values)", /* tp_doc */ 0, /* tp_traverse */ 0, /* tp_clear */ 0, /* tp_richcompare */