Mercurial > pygame
annotate lib/__init__.py @ 3172:d1b367fc08bc tests-returncode
Use a return code of 1 when the tests fail.
| author | Thomas Kluyver <takowl@gmail.com> |
|---|---|
| date | Wed, 09 Jan 2013 10:13:57 +0000 |
| parents | d2c7ea748801 |
| children |
| rev | line source |
|---|---|
| 29 | 1 ## pygame - Python Game Library |
| 107 | 2 ## Copyright (C) 2000-2001 Pete Shinners |
| 7 | 3 ## |
| 4 ## This library is free software; you can redistribute it and/or | |
| 5 ## modify it under the terms of the GNU Library General Public | |
| 6 ## License as published by the Free Software Foundation; either | |
| 7 ## version 2 of the License, or (at your option) any later version. | |
| 8 ## | |
| 9 ## This library is distributed in the hope that it will be useful, | |
| 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 ## Library General Public License for more details. | |
| 13 ## | |
| 14 ## You should have received a copy of the GNU Library General Public | |
| 15 ## License along with this library; if not, write to the Free | |
| 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 17 ## | |
| 18 ## Pete Shinners | |
| 31 | 19 ## pete@shinners.org |
| 314 | 20 """Pygame is a set of Python modules designed for writing games. |
| 21 It is written on top of the excellent SDL library. This allows you | |
| 22 to create fully featured games and multimedia programs in the python | |
| 23 language. The package is highly portable, with games running on | |
| 487 | 24 Windows, MacOS, OS X, BeOS, FreeBSD, IRIX, and Linux. |
| 314 | 25 """ |
| 311 | 26 |
|
3140
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
27 import sys, os |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
28 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
29 # Choose Windows display driver |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
30 if os.name == 'nt': |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
31 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
32 # Respect existing SDL_VIDEODRIVER setting if it has been set |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
33 if 'SDL_VIDEODRIVER' not in os.environ: |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
34 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
35 # If the Windows version is 95/98/ME and DirectX 5 or greater is |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
36 # installed, then use the directx driver rather than the default |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
37 # windib driver. |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
38 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
39 # http://docs.python.org/lib/module-sys.html |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
40 # 0 (VER_PLATFORM_WIN32s) Win32s on Windows 3.1 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
41 # 1 (VER_PLATFORM_WIN32_WINDOWS) Windows 95/98/ME |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
42 # 2 (VER_PLATFORM_WIN32_NT) Windows NT/2000/XP |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
43 # 3 (VER_PLATFORM_WIN32_CE) Windows CE |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
44 if sys.getwindowsversion()[0] == 1: |
|
1078
6a14b3189d8d
set directx as default driver for old versions of windows.
Rene Dudfield <renesd@gmail.com>
parents:
981
diff
changeset
|
45 |
|
3142
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
46 import _winreg |
|
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
47 |
|
3140
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
48 try: |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
49 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
50 # Get DirectX version from registry |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
51 key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
52 'SOFTWARE\\Microsoft\\DirectX') |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
53 dx_version_string = _winreg.QueryValueEx(key, 'Version') |
|
3142
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
54 key.Close() |
|
3140
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
55 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
56 # Set video driver to directx if DirectX 5 or better is |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
57 # installed. |
|
3142
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
58 # To interpret DirectX version numbers, see this page: |
|
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
59 # http://en.wikipedia.org/wiki/DirectX#Releases |
|
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
60 minor_dx_version = int(dx_version_string.split('.')[1]) |
|
3140
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
61 if minor_dx_version >= 5: |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
62 os.environ['SDL_VIDEODRIVER'] = 'directx' |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
63 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
64 # Clean up namespace |
|
3142
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
65 del key, dx_version_string, minor_dx_version |
|
3140
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
66 |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
67 except: |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
68 pass |
|
1078
6a14b3189d8d
set directx as default driver for old versions of windows.
Rene Dudfield <renesd@gmail.com>
parents:
981
diff
changeset
|
69 |
|
3142
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
70 # Clean up namespace |
|
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
71 del _winreg |
|
d2c7ea748801
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3140
diff
changeset
|
72 |
|
3010
10279e350697
When running under X11, always set the SDL window WM_CLASS to make the
Rene Dudfield <renesd@gmail.com>
parents:
2136
diff
changeset
|
73 # when running under X11, always set the SDL window WM_CLASS to make the |
| 3011 | 74 # window managers correctly match the pygame window. |
|
3140
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
75 elif 'DISPLAY' in os.environ and not 'SDL_VIDEO_X11_WMCLASS' in os.environ: |
|
3010
10279e350697
When running under X11, always set the SDL window WM_CLASS to make the
Rene Dudfield <renesd@gmail.com>
parents:
2136
diff
changeset
|
76 os.environ['SDL_VIDEO_X11_WMCLASS'] = os.path.basename(sys.argv[0]) |
|
1078
6a14b3189d8d
set directx as default driver for old versions of windows.
Rene Dudfield <renesd@gmail.com>
parents:
981
diff
changeset
|
77 |
| 387 | 78 class MissingModule: |
|
1610
6c5040262b53
implement *_tags.py module replacement to *_test.py level tags.
Lenard Lindstrom <len-l@telus.net>
parents:
1564
diff
changeset
|
79 _NOT_IMPLEMENTED_ = True |
| 387 | 80 def __init__(self, name, info='', urgent=0): |
| 81 self.name = name | |
| 82 self.info = str(info) | |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
83 try: |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
84 exc = sys.exc_info() |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
85 if exc[0] != None: |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
86 self.reason = "%s: %s" % (exc[0].__name__, str(exc[1])) |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
87 else: |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
88 self.reason = "" |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
89 finally: |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
90 del exc |
| 387 | 91 self.urgent = urgent |
| 92 if urgent: | |
| 93 self.warn() | |
| 94 | |
| 95 def __getattr__(self, var): | |
| 96 if not self.urgent: | |
| 97 self.warn() | |
| 388 | 98 self.urgent = 1 |
| 99 MissingPygameModule = "%s module not available" % self.name | |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
100 if self.reason: |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
101 MissingPygameModule += "\n(%s)" % self.reason |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
102 raise NotImplementedError(MissingPygameModule) |
| 387 | 103 |
| 104 def __nonzero__(self): | |
| 105 return 0 | |
| 106 | |
| 107 def warn(self): | |
| 108 if self.urgent: type = 'import' | |
| 109 else: type = 'use' | |
| 110 message = '%s %s: %s' % (type, self.name, self.info) | |
|
1499
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
111 if self.reason: |
|
65e001d30448
bug fix - required modules not raising error when failing to import.
Lenard Lindstrom <len-l@telus.net>
parents:
1495
diff
changeset
|
112 message += "\n(%s)" % self.reason |
| 396 | 113 try: |
| 387 | 114 import warnings |
| 115 if self.urgent: level = 4 | |
| 116 else: level = 3 | |
| 117 warnings.warn(message, RuntimeWarning, level) | |
| 396 | 118 except ImportError: |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
119 print (message) |
| 387 | 120 |
| 388 | 121 |
| 387 | 122 |
| 314 | 123 #we need to import like this, each at a time. the cleanest way to import |
| 124 #our modules is with the import command (not the __import__ function) | |
| 125 | |
| 126 #first, the "required" modules | |
| 127 from pygame.base import * | |
| 128 from pygame.constants import * | |
|
1564
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
129 from pygame.version import * |
| 314 | 130 from pygame.rect import Rect |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
131 from pygame.compat import geterror |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1994
diff
changeset
|
132 from pygame.rwobject import encode_string, encode_file_path |
| 314 | 133 import pygame.surflock |
| 460 | 134 import pygame.color |
| 135 Color = color.Color | |
|
3021
ab418efb80e3
imported pygame._view in the __init__ so that py2exe can find it.
Rene Dudfield <renesd@gmail.com>
parents:
3011
diff
changeset
|
136 import pygame._view |
|
ab418efb80e3
imported pygame._view in the __init__ so that py2exe can find it.
Rene Dudfield <renesd@gmail.com>
parents:
3011
diff
changeset
|
137 |
|
1564
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
138 __version__ = ver |
| 314 | 139 |
| 140 #next, the "standard" modules | |
| 141 #we still allow them to be missing for stripped down pygame distributions | |
| 1994 | 142 try: import pygame.math |
| 143 except (ImportError,IOError):math=MissingModule("math", geterror(), 1) | |
| 144 | |
|
1564
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
145 try: import pygame.cdrom |
|
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
146 except (ImportError,IOError):cdrom=MissingModule("cdrom", geterror(), 1) |
| 314 | 147 |
| 148 try: import pygame.cursors | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
149 except (ImportError,IOError):cursors=MissingModule("cursors", geterror(), 1) |
| 314 | 150 |
| 151 try: import pygame.display | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
152 except (ImportError,IOError):display=MissingModule("display", geterror(), 1) |
| 314 | 153 |
| 154 try: import pygame.draw | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
155 except (ImportError,IOError):draw=MissingModule("draw", geterror(), 1) |
| 314 | 156 |
| 157 try: import pygame.event | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
158 except (ImportError,IOError):event=MissingModule("event", geterror(), 1) |
| 314 | 159 |
| 160 try: import pygame.image | |
|
2116
04bace00377c
remove Mac error debugging
Lenard Lindstrom <len-l@telus.net>
parents:
2113
diff
changeset
|
161 except (ImportError,IOError):image=MissingModule("image", geterror(), 1) |
| 314 | 162 |
|
1564
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
163 try: import pygame.joystick |
|
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
164 except (ImportError,IOError):joystick=MissingModule("joystick", geterror(), 1) |
| 314 | 165 |
| 166 try: import pygame.key | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
167 except (ImportError,IOError):key=MissingModule("key", geterror(), 1) |
| 314 | 168 |
| 169 try: import pygame.mouse | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
170 except (ImportError,IOError):mouse=MissingModule("mouse", geterror(), 1) |
| 314 | 171 |
| 172 try: import pygame.sprite | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
173 except (ImportError,IOError):sprite=MissingModule("sprite", geterror(), 1) |
| 314 | 174 |
|
1160
1610e8d6c73e
Added threads.py to __init__.py so is available as pygame.threads. Added in test stubs threads_test.py
akalias
parents:
1079
diff
changeset
|
175 |
|
1564
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
176 try: import pygame.threads |
|
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
177 except (ImportError,IOError):threads=MissingModule("threads", geterror(), 1) |
|
1160
1610e8d6c73e
Added threads.py to __init__.py so is available as pygame.threads. Added in test stubs threads_test.py
akalias
parents:
1079
diff
changeset
|
178 |
|
2136
9de026eb9cab
Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
2116
diff
changeset
|
179 try: import pygame.pixelcopy |
|
9de026eb9cab
Merge the surface_buffer branch back into trunk.
Lenard Lindstrom <len-l@telus.net>
parents:
2116
diff
changeset
|
180 except (ImportError,IOError):pixelcopy=MissingModule("pixelcopy", geterror(), 1) |
|
1160
1610e8d6c73e
Added threads.py to __init__.py so is available as pygame.threads. Added in test stubs threads_test.py
akalias
parents:
1079
diff
changeset
|
181 |
|
1517
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
182 def warn_unwanted_files(): |
|
1520
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
183 """ Used to warn about unneeded old files. |
|
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
184 """ |
|
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
185 |
|
1517
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
186 # a temporary hack to warn about camera.so and camera.pyd. |
|
1518
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
187 install_path= os.path.split(pygame.base.__file__)[0] |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
188 extension_ext = os.path.splitext(pygame.base.__file__)[1] |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
189 |
|
1520
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
190 # here are the .so/.pyd files we need to ask to remove. |
|
1518
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
191 ext_to_remove = ["camera"] |
|
1520
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
192 |
|
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
193 # here are the .py/.pyo/.pyc files we need to ask to remove. |
|
1886
e1fbe720d23f
Disabled old file detection/warning. Added old file remove method to end of setup.py
Rene Dudfield <renesd@gmail.com>
parents:
1871
diff
changeset
|
194 py_to_remove = ["color"] |
|
1819
1d983af0dd1f
Removed color.py warning from Symbian. It is used as wrapper for the native module.
gamedude
parents:
1610
diff
changeset
|
195 |
|
1d983af0dd1f
Removed color.py warning from Symbian. It is used as wrapper for the native module.
gamedude
parents:
1610
diff
changeset
|
196 if os.name == "e32": # Don't warn on Symbian. The color.py is used as a wrapper. |
|
1d983af0dd1f
Removed color.py warning from Symbian. It is used as wrapper for the native module.
gamedude
parents:
1610
diff
changeset
|
197 py_to_remove = [] |
|
1520
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
198 |
|
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
199 # See if any of the files are there. |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
200 extension_files = ["%s%s" % (x, extension_ext) for x in ext_to_remove] |
|
1518
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
201 |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
202 py_files = ["%s%s" % (x, py_ext) |
|
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
203 for py_ext in [".py", ".pyc", ".pyo"] |
|
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
204 for x in py_to_remove] |
|
1518
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
205 |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
206 files = py_files + extension_files |
|
1517
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
207 |
|
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
208 unwanted_files = [] |
|
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
209 for f in files: |
|
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
210 unwanted_files.append( os.path.join( install_path, f ) ) |
|
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
211 |
|
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
212 |
|
1520
6c5176415fd1
add some comments, and a doc string to warn_unwanted_files
Rene Dudfield <renesd@gmail.com>
parents:
1519
diff
changeset
|
213 |
|
1518
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
214 ask_remove = [] |
|
1517
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
215 for f in unwanted_files: |
|
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
216 if os.path.exists(f): |
|
1518
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
217 ask_remove.append(f) |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
218 |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
219 |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
220 if ask_remove: |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
221 message = "Detected old file(s). Please remove the old files:\n" |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
222 |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
223 for f in ask_remove: |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
224 message += "%s " % f |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
225 message += "\nLeaving them there might break pygame. Cheers!\n\n" |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
226 |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
227 try: |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
228 import warnings |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
229 level = 4 |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
230 warnings.warn(message, RuntimeWarning, level) |
|
430ee699d834
made the error message nicer... and added checks for old py files too.
Rene Dudfield <renesd@gmail.com>
parents:
1517
diff
changeset
|
231 except ImportError: |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
232 print (message) |
|
1886
e1fbe720d23f
Disabled old file detection/warning. Added old file remove method to end of setup.py
Rene Dudfield <renesd@gmail.com>
parents:
1871
diff
changeset
|
233 |
|
e1fbe720d23f
Disabled old file detection/warning. Added old file remove method to end of setup.py
Rene Dudfield <renesd@gmail.com>
parents:
1871
diff
changeset
|
234 |
|
e1fbe720d23f
Disabled old file detection/warning. Added old file remove method to end of setup.py
Rene Dudfield <renesd@gmail.com>
parents:
1871
diff
changeset
|
235 # disable, because we hopefully don't need it. |
|
e1fbe720d23f
Disabled old file detection/warning. Added old file remove method to end of setup.py
Rene Dudfield <renesd@gmail.com>
parents:
1871
diff
changeset
|
236 #warn_unwanted_files() |
|
1517
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
237 |
|
ce4602f41c64
Added a runtime check for old unneeded files.
Rene Dudfield <renesd@gmail.com>
parents:
1509
diff
changeset
|
238 |
|
1160
1610e8d6c73e
Added threads.py to __init__.py so is available as pygame.threads. Added in test stubs threads_test.py
akalias
parents:
1079
diff
changeset
|
239 |
| 314 | 240 try: from pygame.surface import * |
| 241 except (ImportError,IOError):Surface = lambda:Missing_Function | |
|
1495
782f92b318e9
Add conditional bufferproxy imports to __init__.py.
Lenard Lindstrom <len-l@telus.net>
parents:
1453
diff
changeset
|
242 |
| 314 | 243 |
|
981
9e7ae3ed0812
Fixed docs for mask module and cleaned up namespace pollution.
marcus
parents:
946
diff
changeset
|
244 try: |
|
9e7ae3ed0812
Fixed docs for mask module and cleaned up namespace pollution.
marcus
parents:
946
diff
changeset
|
245 import pygame.mask |
|
9e7ae3ed0812
Fixed docs for mask module and cleaned up namespace pollution.
marcus
parents:
946
diff
changeset
|
246 from pygame.mask import Mask |
|
809
0ace6eeffe50
changed it so that pygame.Mask is there... and not in locals.
Rene Dudfield <renesd@gmail.com>
parents:
781
diff
changeset
|
247 except (ImportError,IOError):Mask = lambda:Missing_Function |
|
0ace6eeffe50
changed it so that pygame.Mask is there... and not in locals.
Rene Dudfield <renesd@gmail.com>
parents:
781
diff
changeset
|
248 |
|
853
713d52f61c8a
changes for PixelArray I forgot to commit before.
Rene Dudfield <renesd@gmail.com>
parents:
838
diff
changeset
|
249 try: from pygame.pixelarray import * |
|
713d52f61c8a
changes for PixelArray I forgot to commit before.
Rene Dudfield <renesd@gmail.com>
parents:
838
diff
changeset
|
250 except (ImportError,IOError): PixelArray = lambda:Missing_Function |
|
713d52f61c8a
changes for PixelArray I forgot to commit before.
Rene Dudfield <renesd@gmail.com>
parents:
838
diff
changeset
|
251 |
| 539 | 252 try: from pygame.overlay import * |
| 253 except (ImportError,IOError):Overlay = lambda:Missing_Function | |
| 254 | |
| 314 | 255 try: import pygame.time |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
256 except (ImportError,IOError):time=MissingModule("time", geterror(), 1) |
| 314 | 257 |
| 258 try: import pygame.transform | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
259 except (ImportError,IOError):transform=MissingModule("transform", geterror(), 1) |
| 314 | 260 |
| 261 #lastly, the "optional" pygame modules | |
|
3065
0a3be7313aa4
Enable pygame._freetype extension module build by default
Lenard Lindstrom <len-l@telus.net>
parents:
3039
diff
changeset
|
262 if 'PYGAME_FREETYPE' in os.environ: |
|
0a3be7313aa4
Enable pygame._freetype extension module build by default
Lenard Lindstrom <len-l@telus.net>
parents:
3039
diff
changeset
|
263 try: |
|
0a3be7313aa4
Enable pygame._freetype extension module build by default
Lenard Lindstrom <len-l@telus.net>
parents:
3039
diff
changeset
|
264 import pygame.ftfont as font |
|
0a3be7313aa4
Enable pygame._freetype extension module build by default
Lenard Lindstrom <len-l@telus.net>
parents:
3039
diff
changeset
|
265 sys.modules['pygame.font'] = font |
|
0a3be7313aa4
Enable pygame._freetype extension module build by default
Lenard Lindstrom <len-l@telus.net>
parents:
3039
diff
changeset
|
266 except (ImportError,IOError): pass |
| 465 | 267 try: |
| 268 import pygame.font | |
| 269 import pygame.sysfont | |
| 270 pygame.font.SysFont = pygame.sysfont.SysFont | |
| 469 | 271 pygame.font.get_fonts = pygame.sysfont.get_fonts |
| 272 pygame.font.match_font = pygame.sysfont.match_font | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
273 except (ImportError,IOError):font=MissingModule("font", geterror(), 0) |
| 314 | 274 |
|
1394
7d96b3a74f43
try rearranging stuff for py2app
Rene Dudfield <renesd@gmail.com>
parents:
1393
diff
changeset
|
275 # try and load pygame.mixer_music before mixer, for py2app... |
|
7d96b3a74f43
try rearranging stuff for py2app
Rene Dudfield <renesd@gmail.com>
parents:
1393
diff
changeset
|
276 try: |
|
7d96b3a74f43
try rearranging stuff for py2app
Rene Dudfield <renesd@gmail.com>
parents:
1393
diff
changeset
|
277 import pygame.mixer_music |
|
7d96b3a74f43
try rearranging stuff for py2app
Rene Dudfield <renesd@gmail.com>
parents:
1393
diff
changeset
|
278 #del pygame.mixer_music |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
279 #print ("NOTE2: failed importing pygame.mixer_music in lib/__init__.py") |
|
1394
7d96b3a74f43
try rearranging stuff for py2app
Rene Dudfield <renesd@gmail.com>
parents:
1393
diff
changeset
|
280 except (ImportError,IOError): |
|
7d96b3a74f43
try rearranging stuff for py2app
Rene Dudfield <renesd@gmail.com>
parents:
1393
diff
changeset
|
281 pass |
|
7d96b3a74f43
try rearranging stuff for py2app
Rene Dudfield <renesd@gmail.com>
parents:
1393
diff
changeset
|
282 |
| 314 | 283 try: import pygame.mixer |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
284 except (ImportError,IOError):mixer=MissingModule("mixer", geterror(), 0) |
| 314 | 285 |
| 286 try: import pygame.movie | |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
287 except (ImportError,IOError):movie=MissingModule("movie", geterror(), 0) |
| 314 | 288 |
|
781
5ef3852e01b5
commented out scrap, and movieext... since they are both experimental.
Rene Dudfield <renesd@gmail.com>
parents:
743
diff
changeset
|
289 #try: import pygame.movieext |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
290 #except (ImportError,IOError):movieext=MissingModule("movieext", geterror(), 0) |
| 518 | 291 |
|
872
30d0ceb204ba
Added missing module handling for the numpyarray module.
marcus
parents:
853
diff
changeset
|
292 try: import pygame.scrap |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
293 except (ImportError,IOError):scrap=MissingModule("scrap", geterror(), 0) |
|
872
30d0ceb204ba
Added missing module handling for the numpyarray module.
marcus
parents:
853
diff
changeset
|
294 |
|
1564
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
295 try: import pygame.surfarray |
|
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
296 except (ImportError,IOError):surfarray=MissingModule("surfarray", geterror(), 0) |
| 314 | 297 |
|
1564
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
298 try: import pygame.sndarray |
|
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
299 except (ImportError,IOError):sndarray=MissingModule("sndarray", geterror(), 0) |
| 370 | 300 |
| 588 | 301 try: import pygame.fastevent |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
302 except (ImportError,IOError):fastevent=MissingModule("fastevent", geterror(), 0) |
| 588 | 303 |
| 314 | 304 #there's also a couple "internal" modules not needed |
| 305 #by users, but putting them here helps "dependency finder" | |
| 306 #programs get everything they need (like py2exe) | |
|
1564
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
307 try: import pygame.imageext; del pygame.imageext |
|
adf93b55dcd6
undo accidental changes to Setup.in and __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1563
diff
changeset
|
308 except (ImportError,IOError):pass |
| 314 | 309 |
| 567 | 310 def packager_imports(): |
| 311 """ | |
| 312 Some additional things that py2app/py2exe will want to see | |
| 313 """ | |
|
1508
9966a8df94cc
add psuedo-import to __init__.py atexit, required by pygame.base
Lenard Lindstrom <len-l@telus.net>
parents:
1507
diff
changeset
|
314 import atexit |
| 567 | 315 import Numeric |
|
872
30d0ceb204ba
Added missing module handling for the numpyarray module.
marcus
parents:
853
diff
changeset
|
316 import numpy |
| 567 | 317 import OpenGL.GL |
| 743 | 318 import pygame.macosx |
|
1509
b57311dca9a5
remove an accidental colordict import introduced into __init__.py
Lenard Lindstrom <len-l@telus.net>
parents:
1508
diff
changeset
|
319 import pygame.bufferproxy |
| 1507 | 320 import pygame.colordict |
|
3039
2e40a4079266
Bug: _view module omitted by cx_freeze
Lenard Lindstrom <len-l@telus.net>
parents:
3021
diff
changeset
|
321 import pygame._view |
| 314 | 322 |
| 460 | 323 #make Rects pickleable |
|
1549
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
324 try: |
|
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
325 import copy_reg |
|
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
326 except ImportError: |
|
9e3568725e5a
merge src/__init__.py from python3 branch back into trunk
Lenard Lindstrom <len-l@telus.net>
parents:
1520
diff
changeset
|
327 import copyreg as copy_reg |
| 460 | 328 def __rect_constructor(x,y,w,h): |
|
3140
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
329 return Rect(x,y,w,h) |
| 460 | 330 def __rect_reduce(r): |
|
3140
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
331 assert type(r) == Rect |
|
58a1dbbe4940
fix for issue #31 (pygame.error: No available video device)
Temp User@jmmdesk4
parents:
3108
diff
changeset
|
332 return __rect_constructor, (r.x, r.y, r.w, r.h) |
| 460 | 333 copy_reg.pickle(Rect, __rect_reduce, __rect_constructor) |
| 334 | |
| 1869 | 335 |
| 336 #make Colors pickleable | |
| 337 def __color_constructor(r,g,b,a): | |
|
1871
5ec1d9cae68e
and pickle it properly this time. with salt!
Rene Dudfield <renesd@gmail.com>
parents:
1869
diff
changeset
|
338 return Color(r,g,b,a) |
| 1869 | 339 def __color_reduce(c): |
|
1871
5ec1d9cae68e
and pickle it properly this time. with salt!
Rene Dudfield <renesd@gmail.com>
parents:
1869
diff
changeset
|
340 assert type(c) == Color |
| 1869 | 341 return __color_constructor, (c.r, c.g, c.b, c.a) |
|
1871
5ec1d9cae68e
and pickle it properly this time. with salt!
Rene Dudfield <renesd@gmail.com>
parents:
1869
diff
changeset
|
342 copy_reg.pickle(Color, __color_reduce, __color_constructor) |
| 1869 | 343 |
| 344 | |
| 345 | |
| 346 | |
| 314 | 347 #cleanup namespace |
|
2105
297803165311
merge fsencoding branch back into trunk, correcting Unicode file path encoding
Lenard Lindstrom <len-l@telus.net>
parents:
1994
diff
changeset
|
348 del pygame, os, sys, surflock, MissingModule, copy_reg, geterror |
