Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tweaking version getters for sdl modules and freetype#3379

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Starbuck5 merged 14 commits intopygame:mainfromoddbookworm:getters
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
14 commits
Select commitHold shift + click to select a range
e3e4120
added keyword arg to get_sdl_version to return linked or compiled ver…
oddbookwormAug 6, 2022
cfc3a4d
added compiled keyword to image.get_sdl_image_version
oddbookwormAug 7, 2022
49bc9d9
added compiled keyword to freetype.get_version
oddbookwormAug 7, 2022
130c9b9
Merge branch 'pygame:main' into getters
oddbookwormAug 7, 2022
d9d0371
formatted
oddbookwormAug 7, 2022
6e94d98
removed a couple of commented out temp functions
oddbookwormAug 7, 2022
b58a0fd
hopefully fixed the incompatible types warnings
oddbookwormAug 7, 2022
194d18c
removed accidental extra character in comment
oddbookwormAug 7, 2022
98cd349
changed compiled=True default kwarg to linked=False default kwarg
oddbookwormAug 13, 2022
73730e0
ran formatter
oddbookwormAug 13, 2022
4490f0b
changed default behavior for image and freetype getters to return lin…
oddbookwormAug 29, 2022
28fe46a
updated documentation according to the changes I've made
oddbookwormAug 30, 2022
b352253
removed the files I accidentally added to the commit
oddbookwormAug 30, 2022
4f85e92
removed unnecessary commented line of code
oddbookwormAug 30, 2022
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
2 changes: 1 addition & 1 deletionbuildconfig/stubs/pygame/base.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ def quit() -> None: ...
def get_init() -> bool: ...
def get_error() -> str: ...
def set_error(error_msg: str) -> None: ...
def get_sdl_version() -> Tuple[int, int, int]: ...
def get_sdl_version(linked: bool = True) -> Tuple[int, int, int]: ...
def get_sdl_byteorder() -> int: ...
def register_quit(callable: Callable[[], Any]) -> None: ...

Expand Down
2 changes: 1 addition & 1 deletionbuildconfig/stubs/pygame/freetype.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,7 +7,7 @@ from pygame.surface import Surface
from ._common import ColorValue, FileArg, RectValue

def get_error() -> str: ...
def get_version() -> Tuple[int, int, int]: ...
def get_version(linked: bool = True) -> Tuple[int, int, int]: ...
def init(cache_size: int = 64, resolution: int = 72) -> None: ...
def quit() -> None: ...
def get_init() -> bool: ...
Expand Down
2 changes: 1 addition & 1 deletionbuildconfig/stubs/pygame/image.pyi
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,7 +14,7 @@ _from_string_format = Literal["P", "RGB", "RGBX", "RGBA", "ARGB", "BGRA"]

