Commits

bob  committed 123e718

Fix Mac OS X build and scrap module

  • Participants
  • Parent commits 1708ac6

Comments (0)

Files changed (5)

 IMAGE = -lSDL_image
 MIXER = -lSDL_mixer
 SMPEG = -lsmpeg
+PNG = -lpng
+JPEG = -ljpeg
 NUMERIC = -I/usr/include/python2.0/Numeric
 #--EndConfig
 
 #everything you can, but you can ignore ones you don't have
 #dependencies for, just comment them out
 
-imageext src/imageext.c $(SDL) $(IMAGE)
+imageext src/imageext.c $(SDL) $(IMAGE) $(PNG) $(JPEG)
 font src/font.c $(SDL) $(FONT)
 mixer src/mixer.c $(SDL) $(MIXER)
 mixer_music src/music.c $(SDL) $(MIXER)
 surfarray src/surfarray.c $(SDL) $(NUMERIC)
 sndarray src/sndarray.c $(SDL) $(NUMERIC) $(MIXER)
 movie src/movie.c $(SDL) $(SMPEG)
+scrap src/scrap.c $(SDL)
 
 #experimental new movie movie. requires libavcodec and libavformat.
 #add any necessary compile flags to this line and uncomment.

File config_darwin.py

 from distutils.sysconfig import get_python_inc
 
 class Dependency:
-    libext = '.dylib'
+    libext = '.a'
     def __init__(self, name, checkhead, checklib, lib):
         self.name = name
         self.inc_dir = None
         self.lib_dir = None
         self.lib = lib
         self.found = 0
-        self.checklib = checklib+self.libext
+        self.checklib = checklib + self.libext
         self.checkhead = checkhead
         self.cflags = ''
 
 
 class FrameworkDependency(Dependency):
     def configure(self, incdirs, libdirs):
-      for n in '/Library/Frameworks/','$HOME/Library/Frameworks/','/System/Library/Frameworks/':
-        n = os.path.expandvars(n)
-        if os.path.isfile(n+self.lib+'.framework/Versions/Current/'+self.lib):
-          print 'Framework '+self.lib+' found'
-          self.found = 1
-          self.inc_dir = n+self.lib+'.framework/Versions/Current/Headers'
-          self.cflags = '-Xlinker "-framework" -Xlinker "'+self.lib+'"'
-          self.cflags += ' -Xlinker "-F'+n+'"'
-          self.origlib = self.lib
-          self.lib = ''
-          return
-      print 'Framework '+self.lib+' not found'
+        BASE_DIRS = '/', os.path.expanduser('~/'), '/System/'
+        for n in BASE_DIRS:
+            n += 'Library/Frameworks/'
+            fmwk = n + self.lib + '.framework/Versions/Current/'
+            if os.path.isfile(fmwk + self.lib):
+                print 'Framework ' + self.lib + ' found'
+                self.found = 1
+                self.inc_dir = fmwk + 'Headers'
+                self.cflags = (
+                    '-Xlinker "-framework" -Xlinker "' + self.lib + '"' +
+                    ' -Xlinker "-F' + n + '"')
+                self.origlib = self.lib
+                self.lib = ''
+                return
+        print 'Framework ' + self.lib + ' not found'
 
 
 class DependencyPython:
     FrameworkDependency('IMAGE', 'SDL_image.h', 'libSDL_image', 'SDL_image'),
     FrameworkDependency('MIXER', 'SDL_mixer.h', 'libSDL_mixer', 'SDL_mixer'),
     FrameworkDependency('SMPEG', 'smpeg.h', 'libsmpeg', 'smpeg'),
-    DependencyPython('NUMERIC', 'Numeric', 'Numeric/arrayobject.h')
+    DependencyPython('NUMERIC', 'Numeric', 'Numeric/arrayobject.h'),
+    Dependency('PNG', 'png.h', 'libpng', 'png'),
+    Dependency('JPEG', 'jpeglib.h', 'libjpeg', 'jpeg'),
 ]
 
 
-from distutils.util import split_quoted
 def main():
     global DEPS
 
     print 'Hunting dependencies...'
-    incdirs = []
-    libdirs = []
+    incdirs = ['/usr/local/include']
+    libdirs = ['/usr/local/lib']
     newconfig = []
     for d in DEPS:
-      d.configure(incdirs, libdirs)
+        d.configure(incdirs, libdirs)
     DEPS[0].cflags = '-Ddarwin '+ DEPS[0].cflags
     try:
         import objc

File lib/__init__.py

 except (ImportError,IOError), msg:sprite=MissingModule("sprite", msg, 1)
 
 try: import pygame.scrap
