Commits

aholkner  committed f6c1a23

Fixes to display init, rectangle parsing, default font, font rwops.

  • Participants
  • Parent commits 5a384f9
  • Branches ctypes-soc

Comments (0)

Files changed (7)

File pygame/base.py

     fail = 0
 
     SDL.SDL_Init(SDL.SDL_INIT_EVENTTHREAD | SDL.SDL_INIT_TIMER)
+
+    if _video_autoinit():
+        success += 1
+    else:
+        fail += 1
+
     for mod in sys.modules.values():
         if hasattr(mod, '__PYGAMEinit__') and callable(mod.__PYGAMEinit__):
             try:

File pygame/display.py

     When using an pygame.OPENGL display mode this will perform a gl buffer
     swap.
     '''
+    _video_init_check()
     screen = SDL_GetVideoSurface()
     if not screen:
         raise pygame.base.error, 'Display mode not set'
     # Undocumented: also allows argument tuple to represent one rect;
     # e.g. update(0, 0, 10, 10) or update((0, 0), (10, 10))
 
+    _video_init_check()
     screen = SDL_GetVideoSurface()
     if not screen:
         raise pygame.base.error, 'Display mode not set'
 
     :rtype: str
     '''
+    _video_init_check()
     return SDL_VideoDriverName()
 
 def Info():
     :see: `VideoInfo`
     :rtype: `VideoInfo`
     '''
+    _video_init_check()
     return VideoInfo()
 
 class VideoInfo:
     :note: Currently unimplemented, returns an empty dict.
     :rtype: dict
     '''
+    _video_init_check()
     return {}
 
 def list_modes(depth=0, flags=pygame.constants.FULLSCREEN):
     :rtype: list of (int, int), or -1
     :return: list of (width, height) pairs, or -1 if any mode is suitable.
     '''
+    _video_init_check()
     format = SDL_PixelFormat()
     format.BitsPerPixel = depth
 
     :return: depth, in bits per pixel, or 0 if the requested mode cannot be
         set.
     '''
+    _video_init_check()
     if not depth:
         depth = SDL_GetVideoInfo().vfmt.BitsPerPixel
     return SDL_VideoModeOK(size[0], size[1], depth, flags)
      - `value`: int
 
     '''
+    _video_init_check()
     SDL_GL_SetAttribute(flag, value)
 
 def gl_get_attribute(flag):
 
     :rtype: int
     '''
+    _video_init_check()
     return SDL_GL_GetAttribute(flag)
 
 def get_active():
     :rtype: bool
     :return: True on success
     '''
+    _video_init_check()
     try:
         SDL_WM_IconifyWindow()
         return True
 
     :rtype: bool
     '''
+    _video_init_check()
     screen = SDL_GetVideoSurface()
     try:
         SDL_WM_ToggleFullScreen(screen)
 
     :rtype: bool
     '''
+    _video_init_check()
     if not green or not blue:
         green = red
         blue = red
 
     :rtype: bool
     '''
+    _video_init_check()
     try:
         SDL_SetGammaRamp(red, green, blue)
         return True
             Sequence having at most 256 RGB triplets.
 
     '''
+    _video_init_check()
     surf = SDL_GetVideoSurface()
     if not surf:
         raise pygame.base.error, 'No display mode is set'
     lenth = min(surf.format.palette.ncolors, len(palette))
     colors = [SDL_Color(r, g, b) for r, g, b in palette[:length]]
     SDL_SetPalette(surf, SDL_PHYSPAL, colors, 0)
+
+def _video_init_check():
+    if not SDL_WasInit(SDL_INIT_VIDEO):
+        raise pygame.base.error, 'video system not initialized'
+

File pygame/event.py

 from SDL import *
 import pygame.base
 import pygame.constants
-
-def _video_init_check():
-    if not SDL_WasInit(SDL_INIT_VIDEO):
-        raise pygame.base.error, 'video system not initialized'
+import pygame.display
 
 def pump():
     '''Internally process pygame event handlers.
     If you fail to make a call to the event queue for too long, the system may
     decide your program has locked up.
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
     SDL_PumpEvents()
 
 def get(typelist=None):
 
     :rtype: list of `Event`
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
     
     if not typelist:
         mask = SDL_ALLEVENTS
 
     :rtype: Event
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     event = SDL_PollEventAndReturn()
     if event:
 
     :rtype: Event
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     return Event(0, sdl_event=SDL_WaitEventAndReturn())
 
 
     :rtype: bool
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     if not typelist:
         mask = SDL_ALLEVENTS
             Event type or list of event types to remove.
     
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
     
     if not typelist:
         mask = SDL_ALLEVENTS
             Event type or list of event types to disallow.
 
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     if typelist == None:
         SDL_EventState(SDL_ALLEVENTS, SDL_IGNORE)
             Event type or list of event types to disallow.
 
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     if typelist == None:
         SDL_EventState(SDL_ALLEVENTS, SDL_ENABLE)
 
     :rtype: int
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     if typelist == None:
         return SDL_EventState(SDL_ALLEVENTS, SDL_QUERY) == SDL_ENABLE
      - `grab`: bool
 
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     if grab:
         SDL_WM_GrabInput(SDL_GRAB_ON)
 
     :rtype: bool
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     return SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON
 
     '''
     global _user_event_nextid
 
-    _video_init_check()
+    pygame.display._video_init_check()
 
     sdl_event = SDL_Event(pygame.constants.USEREVENT)
     sdl_event.code = _USEROBJECT_CHECK1

File pygame/font.py

 from SDL.ttf import *
 
 import pygame.base
+import pygame.pkgdata
 
 _font_initialized = 0
 _font_defaultname = 'freesansbold.ttf'
     return _font_defaultname
 
 class Font(object):
-    __slots__ = ['_font']
+    __slots__ = ['_font', '_rw']
 
     def __init__(self, file, size):
         '''Create a new Font object from a file.
         if not _font_initialized:
             raise pygame.base.error, 'font not initialized'
 