def load(filename: FileArg, namehint: str = "") -> Surface: ...
def save(surface: Surface, filename: FileArg, namehint: str = "") -> None: ...
def get_sdl_image_version() -> Optional[Tuple[int, int, int]]: ...
def get_sdl_image_version(linked: bool = True) -> Optional[Tuple[int, int, int]]: ...
def get_extended() -> bool: ...
def tostring(
surface: Surface, format: _to_string_format, flipped: bool = False
Expand Down
8 changes: 6 additions & 2 deletionsdocs/reST/ref/freetype.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -74,14 +74,18 @@ loaded. This module must be imported explicitly to be used. ::
.. function:: get_version

| :sl:`Return the FreeType version`
| :sg:`get_version() -> (int, int, int)`
| :sg:`get_version(linked=True) -> (int, int, int)`

Returns the version of the FreeType library in use by this module.
Returns the version of the FreeType library in use by this module. ``linked=True``
is the default behavior and returns the linked version of FreeType and ``linked=False``
returns the compiled version of FreeType.

Note that the ``freetype`` module depends on the FreeType 2 library.
It will not compile with the original FreeType 1.0. Hence, the first element
of the tuple will always be "2".

.. versionchanged:: 2.1.4 ``linked`` keyword argument added and default behavior changed from returning compiled version to returning linked version

.. function:: init

| :sl:`Initialize the underlying FreeType library.`
Expand Down
10 changes: 8 additions & 2 deletionsdocs/reST/ref/image.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,15 +130,21 @@ following formats.
.. function:: get_sdl_image_version

| :sl:`get version number of the SDL_Image library being used`
| :sg:`get_sdl_image_version() -> None`
| :sg:`get_sdl_image_version() -> (major, minor, patch)`
| :sg:`get_sdl_image_version(linked=True) -> None`
| :sg:`get_sdl_image_version(linked=True) -> (major, minor, patch)`

If pygame is built with extended image formats, then this function will
return the SDL_Image library's version number as a tuple of 3 integers
``(major, minor, patch)``. If not, then it will return ``None``.

``linked=True`` is the default behavior and the function will return the
version of the library that Pygame is linked against, while ``linked=False``
will return the version of the library that Pygame is compiled against.

.. versionadded:: 2.0.0

.. versionchanged:: 2.1.4 ``linked`` keyword argument added and default behavior changed from returning compiled version to returning linked version

.. ## pygame.image.get_sdl_image_version ##

.. function:: get_extended
Expand Down
11 changes: 8 additions & 3 deletionsdocs/reST/ref/pygame.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -108,14 +108,19 @@ object instead of the module, which can be used to test for availability.
.. function:: get_sdl_version

| :sl:`get the version number of SDL`
| :sg:`get_sdl_version() -> major, minor, patch`
| :sg:`get_sdl_version(linked=True) -> major, minor, patch`

Returns the three version numbers of the SDL library. This version is built
at compile time. It can be used to detect which features may or may not be
Returns the three version numbers of the SDL library. ``linked=True``
will cause the function to return the version of the library that pygame
is linked against while ``linked=False`` will cause the function to return
the version of the library that pygame is compiled against.
It can be used to detect which features may or may not be
available through pygame.

.. versionadded:: 1.7.0

.. versionchanged:: 2.1.4 ``linked`` keyword argument added

.. ## pygame.get_sdl_version ##

.. function:: get_sdl_byteorder
Expand Down
25 changes: 19 additions & 6 deletionssrc_c/_freetype.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,7 +45,7 @@ _ft_quit(PyObject *, PyObject *);
static PyObject *
_ft_init(PyObject *, PyObject *, PyObject *);
static PyObject *
_ft_get_version(PyObject *, PyObject *);
_ft_get_version(PyObject *, PyObject *, PyObject *);
static PyObject *
_ft_get_error(PyObject *, PyObject *);
static PyObject *
Expand DownExpand Up@@ -493,7 +493,7 @@ static PyMethodDef _ft_methods[] = {
{"was_init", _ft_get_init, METH_NOARGS,
DOC_PYGAMEFREETYPEWASINIT}, // DEPRECATED
{"get_error", _ft_get_error, METH_NOARGS, DOC_PYGAMEFREETYPEGETERROR},
{"get_version", _ft_get_version,METH_NOARGS,
{"get_version",(PyCFunction)_ft_get_version,METH_VARARGS | METH_KEYWORDS,
DOC_PYGAMEFREETYPEGETVERSION},
{"get_cache_size", _ft_get_cache_size, METH_NOARGS,
DOC_PYGAMEFREETYPEGETCACHESIZE},
Expand DownExpand Up@@ -2039,11 +2039,24 @@ _ft_get_error(PyObject *self, PyObject *_null)
}

static PyObject *
_ft_get_version(PyObject *self, PyObject *_null)
_ft_get_version(PyObject *self, PyObject *args, PyObject *kwargs)
{
/* Return the linked FreeType2 version */
return Py_BuildValue("iii", FREETYPE_MAJOR, FREETYPE_MINOR,
FREETYPE_PATCH);
int linked = 1;
static char *keywords[] = {"linked", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|p", keywords, &linked)) {
return NULL;
}

if (linked) {
FT_Int major, minor, patch;
FT_Library_Version(inst->library, &major, &minor, &patch);
return Py_BuildValue("iii", major, minor, patch);
}
else {
return Py_BuildValue("iii", FREETYPE_MAJOR, FREETYPE_MINOR,
FREETYPE_PATCH);
}
}

static PyObject *
Expand Down
20 changes: 16 additions & 4 deletionssrc_c/base.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -385,11 +385,23 @@ pg_atexit_quit(void)
}

static PyObject *
pg_get_sdl_version(PyObject *self, PyObject *_null)
pg_get_sdl_version(PyObject *self, PyObject *args, PyObject *kwargs)
{
int linked = 1; /* Default is linked version. */
SDL_version v;

SDL_GetVersion(&v);
static char *keywords[] = {"linked", NULL};

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|p", keywords, &linked)) {
return NULL; /* Exception already set. */
}

if (linked) {
SDL_GetVersion(&v);
}
else {
SDL_VERSION(&v);
}
return Py_BuildValue("iii", v.major, v.minor, v.patch);
}

