1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
24 Windows, MacOS, OS X, BeOS, FreeBSD, IRIX, and Linux.
25 """
26
27 import sys, os, string
28
29
30
31 if not 'SDL_VIDEODRIVER' in os.environ:
32
33
34
35
36
37 if hasattr(sys, "getwindowsversion"):
38 try:
39 if (sys.getwindowsversion()[3] in [1,2] and
40 sys.getwindowsversion()[0] in [0,1,2,3,4,5]):
41 os.environ['SDL_VIDEODRIVER'] = 'directx'
42 except:
43 pass
44
45
47 _NOT_IMPLEMENTED_ = True
48 - def __init__(self, name, info='', urgent=0):
49 self.name = name
50 self.info = str(info)
51 try:
52 exc = sys.exc_info()
53 if exc[0] != None:
54 self.reason = "%s: %s" % (exc[0].__name__, str(exc[1]))
55 else:
56 self.reason = ""
57 finally:
58 del exc
59 self.urgent = urgent
60 if urgent:
61 self.warn()
62
64 if not self.urgent:
65 self.warn()
66 self.urgent = 1
67 MissingPygameModule = "%s module not available" % self.name
68 if self.reason:
69 MissingPygameModule += "\n(%s)" % self.reason
70 raise NotImplementedError(MissingPygameModule)
71
74
76 if self.urgent: type = 'import'
77 else: type = 'use'
78 message = '%s %s: %s' % (type, self.name, self.info)
79 if self.reason:
80 message += "\n(%s)" % self.reason
81 try:
82 import warnings
83 if self.urgent: level = 4
84 else: level = 3
85 warnings.warn(message, RuntimeWarning, level)
86 except ImportError:
87 print (message)
88
89
90
91
92
93
94
95 from pygame.base import *
96 from pygame.constants import *
97 from pygame.version import *
98 from pygame.rect import Rect
99 from pygame.compat import geterror
100 import pygame.rwobject
101 import pygame.surflock
102 import pygame.color
103 Color = color.Color
104 __version__ = ver
105
106
107
108 try: import pygame.cdrom
109 except (ImportError,IOError):cdrom=MissingModule("cdrom", geterror(), 1)
110
111 try: import pygame.cursors
112 except (ImportError,IOError):cursors=MissingModule("cursors", geterror(), 1)
113
114 try: import pygame.display
115 except (ImportError,IOError):display=MissingModule("display", geterror(), 1)
116
117 try: import pygame.draw
118 except (ImportError,IOError):draw=MissingModule("draw", geterror(), 1)
119
120 try: import pygame.event
121 except (ImportError,IOError):event=MissingModule("event", geterror(), 1)
122
123 try: import pygame.image
124 except (ImportError,IOError):image=MissingModule("image", geterror(), 1)
125
126 try: import pygame.joystick
127 except (ImportError,IOError):joystick=MissingModule("joystick", geterror(), 1)
128
129 try: import pygame.key
130 except (ImportError,IOError):key=MissingModule("key", geterror(), 1)
131
132 try: import pygame.mouse
133 except (ImportError,IOError):mouse=MissingModule("mouse", geterror(), 1)
134
135 try: import pygame.sprite
136 except (ImportError,IOError):sprite=MissingModule("sprite", geterror(), 1)
137
138
139 try: import pygame.threads
140 except (ImportError,IOError):threads=MissingModule("threads", geterror(), 1)
141
142
144 """ Used to warn about unneeded old files.
145 """
146
147
148 install_path= os.path.split(pygame.base.__file__)[0]
149 extension_ext = os.path.splitext(pygame.base.__file__)[1]
150
151
152 ext_to_remove = ["camera"]
153
154
155 py_to_remove = ["color"]
156
157 if os.name == "e32":
158 py_to_remove = []
159
160
161 extension_files = ["%s%s" % (x, extension_ext) for x in ext_to_remove]
162
163 py_files = ["%s%s" % (x, py_ext)
164 for py_ext in [".py", ".pyc", ".pyo"]
165 for x in py_to_remove]
166
167 files = py_files + extension_files
168
169 unwanted_files = []
170 for f in files:
171 unwanted_files.append( os.path.join( install_path, f ) )
172
173
174
175 ask_remove = []
176 for f in unwanted_files:
177 if os.path.exists(f):
178 ask_remove.append(f)
179
180
181 if ask_remove:
182 message = "Detected old file(s). Please remove the old files:\n"
183
184 for f in ask_remove:
185 message += "%s " % f
186 message += "\nLeaving them there might break pygame. Cheers!\n\n"
187
188 try:
189 import warnings
190 level = 4
191 warnings.warn(message, RuntimeWarning, level)
192 except ImportError:
193 print (message)
194
195
196
197
198
199
200
201 try: from pygame.surface import *
202 except (ImportError,IOError):Surface = lambda:Missing_Function
203
204
205 try:
206 import pygame.mask
207 from pygame.mask import Mask
208 except (ImportError,IOError):Mask = lambda:Missing_Function
209
210 try: from pygame.pixelarray import *
211 except (ImportError,IOError): PixelArray = lambda:Missing_Function
212
213 try: from pygame.overlay import *
214 except (ImportError,IOError):Overlay = lambda:Missing_Function
215
216 try: import pygame.time
217 except (ImportError,IOError):time=MissingModule("time", geterror(), 1)
218
219 try: import pygame.transform
220 except (ImportError,IOError):transform=MissingModule("transform", geterror(), 1)
221
222
223 try:
224 import pygame.font
225 import pygame.sysfont
226 pygame.font.SysFont = pygame.sysfont.SysFont
227 pygame.font.get_fonts = pygame.sysfont.get_fonts
228 pygame.font.match_font = pygame.sysfont.match_font
229 except (ImportError,IOError):font=MissingModule("font", geterror(), 0)
230
231
232 try:
233 import pygame.mixer_music
234
235
236 except (ImportError,IOError):
237 pass
238
239 try: import pygame.mixer
240 except (ImportError,IOError):mixer=MissingModule("mixer", geterror(), 0)
241
242 try: import pygame.movie
243 except (ImportError,IOError):movie=MissingModule("movie", geterror(), 0)
244
245
246
247
248 try: import pygame.scrap
249 except (ImportError,IOError):scrap=MissingModule("scrap", geterror(), 0)
250
251 try: import pygame.surfarray
252 except (ImportError,IOError):surfarray=MissingModule("surfarray", geterror(), 0)
253
254 try: import pygame.sndarray
255 except (ImportError,IOError):sndarray=MissingModule("sndarray", geterror(), 0)
256
257 try: import pygame.fastevent
258 except (ImportError,IOError):fastevent=MissingModule("fastevent", geterror(), 0)
259
260
261
262
263 try: import pygame.imageext; del pygame.imageext
264 except (ImportError,IOError):pass
265
267 """
268 Some additional things that py2app/py2exe will want to see
269 """
270 import atexit
271 import Numeric
272 import numpy
273 import OpenGL.GL
274 import pygame.macosx
275 import pygame.mac_scrap
276 import pygame.bufferproxy
277 import pygame.colordict
278
279
280 try:
281 import copy_reg
282 except ImportError:
283 import copyreg as copy_reg
287 assert type(r) == Rect
288 return __rect_constructor, (r.x, r.y, r.w, r.h)
289 copy_reg.pickle(Rect, __rect_reduce, __rect_constructor)
290
291
292
294 return Color(r,g,b,a)
296 assert type(c) == Color
297 return __color_constructor, (c.r, c.g, c.b, c.a)
298 copy_reg.pickle(Color, __color_reduce, __color_constructor)
299
300
301
302
303
304 del pygame, os, sys, rwobject, surflock, MissingModule, copy_reg, geterror
305