Skip to content

Commit

Permalink
some work on Python3 compatibility. yet incomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
albertz committed Oct 4, 2011
1 parent 5e1488e commit 4f6c626
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
9 changes: 6 additions & 3 deletions SDL/__init__.py
Expand Up @@ -90,7 +90,6 @@ def start(app_main = None):
from Foundation import NSAutoreleasePool, NSObject
except ImportError:
using_cocoapy = True
import cocoapy as cp

if not using_cocoapy:
pool = NSAutoreleasePool.alloc().init()
Expand Down Expand Up @@ -119,8 +118,12 @@ def activateNow_(self, aNotification):
if app_main is not None:
NSApp().run()
del pool
else:
import cocoapy as cp
else: # use CocoaPy
if sys.version_info.major == 2:
import cocoapy as cp
else:
from . import cocoapy
cp = cocoapy
init_SDL_dll("/Library/Frameworks/SDL.framework/SDL", "/Library/Frameworks/SDL.framework/Headers")
init_SDLImage_dll("/Library/Frameworks/SDL_image.framework/SDL_image", "/Library/Frameworks/SDL_image.framework/Headers")
print('Done loading SDL')
Expand Down
12 changes: 7 additions & 5 deletions SDL/cocoapy/__init__.py
Expand Up @@ -29,9 +29,11 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

from runtime import objc, send_message, send_super
from runtime import get_selector
from runtime import ObjCClass, ObjCInstance, ObjCSubclass
import sys

from cocoatypes import *
from cocoalibs import *
from .runtime import objc, send_message, send_super
from .runtime import get_selector
from .runtime import ObjCClass, ObjCInstance, ObjCSubclass

from .cocoatypes import *
from .cocoalibs import *
6 changes: 3 additions & 3 deletions SDL/cocoapy/cocoalibs.py
@@ -1,8 +1,8 @@
from ctypes import *
from ctypes import util

from runtime import send_message, ObjCInstance
from cocoatypes import *
from .runtime import send_message, ObjCInstance
from .cocoatypes import *

######################################################################

Expand Down Expand Up @@ -85,7 +85,7 @@ def cfnumber_to_float(cfnumber):
NSApplicationDidUnhideNotification = c_void_p.in_dll(appkit, 'NSApplicationDidUnhideNotification')

# /System/Library/Frameworks/AppKit.framework/Headers/NSEvent.h
NSAnyEventMask = 0xFFFFFFFFL # NSUIntegerMax
NSAnyEventMask = 0xFFFFFFFF # NSUIntegerMax

NSKeyDown = 10
NSKeyUp = 11
Expand Down
2 changes: 1 addition & 1 deletion SDL/cocoapy/cocoatypes.py
@@ -1,7 +1,7 @@
from ctypes import *

import sys, platform
__LP64__ = (sys.maxint > 2**32)
__LP64__ = (sys.maxsize > 2**32)
__i386__ = (platform.machine() == 'i386')

PyObjectEncoding = '{PyObject=@}'
Expand Down
7 changes: 5 additions & 2 deletions SDL/cocoapy/runtime.py
Expand Up @@ -36,16 +36,19 @@
from ctypes import *
from ctypes import util

from cocoatypes import *
from .cocoatypes import *

__LP64__ = (sys.maxint > 2**32)
__LP64__ = (sys.maxsize > 2**32)
__i386__ = (platform.machine() == 'i386')

if sizeof(c_void_p) == 4:
c_ptrdiff_t = c_int32
elif sizeof(c_void_p) == 8:
c_ptrdiff_t = c_int64

if sys.version_info.major >= 3:
basestring = str

######################################################################

objc = cdll.LoadLibrary(util.find_library('objc'))
Expand Down

0 comments on commit 4f6c626

Please sign in to comment.