Expand DownExpand Up@@ -2077,8 +2089,8 @@ static PyMethodDef _base_methods[] = {
DOC_PYGAMEREGISTERQUIT},
{"get_error", (PyCFunction)pg_get_error, METH_NOARGS, DOC_PYGAMEGETERROR},
{"set_error", pg_set_error, METH_VARARGS, DOC_PYGAMESETERROR},
{"get_sdl_version", (PyCFunction)pg_get_sdl_version, METH_NOARGS,
DOC_PYGAMEGETSDLVERSION},
{"get_sdl_version", (PyCFunction)pg_get_sdl_version,
METH_VARARGS | METH_KEYWORDS,DOC_PYGAMEGETSDLVERSION},
{"get_sdl_byteorder", (PyCFunction)pg_get_sdl_byteorder, METH_NOARGS,
DOC_PYGAMEGETSDLBYTEORDER},

Expand Down
4 changes: 2 additions & 2 deletionssrc_c/doc/freetype_doc.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
/* Auto generated file: with makeref.py . Docs go in docs/reST/ref/ . */
#define DOC_PYGAMEFREETYPE "Enhanced pygame module for loading and rendering computer fonts"
#define DOC_PYGAMEFREETYPEGETERROR "get_error() -> str\nget_error() -> None\nReturn the latest FreeType error"
#define DOC_PYGAMEFREETYPEGETVERSION "get_version() -> (int, int, int)\nReturn the FreeType version"
#define DOC_PYGAMEFREETYPEGETVERSION "get_version(linked=True) -> (int, int, int)\nReturn the FreeType version"
#define DOC_PYGAMEFREETYPEINIT "init(cache_size=64, resolution=72) -> None\nInitialize the underlying FreeType library."
#define DOC_PYGAMEFREETYPEQUIT "quit() -> None\nShut down the underlying FreeType library."
#define DOC_PYGAMEFREETYPEGETINIT "get_init() -> bool\nReturns True if the FreeType module is currently initialized."
Expand DownExpand Up@@ -65,7 +65,7 @@ pygame.freetype.get_error
Return the latest FreeType error

pygame.freetype.get_version
get_version() -> (int, int, int)
get_version(linked=True) -> (int, int, int)
Return the FreeType version

pygame.freetype.init
Expand Down
6 changes: 3 additions & 3 deletionssrc_c/doc/image_doc.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,7 +2,7 @@
#define DOC_PYGAMEIMAGE "pygame module for image transfer"
#define DOC_PYGAMEIMAGELOAD "load(filename) -> Surface\nload(fileobj, namehint="") -> Surface\nload new image from a file (or file-like object)"
#define DOC_PYGAMEIMAGESAVE "save(Surface, filename) -> None\nsave(Surface, fileobj, namehint="") -> None\nsave an image to file (or file-like object)"
#define DOC_PYGAMEIMAGEGETSDLIMAGEVERSION "get_sdl_image_version() -> None\nget_sdl_image_version() -> (major, minor, patch)\nget version number of the SDL_Image library being used"
#define DOC_PYGAMEIMAGEGETSDLIMAGEVERSION "get_sdl_image_version(linked=True) -> None\nget_sdl_image_version(linked=True) -> (major, minor, patch)\nget version number of the SDL_Image library being used"
#define DOC_PYGAMEIMAGEGETEXTENDED "get_extended() -> bool\ntest if extended image formats can be loaded"
#define DOC_PYGAMEIMAGETOSTRING "tostring(Surface, format, flipped=False) -> bytes\ntransfer image to byte buffer"
#define DOC_PYGAMEIMAGETOBYTES "tobytes(Surface, format, flipped=False) -> bytes\ntransfer image to byte buffer"
Expand DownExpand Up@@ -32,8 +32,8 @@ pygame.image.save
save an image to file (or file-like object)

pygame.image.get_sdl_image_version
get_sdl_image_version() -> None
get_sdl_image_version() -> (major, minor, patch)
get_sdl_image_version(linked=True) -> None
get_sdl_image_version(linked=True) -> (major, minor, patch)
get version number of the SDL_Image library being used

pygame.image.get_extended
Expand Down
4 changes: 2 additions & 2 deletionssrc_c/doc/pygame_doc.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,7 +6,7 @@
#define DOC_PYGAMEERROR "raise pygame.error(message)\nstandard pygame exception"
#define DOC_PYGAMEGETERROR "get_error() -> errorstr\nget the current error message"
#define DOC_PYGAMESETERROR "set_error(error_msg) -> None\nset the current error message"
#define DOC_PYGAMEGETSDLVERSION "get_sdl_version() -> major, minor, patch\nget the version number of SDL"
#define DOC_PYGAMEGETSDLVERSION "get_sdl_version(linked=True) -> major, minor, patch\nget the version number of SDL"
#define DOC_PYGAMEGETSDLBYTEORDER "get_sdl_byteorder() -> int\nget the byte order of SDL"
#define DOC_PYGAMEREGISTERQUIT "register_quit(callable) -> None\nregister a function to be called when pygame quits"
#define DOC_PYGAMEENCODESTRING "encode_string([obj [, encoding [, errors [, etype]]]]) -> bytes or None\nEncode a Unicode or bytes object"
Expand DownExpand Up@@ -50,7 +50,7 @@ pygame.set_error
set the current error message

