Commits

aholkner  committed 6160987

Fixes to event, rect, surface; see changelog

  • Participants
  • Parent commits 4bee23b
  • Branches ctypes-soc

Comments (0)

Files changed (8)

  - SDL_INIT_NOPARACHUTE init flag passed
  - Many functions now silently downcast floats to ints (yuk)
  - Added pygame_icon.bmp, missing from previous distribution
+ - Added freesansbold.ttf, missing from previous distribution
+ - pygame.display.update() no longer confuses a length-2 list of
+   rects with a rect of two tuples.
+ - Added 'x' and 'y' properties to Rect
+ - Fix typemask list argument in event functions
+ - 'dict' attribute added to Event 
+ - Fix user-posted event handling
 
 SDL-ctypes 0.07
 ---------------

File SDL/events.py

         SDL.constants.SDL_SYSWMEVENT: (SDL_SysWMEvent, 'syswm')
     }
 
+    def __init__(self, typecode):
+        self.type = typecode
+
     def __repr__(self):
         if self.type in self.types:
             return self.types[self.type][0].__repr__(self)

File SDL/mixer.py

         _channelfinished_ref = _Mix_ChannelFinishedFunc(channel_finished)
     else:
         _channelfinished_ref = _Mix_ChannelFinishedFunc()
-    _Mix_ChannelFinished(cfunc)
+    _Mix_ChannelFinished(_channelfinished_ref)
 
 _Mix_EffectFunc = CFUNCTYPE(None, c_int, POINTER(c_ubyte), c_int, c_void_p)
 def _make_Mix_EffectFunc(func, udata):
 
 pygame:
 mac default icon
+search libs e.g. SDL_ttf-2.0 before SDL_ttf

File pygame/event.py

     '''
     pygame.display._video_init_check()
     
-    if not typelist:
+    if typelist is None:
         mask = SDL_ALLEVENTS
     else:
         if hasattr(typelist, '__len__'):
-            mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist)
+            mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist, 0)
         else:
             mask = int(typelist)
 
     '''
     pygame.display._video_init_check()
 
-    if not typelist:
+    if typelist is None:
         mask = SDL_ALLEVENTS
     else:
         if hasattr(typelist, '__len__'):
-            mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist)
+            mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist, 0)
         else:
             mask = SDL_EVENTMASK(int(typelist))
     
     SDL_PumpEvents()
     events = SDL_PeepEvents(1, SDL_PEEKEVENT, mask)
 
-    if not typelist:
+    if typelist is None:
         if events:
-            return Event(0, sdl_event=events[0])
+            return Event(0, sdl_event=events[0], keep_userdata=True)
         else:
             return Event(pygame.locals.NOEVENT) # XXX deviation from pygame
     return len(events) > 0
     '''
     pygame.display._video_init_check()
     
-    if not typelist:
+    if typelist is None:
         mask = SDL_ALLEVENTS
     else:
         if hasattr(typelist, '__len__'):
-            mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist)
+            mask = reduce(lambda a,b: a | SDL_EVENTMASK(b), typelist, 0)
         else:
             mask = int(typelist)
 
     If None is passed as the argument, this has the opposite effect and none of
     the event types are allowed to be placed on the queue.
 
+    :note: events posted with `post` will not be blocked.
+
     :Parameters:
         `typelist` : int or sequence of int or None
             Event type or list of event types to disallow.
     '''
     pygame.display._video_init_check()
 
-    if typelist == None:
+    if typelist is None:
         SDL_EventState(SDL_ALLEVENTS, SDL_IGNORE)
     elif hasattr(typelist, '__len__'):
         for val in typelist:
     '''
     pygame.display._video_init_check()
 
-    if typelist == None:
+    if typelist is None:
         SDL_EventState(SDL_ALLEVENTS, SDL_ENABLE)
     elif hasattr(typelist, '__len__'):
         for val in typelist:
     else:
         SDL_EventState(typelist, SDL_ENABLE)
 
-def get_blocked(event_type):
+def get_blocked(typelist):
     '''Test if a type of event is blocked from the queue.
 
     Returns true if the given event type is blocked from the queue.
 
     return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON
 
-_USEROBJECT_CHECK1 = 0xdeadbeef
+_USEROBJECT_CHECK1 = c_int(0xdeadbeef).value  # signed
 _USEROBJECT_CHECK2 = 0xfeedf00d
 _user_event_objects = {}
-_user_event_nextid = 0
+_user_event_nextid = 1
     
 def post(event):
     '''Place a new event on the queue.
 
     pygame.display._video_init_check()
 
-    sdl_event = SDL_Event(pygame.locals.USEREVENT)
-    sdl_event.code = _USEROBJECT_CHECK1
-    sdl_event.data1 = c_void_p(_USEROBJECT_CHECK2)
-    sdl_event.data2 = c_void_p(_user_event_nextid)
+    sdl_event = SDL_Event(event.type)
+    sdl_event.user.code = _USEROBJECT_CHECK1
+    sdl_event.user.data1 = c_void_p(_USEROBJECT_CHECK2)
+    sdl_event.user.data2 = c_void_p(_user_event_nextid)
     _user_event_objects[_user_event_nextid] = event
     _user_event_nextid += 1
 
 
         '''
         if sdl_event:
-            if sdl_event.type == pygame.locals.USEREVENT and \
-               sdl_event.code == _USEROBJECT_CHECK1 and \
-               sdl_event.data1.value == _USEROBJECT_CHECK2 and \
-               sdl_event.data2.value in _user_event_objects:
+            uevent = cast(pointer(sdl_event), POINTER(SDL_UserEvent)).contents
+            if uevent.code == _USEROBJECT_CHECK1 and \
+               uevent.data1.value == _USEROBJECT_CHECK2 and \
+               uevent.data2.value in _user_event_objects:
                 # An event that was posted; grab dict from local store.
                 id = sdl_event.data2.value
                 for key, value in _user_event_objects[id].items():
             for key, value in attributes.items():
                 setattr(self, key, value)
 
+        # Bizarre undocumented but used by some people.
+        self.dict = self.__dict__
+
     def __repr__(self):
         d = copy(self.__dict__)
         del d['type']

File pygame/rect.py

                                                             int(args[1]),
                                                             int(args[2]),
                                                             int(args[3])))
-        elif len(args) == 2:
+        elif len(args) == 2 and len(args[0]) == 2 and len(args[1]) == 2:
             if args[1][0] < 0 or args[1][1] < 0:
                 object.__setattr__(self, '_r', 
                                    _RectProxy((int(args[0][0]), 
         return self._r.w != 0 and self._r.h != 0
 
     def __getattr__(self, name):
-        if name == 'top':
+        if name in ('top', 'y'):
             return self._r.y
-        elif name == 'left':
+        elif name in ('left', 'x'):
             return self._r.x
         elif name == 'bottom':
             return self._r.y + self._r.h

File pygame/surface.py

         surf = self._surf
         return SDL_GetRGBA(mapped, surf.format)
         
-    def set_clip(self, rect=None):
+    def set_clip(self, *rect):
         '''Set the current clipping area of the Surface.
 
         Each Surface has an active clipping area. This is a rectangle that

File pygame/transform.py

         raise NotImplementedError, 'Python imaging library (PIL) required.'
     
     # XXX: Differ from Pygame: subsurfaces permitted.
-    width, height = size
+    width, height = int(size[0]), int(size[1])
     if width < 0 or height < 0:
         raise ValueError, 'Cannot scale to negative size'