@@ -713,6 +713,28 @@ window_from_display_module(PyTypeObject *cls, PyObject *_null)
713713 return (PyObject * )self ;
714714}
715715
716+ PyObject *
717+ window_repr (pgWindowObject * self )
718+ {
719+ const char * title ;
720+ int win_id ;
721+ if (!self -> _win ) {
722+ return PyUnicode_FromString ("<Window(Destroyed)>" );
723+ }
724+
725+ if (self -> _is_borrowed ) {
726+ return PyUnicode_FromString ("<Window(From Display)>" );
727+ }
728+
729+ title = SDL_GetWindowTitle (self -> _win );
730+ win_id = SDL_GetWindowID (self -> _win );
731+ if (win_id == 0 ) {
732+ return RAISE (pgExc_SDLError , SDL_GetError ());
733+ }
734+
735+ return PyUnicode_FromFormat ("<Window(title='%s', id=%d)>" , title , win_id );
736+ }
737+
716738static PyMethodDef window_methods [] = {
717739 {"destroy" , (PyCFunction )window_destroy , METH_NOARGS ,
718740 DOC_SDL2_VIDEO_WINDOW_DESTROY },
@@ -775,7 +797,8 @@ static PyTypeObject pgWindow_Type = {
775797 .tp_methods = window_methods ,
776798 .tp_init = (initproc )window_init ,
777799 .tp_new = PyType_GenericNew ,
778- .tp_getset = _window_getset };
800+ .tp_getset = _window_getset ,
801+ .tp_repr = (reprfunc )window_repr };
779802
780803static PyMethodDef _window_methods [] = {
781804 {"get_grabbed_window" , (PyCFunction )get_grabbed_window , METH_NOARGS ,
0 commit comments