-        size = max(1, size)
+        if not file:
+            file = pygame.pkgdata.getResource(_font_defaultname)
+            size *= 0.6875  # XXX Peter's phone number??
 
-        if not file:
-            raise NotImplemented, 'TODO: default font'
+        size = int(max(1, size))
 
         if hasattr(file, 'read'):
             rw = SDL_RWFromObject(file)
-            # XXX: Differ from pygame: don't freesrc here
-            font = TTF_OpenFontRW(rw, 0, size)
+            # Keep the RWops around, the callbacks will be used long for
+            # the duration of this Font instance.
+            self._rw = rw
+            font = TTF_OpenFontRW(rw, 1, size)
         else:
             font = TTF_OpenFont(file, size)
         self._font = font
         '''
         return TTF_GetFontStyle(self._font) & TTF_STYLE_BOLD != 0
 
-    def set_italic(self):
+    def set_italic(self, italic):
         '''Enable fake rendering of italic text.
 
         Enables fake rendering of italic text. This is a fake skewing of the

File pygame/mouse.py

 
 from SDL import *
 import pygame.base
-
-def _video_init_check():
-    if not SDL_WasInit(SDL_INIT_VIDEO):
-        raise pygame.base.error, 'video system not initialized'
+import pygame.display
 
 def get_pressed():
     '''Get the state of the mouse buttons.
     :rtype: int, int, int
     :return: left, middle, right
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     state, x, y = SDL_GetMouseState()
     return state & SDL_BUTTON(1), state & SDL_BUTTON(2), state & SDL_BUTTON(3)
     :rtype: int, int
     :return: X, Y
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     state, x, y = SDL_GetMouseState()
     return x, y
     :rtype: int, int
     :return: X, Y
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     return SDL_GetRelativeMouseState()
 
             Tuple of X, Y coordinates.
 
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     x, y = pos
     SDL_WarpMouse(x, y)
             If True, the mouse cursor will be visible.
 
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     # XXX Differ from pygame: no return value here
     SDL_ShowCursor(visible)
     
     :rtype: bool
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     return SDL_GetAppState() & SDL_APPMOUSEFOCUS != 0
 
             Bitmask of mask: transparent if 0, solid if 1
 
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     w, h = size
     spotx, spoty = hotspot
     :rtype: tuple, tuple, list, list
     :return: size, hotspot, xormasks, andmasks
     '''
-    _video_init_check()
+    pygame.display._video_init_check()
 
     cursor = SDL_GetCursor()
 

File pygame/rect.py

         except TypeError:
             return None
 
-    def move(self, x, y):
+    def move(self, *pos):
+        x, y = _two_ints_from_args(pos)
         return Rect(self._r.x + x, self._r.y + y, self._r.w, self._r.h)
 
-    def move_ip(self, x, y):
+    def move_ip(self, *pos):
+        x, y = _two_ints_from_args(pos)
         self._r.x += x
         self._r.y += y
 
 def _rect_collide(a, b):
     return a.x + a.w > b.x and b.x + b.w > a.x and \
            a.y + a.h > b.y and b.y + b.h > b.y
+
+def _two_ints_from_args(arg):
+    if len(arg) == 1:
+        return _two_ints_from_args(arg[0])
+    else:
+        return arg[:2]

File pygame/surface.py

         :rtype: Rect
         '''
         rect = pygame.rect.Rect(0, 0, self._surf.w, self._surf.h)
-        for key, value in kwargs:
-            rect.setattr(rect, key, value)
+        for key, value in kwargs.items():
+            setattr(rect, key, value)
         return rect
 
     def get_bitsize(self):