Skip to content

Commit 40e37b2

Browse files
committed
Update pysdl2.py - initial support for Mac
1 parent 5c91c65 commit 40e37b2

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

examples/README-examples.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ workarounds.
4545
- [gtk3.py](gtk3.py): example for [PyGObject / PyGI](https://wiki.gnome.org/Projects/PyGObject)
4646
library (GTK 3). Currently broken on Mac ([#310](../../../issues/310)).
4747
- [pysdl2.py](pysdl2.py): off-screen rendering example for
48-
[PySDL2](https://github.com/marcusva/py-sdl2) library. Currently tested
49-
and works fine on Linux and Windows. For Mac support and performance
50-
tweaking see Issue [#324](../../../issues/324).
48+
[PySDL2](https://github.com/marcusva/py-sdl2) library. There are issues
49+
when running on slow machine - key events are being lost (noticed on Mac).
50+
Example has some issues that are reported in Issue [#324](../../../issues/324).
5151
- [pywin32.py](pywin32.py): example for [pywin32](https://github.com/mhammond/pywin32)
5252
library
5353
- [qt.py](qt.py): example for [PyQt4](https://wiki.python.org/moin/PyQt4),

examples/pysdl2.py

+20-5
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
1616
Tested configurations:
1717
- Windows 7: SDL 2.0.7 and PySDL2 0.9.6
18+
- Mac 10.9: SDL 2.0.7 and PySDL2 0.9.6
1819
- Fedora 26: SDL2 2.0.7 with PySDL2 0.9.6
1920
- Ubuntu 14.04: SDL2 with PySDL2 0.9.6
2021
2122
Install instructions:
2223
1. Install SDL libraries for your OS, e.g:
2324
- Windows: Download SDL2.dll from http://www.libsdl.org/download-2.0.php
2425
and put SDL2.dll in C:\Python27\ (where you've installed Python)
26+
- Mac: Install Homebrew from https://brew.sh/
27+
and then type "brew install sdl2"
2528
- Fedora: sudo dnf install SDL2 SDL2_ttf SDL2_image SDL2_gfx SDL2_mixer
2629
- Ubuntu: sudo apt-get install libsdl2-dev
2730
2. Install PySDL2 using pip package manager:
@@ -60,20 +63,32 @@ def die(msg):
6063
# noinspection PyUnresolvedReferences
6164
from cefpython3 import cefpython as cef
6265
except ImportError:
63-
die("""ERROR: cefpython3 package not found\n
64-
To install type: `pip install cefpython3`""")
66+
die("ERROR: cefpython3 package not found\n"
67+
" To install type: pip install cefpython3")
68+
6569
try:
6670
# noinspection PyUnresolvedReferences
6771
import sdl2
6872
# noinspection PyUnresolvedReferences
6973
import sdl2.ext
70-
except ImportError:
71-
die("ERROR: SDL2 package not found\nTo install type: `pip install PySDL2`")
74+
except ImportError as exc:
75+
excstr = repr(exc)
76+
if "No module named sdl2" in excstr:
77+
die("ERROR: PySDL2 package not found\n"
78+
" To install type: pip install PySDL2")
79+
elif ("could not find any library for SDL2"
80+
" (PYSDL2_DLL_PATH: unset)" in excstr):
81+
die("ERROR: SDL2 package not found.\n"
82+
" See install instructions in top comment in sources.")
83+
else:
84+
die(excstr)
85+
7286
try:
7387
# noinspection PyUnresolvedReferences
7488
from PIL import Image
7589
except ImportError:
76-
die("ERROR: PIL package not found\nTo install type: pip install Pillow")
90+
die("ERROR: PIL package not found\n"
91+
" To install type: pip install Pillow")
7792

7893

7994
def main():

0 commit comments

Comments
 (0)