pygame.get_sdl_version
get_sdl_version() -> major, minor, patch
get_sdl_version(linked=True) -> major, minor, patch
get the version number of SDL

pygame.get_sdl_byteorder
Expand Down
2 changes: 1 addition & 1 deletionsrc_c/freetype/ft_wrap.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -534,10 +534,10 @@ _PGFT_UnloadFont(FreeTypeInstance *ft, pgFontObject *fontobj)
* Library (de)initialization
*
*********************************************************/
FreeTypeInstance *inst = 0;
int
_PGFT_Init(FreeTypeInstance **_instance, int cache_size)
{
FreeTypeInstance *inst = 0;
int error;

inst = _PGFT_malloc(sizeof(FreeTypeInstance));
Expand Down
2 changes: 2 additions & 0 deletionssrc_c/freetype/ft_wrap.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -253,6 +253,8 @@ extern _FreeTypeState _modstate;
* Internal API
**********************************************************/

extern FreeTypeInstance *inst;

/**************************************** General functions ******************/
const char *
_PGFT_GetError(FreeTypeInstance *);
Expand Down
6 changes: 3 additions & 3 deletionssrc_c/image.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -236,12 +236,12 @@ image_get_extended(PyObject *self, PyObject *_null)
}

static PyObject *
image_get_sdl_image_version(PyObject *self, PyObject *_null)
image_get_sdl_image_version(PyObject *self, PyObject *args, PyObject *kwargs)
{
if (extverobj == NULL)
Py_RETURN_NONE;
else
returnPyObject_CallObject(extverobj,NULL);
returnPyObject_Call(extverobj,args, kwargs);
}

#if PG_COMPILE_SSE4_2
Expand DownExpand Up@@ -1586,7 +1586,7 @@ static PyMethodDef _image_methods[] = {
{"get_extended", (PyCFunction)image_get_extended, METH_NOARGS,
DOC_PYGAMEIMAGEGETEXTENDED},
{"get_sdl_image_version", (PyCFunction)image_get_sdl_image_version,
METH_NOARGS, DOC_PYGAMEIMAGEGETSDLIMAGEVERSION},
METH_VARARGS | METH_KEYWORDS, DOC_PYGAMEIMAGEGETSDLIMAGEVERSION},

{"tostring", image_tostring, METH_VARARGS, DOC_PYGAMEIMAGETOSTRING},
{"tobytes", image_tostring, METH_VARARGS, DOC_PYGAMEIMAGETOBYTES},
Expand Down
25 changes: 21 additions & 4 deletionssrc_c/imageext.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -414,10 +414,26 @@ image_save_ext(PyObject *self, PyObject *arg)
}

static PyObject *
imageext_get_sdl_image_version(PyObject *self, PyObject *_null)
imageext_get_sdl_image_version(PyObject *self, PyObject *args,
PyObject *kwargs)
{
return Py_BuildValue("iii", SDL_IMAGE_MAJOR_VERSION,
SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_PATCHLEVEL);
int linked = 1;

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

if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|p", keywords, &linked)) {
return NULL;
}

if (linked) {
SDL_version v;
SDL_IMAGE_VERSION(&v);
return Py_BuildValue("iii", v.major, v.minor, v.patch);
}
else {
const SDL_version *v = IMG_Linked_Version();
return Py_BuildValue("iii", v->major, v->minor, v->patch);
}
}

/*
Expand All@@ -436,7 +452,8 @@ _imageext_free(void *ptr)
static PyMethodDef _imageext_methods[] = {
{"load_extended", image_load_ext, METH_VARARGS, DOC_PYGAMEIMAGE},
{"save_extended", image_save_ext, METH_VARARGS, DOC_PYGAMEIMAGE},
{"_get_sdl_image_version", imageext_get_sdl_image_version, METH_NOARGS,
{"_get_sdl_image_version", (PyCFunction)imageext_get_sdl_image_version,
METH_VARARGS | METH_KEYWORDS,
"_get_sdl_image_version() -> (major, minor, patch)\n"
"Note: Should not be used directly."},
{NULL, NULL, 0, NULL}};
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp