8000 Add keyword argument support to display.c by jonotassia · Pull Request #3859 · pygame/pygame · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add keyword argument support to display.c #3859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/reST/ref/display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,8 @@ required).
it is a good idea to check the value of any requested OpenGL attributes. See
``pygame.display.gl_set_attribute()`` for a list of valid flags.

.. versionchanged:: 2.5.0 Added support for keyword arguments.

.. ## pygame.display.gl_get_attribute ##

.. function:: gl_set_attribute
Expand Down Expand Up @@ -463,6 +465,8 @@ required).

Minimum bit size of the frame buffer. Defaults to 0.

.. versionchanged:: 2.5.0 Added support for keyword arguments.

.. versionadded:: 2.0.0 Additional attributes:

::
Expand Down Expand Up @@ -629,6 +633,8 @@ required).
window. In pygame 1.x, some systems supported an alternate shorter title to
be used for minimized displays, but in pygame 2 ``icontitle`` does nothing.

.. versionchanged:: 2.5.0 Added support for keyword arguments.

.. ## pygame.display.set_caption ##

.. function:: get_caption
Expand All @@ -652,6 +658,8 @@ required).
system default palette will be restored. The palette is a sequence of
``RGB`` triplets.

.. versionchanged:: 2.5.0 Added support for keyword arguments.

.. ## pygame.display.set_palette ##

.. function:: get_num_displays
Expand Down
44 changes: 30 additions & 14 deletions src_c/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,15 @@ pg_get_surface(PyObject *self, PyObject *_null)
}

static PyObject *
pg_gl_set_attribute(PyObject *self, PyObject *arg)
pg_gl_set_attribute(PyObject *self, PyObject *arg, PyObject *kwargs)
{
int flag, value, result;
VIDEO_INIT_CHECK();
if (!PyArg_ParseTuple(arg, "ii", &flag, &value))

static char *keywords[] = {"flag", "value", NULL};

if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "ii", keywords, &flag,
&value))
return NULL;
if (flag == -1) /*an undefined/unsupported val, ignore*/
Py_RETURN_NONE;
Expand All @@ -624,11 +628,14 @@ pg_gl_set_attribute(PyObject *self, PyObject *arg)
}

static PyObject *
pg_gl_get_attribute(PyObject *self, PyObject *arg)
pg_gl_get_attribute(PyObject *self, PyObject *arg, PyObject *kwargs)
{
int flag, value, result;
VIDEO_INIT_CHECK();
if (!PyArg_ParseTuple(arg, "i", &flag))

static char *keywords[] = {"flag", NULL};

if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "i", keywords, &flag))
return NULL;
result = SDL_GL_GetAttribute(flag, &value);
if (result == -1)
Expand Down Expand Up @@ -1697,7 +1704,7 @@ pg_update(PyObject *self, PyObject *arg)
}

static PyObject *
pg_set_palette(PyObject *self, PyObject *args)
pg_set_palette(PyObject *self, PyObject *arg, PyObject *kwargs)
{
pgSurfaceObject *surface = pg_GetDefaultWindowSurface();
SDL_Surface *surf;
10000 Expand All @@ -1708,7 +1715,10 @@ pg_set_palette(PyObject *self, PyObject *args)
Uint8 rgba[4];

VIDEO_INIT_CHECK();
if (!PyArg_ParseTuple(args, "|O", &list))

static char *keywords[] = {"palette", NULL};

if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "|O", keywords, &list))
return NULL;
if (!surface)
return RAISE(pgExc_SDLError, "No display mode is set");
Expand Down Expand Up @@ -1901,6 +1911,7 @@ pg_set_gamma_ramp(PyObject *self, PyObject *arg)
r = gamma_ramp;
g = gamma_ramp + 256;
b = gamma_ramp + 512;

if (!PyArg_ParseTuple(arg, "O&O&O&", pg_convert_to_uint16, r,
pg_convert_to_uint16, g, pg_convert_to_uint16, b)) {
free(gamma_ramp);
Expand All @@ -1925,7 +1936,7 @@ pg_set_gamma_ramp(PyObject *self, PyObject *arg)
}

static PyObject *
pg_set_caption(PyObject *self, PyObject *arg)
pg_set_caption(PyObject *self, PyObject *arg, PyObject *kwargs)
{
_DisplayState *state = DISPLAY_MOD_STATE(self);
SDL_Window *win = pg_GetDefaultWindow();
Expand All @@ -1937,7 +1948,10 @@ pg_set_caption(PyObject *self, PyObject *arg)
__analysis_assume(title = "inited");
#endif

if (!PyArg_ParseTuple(arg, "s|s", &title, &icontitle))
static char *keywords[] = {"title", "icontitle", NULL};

if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "s|s", keywords, &title,
&icontitle))
return NULL;

if (state->title)
Expand Down Expand Up @@ -2553,12 +2567,14 @@ static PyMethodDef _pg_display_methods[] = {
{"flip", (PyCFunction)pg_flip, METH_NOARGS, DOC_PYGAMEDISPLAYFLIP},
{"update", (PyCFunction)pg_update, METH_VARARGS, DOC_PYGAMEDISPLAYUPDATE},

{"set_palette", pg_set_palette, METH_VARARGS, DOC_PYGAMEDISPLAYSETPALETTE},
{"set_palette", (PyCFunction)pg_set_palette, METH_VARARGS | METH_KEYWORDS,
DOC_PYGAMEDISPLAYSETPALETTE},
{"set_gamma", pg_set_gamma, METH_VARARGS, DOC_PYGAMEDISPLAYSETGAMMA},
{"set_gamma_ramp", pg_set_gamma_ramp, METH_VARARGS,
DOC_PYGAMEDISPLAYSETGAMMARAMP},

{"set_caption", pg_set_caption, METH_VARARGS, DOC_PYGAMEDISPLAYSETCAPTION},
{"set_caption", (PyCFunction)pg_set_caption, METH_VARARGS | METH_KEYWORDS,
DOC_PYGAMEDISPLAYSETCAPTION},
{"get_caption", (PyCFunction)pg_get_caption, METH_NOARGS,
DOC_PYGAMEDISPLAYGETCAPTION},
{"set_icon", pg_set_icon, METH_O, DOC_PYGAMEDISPLAYSETICON},
Expand All @@ -2580,10 +2596,10 @@ static PyMethodDef _pg_display_methods[] = {
{"is_fullscreen", (PyCFunction)pg_is_fullscreen, METH_NOARGS,
"provisional API, subject to change"},

{"gl_set_attribute", pg_gl_set_attribute, METH_VARARGS,
DOC_PYGAMEDISPLAYGLSETATTRIBUTE},
{"gl_get_attribute", pg_gl_get_attribute, METH_VARARGS,
DOC_PYGAMEDISPLAYGLGETATTRIBUTE},
{"gl_set_attribute", (PyCFunction)pg_gl_set_attribute,
METH_VARARGS | METH_KEYWORDS, DOC_PYGAMEDISPLAYGLSETATTRIBUTE},
{"gl_get_attribute", (PyCFunction)pg_gl_get_attribute,
METH_VARARGS | METH_KEYWORDS, DOC_PYGAMEDISPLAYGLGETATTRIBUTE},

{"get_allow_screensaver", (PyCFunction)pg_get_allow_screensaver,
METH_NOARGS, DOC_PYGAMEDISPLAYGETALLOWSCREENSAVER},
Expand Down
Loading
0