File: integration.rst

package info (click to toggle)
pysdl2 0.9.6+dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,204 kB
  • sloc: python: 16,109; makefile: 213; sh: 32
file content (77 lines) | stat: -rw-r--r-- 3,362 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Integrating PySDL2
==================
PySDL2 consists of two packages, :mod:`sdl2`, which is a plain 1:1 API
wrapper around the SDL2 API, and :mod:`sdl2.ext`, which offers enhanced
functionality for :mod:`sdl2`.

The :mod:`sdl2` package is implemented in a way that shall make it easy for
you to integrate and deploy it with your own software projects. You can rely
on PySDL2 as third-party package, so that the user needs to install it
before he can use your software. Alternatively, you can just copy the
whole package into your project to ship it within your own project
bundle.

.. _importing-pysdl2:

Importing
---------
The :mod:`sdl2` package relies on an external SDL2 library for creating the
wrapper functions. This means that the user needs to have SDL2 installed or
that you ship a SDL2 library with your project.

If the user has a SDL2 library installed on the target system, the
:mod:`ctypes` hooks of :mod:`sdl2` try to find it in the OS-specific standard
locations via :func:`ctypes.util.find_library`. If you are going to ship your
own SDL2 library with the project or can not rely on the standard mechanism of
:mod:`ctypes`, it is also possible to set the environment variable
:envvar:`PYSDL2_DLL_PATH`, which shall point to the directory of the SDL2
library or consist of a list of directories, in which the SDL2 libraries can
be found.

.. note::

   :envvar:`PYSDL2_DLL_PATH` is preferred over the standard
   mechanism. If the module finds a SDL2 library in :envvar:`PYSDL2_DLL_PATH`,
   it will try to use that one in the first place, before using any SDL2
   library installed on the target system.

Let's assume, you ship your own library *SDL2.dll* within your project
location *fancy_project/third_party*. You can set the environment
variable :envvar:`PYSDL2_DLL_PATH` before starting Python. ::

  # Win32 platforms
  set PYSDL2_DLL_PATH=C:\path\to\fancy_project\third_party

  # Unix/Posix-alike environments - bourne shells
  export PYSDL2_DLL_PATH=/path/to/fancy_project/third_party

  # Unix/Posix-alike environments - C shells
  setenv PYSDL2_DLL_PATH /path/to/fancy_project/third_party

  # Define multiple paths to search for the libraries - Win32
  set PYSDL2_DLL_PATH=C:\first\path;C:\second\path

You also can set the environment variable within Python using
:data:`os.environ`. ::

  os.environ["PYSDL2_DLL_PATH"] = "C:\\path\\to\\fancy_project\\third_party"
  os.environ["PYSDL2_DLL_PATH"] = "/path/to/fancy_project/third_party"

.. note::

   If you aim to integrate :mod:`sdl` directly into your software and do
   not want or are not allowed to change the environment variables, you
   can also change the ``os.getenv("PYSDL2_DLL_PATH")`` query within the
   *sdl2/dll.py* (or *sdl2/sdlimage.py*, *sdl2/sdlttf.py*, *sdl2/sdlgfx.py*)
   file to point to the directory, in which you keep the DLL.

Using different SDL2 versions
-----------------------------
PySDL2 tries to provide interfaces to the most recent versions of the
SDL2 libraries. Sometimes this means that PySDL2 tries to test for
functions that might not be available for your very own project or that
are not available on the target system due to a version of the specific
library. To check, if the SDL2 libraries do not provide certain
functions, you can enable the specific warnings for them.

>>> python -W"module"::ImportWarning:sdl2.dll yourfile.py