-except (ImportError,IOError), msg:sprite=MissingModule("scrap", msg, 1)
-
-if sys.platform == 'darwin':
-    try:
-        import pygame.mac_scrap
-        pygame.mac_scrap.put.__doc__ = pygame.scrap.put.__doc__
-        pygame.mac_scrap.get.__doc__ = pygame.scrap.get.__doc__
-        pygame.mac_scrap.lost.__doc__ = pygame.scrap.lost.__doc__
-        pygame.mac_scrap.init.__doc__ = pygame.scrap.init.__doc__
-
-        pygame.scrap.put = pygame.mac_scrap.put
-        pygame.scrap.get = pygame.mac_scrap.get
-        pygame.scrap.lost = pygame.mac_scrap.lost
-        pygame.scrap.init = pygame.mac_scrap.init
-    except:
-        pass
-    
-
+except (ImportError,IOError), msg:scrap=MissingModule("scrap", msg, 1)
 
 try: from pygame.surface import *
 except (ImportError,IOError):Surface = lambda:Missing_Function
     """
     Some additional things that py2app/py2exe will want to see
     """
-    import pygame.macosx
     import Numeric
     import OpenGL.GL
+    import pygame.macosx
+    import pygame.mac_scrap
 
 #make Rects pickleable
 import copy_reg

File lib/mac_scrap.py

-#NOTE: the docs for this will be inserted from the scrap.doc file.  
-#        see pygame/__init__.py
-try:
-    from AppKit import *
-    from Foundation import *
-except:
-    pass
+#
+# These methods are called internally by pygame.scrap
+#
+from AppKit import *
+from Foundation import *
 
 import pygame.locals
 
-
+ScrapPboardType = u'org.pygame.scrap'
 
 def init():
-    # FIXME: NOTE: I don't know what type of init we need here.
     return 1
 
 def get(scrap_type):
     if scrap_type == pygame.locals.SCRAP_TEXT:
-	board = NSPasteboard.generalPasteboard()
-	content = board.stringForType_(NSStringPboardType)
-	return content
+        board = NSPasteboard.generalPasteboard()
+        content = board.stringForType_(NSStringPboardType)
+        return content
     else:
-        raise "Unsupported scrap_type"
+        raise ValueError("Unsupported scrap_type: %r" % (scrap_type,))
 
 
 def put(scrap_type, thing):
     if scrap_type == pygame.locals.SCRAP_TEXT:
         board = NSPasteboard.generalPasteboard()
-        board.declareTypes_owner_([NSStringPboardType], None)
-        board.setString_forType_(unicode(thing), NSStringPboardType)
+        board.declareTypes_owner_([NSStringPboardType, ScrapPboardType], None)
+        if isinstance(thing, unicode):
+            text_thing = thing
+        else:
+            text_thing = unicode(text_thing, 'utf-8')
+        board.setString_forType_(text_thing, NSStringPboardType)
+        board.setString_forType_(u'', ScrapPboardType)
     else:
-        raise "Unsupported scrap_type"
+        raise ValueError("Unsupported scrap_type: %r" % (scrap_type,))
 
 def lost():
-    #FIXME: TODO: how do we do this on mac?
-    return 0
-    pass
-
-
+    board = NSPasteboard.generalPasteboard()
+    return not board.availableTypeFromArray_([ScrapPboardType])
     #error Unknown window manager for clipboard handling
 #endif /* scrap type */
 
+/* MAC_SCRAP delegates all functionality, we just need a small stub */
+#if !defined(MAC_SCRAP)
+
 /* System dependent data types */
 #if defined(X11_SCRAP)
 /* * */
 /* * */
 static unsigned short InputGroup;
 
-#endif /* scrap type */
+#endif
+
 
 #define FORMAT_PREFIX	"SDL_scrap_0x"
 
     }
 }
 
+#endif /* !defined(MAC_SCRAP) */
+
+#if defined(MAC_SCRAP)
+
+static PyObject *
+mac_scrap_call(char *name, PyObject *args) {
+	static PyObject *mac_scrap_module = NULL;
+	PyObject *method;
+	PyObject *result;
+	if (mac_scrap_module == NULL) {
+		mac_scrap_module = PyImport_ImportModule("pygame.mac_scrap");
+		if (mac_scrap_module == NULL) {
+			return NULL;
+		}
+	}
+	method = PyObject_GetAttrString(mac_scrap_module, name);
+	if (method == NULL) {
+		return NULL;
+	}
+	result = PyObject_CallObject(method, args);
+	Py_DECREF(method);
+	return result;
+}
+
+static PyObject *
+scrap_init(PyObject *self, PyObject *args) {
+	return mac_scrap_call("init", args);
+}
+
+static PyObject *
+scrap_get_scrap(PyObject *self, PyObject *args) {
+	return mac_scrap_call("get", args);
+}
+
+static PyObject *
+scrap_put_scrap(PyObject *self, PyObject *args) {
+	return mac_scrap_call("put", args);
+}
+
+static PyObject *
+scrap_lost_scrap(PyObject *self, PyObject *args) {
+	return mac_scrap_call("lost", args);
+}
+
+#endif /* defined(MAC_SCRAP) */
 
 static PyMethodDef scrap_builtins[] =
 {
 	{ NULL, NULL }
 };
 
-
 PYGAME_EXPORT
 void initscrap(void)
 {