From 7d0a609e6f43b82f3aeeefcb0574f3c1e4b09ad4 Mon Sep 17 00:00:00 2001
From: Jack Jansen <jack.jansen@cwi.nl>
Date: Tue, 2 Dec 2003 23:01:43 +0000
Subject: An interface to the LaunchServices API.

---
 Lib/plat-mac/Carbon/LaunchServices.py |  65 ++++++
 Mac/Modules/launch/_Launchmodule.c    | 401 ++++++++++++++++++++++++++++++++++
 Mac/Modules/launch/launchscan.py      |  71 ++++++
 Mac/Modules/launch/launchsupport.py   | 111 ++++++++++
 setup.py                              |   2 +
 5 files changed, 650 insertions(+)
 create mode 100644 Lib/plat-mac/Carbon/LaunchServices.py
 create mode 100644 Mac/Modules/launch/_Launchmodule.c
 create mode 100644 Mac/Modules/launch/launchscan.py
 create mode 100644 Mac/Modules/launch/launchsupport.py

diff --git a/Lib/plat-mac/Carbon/LaunchServices.py b/Lib/plat-mac/Carbon/LaunchServices.py
new file mode 100644
index 0000000..7131d09
--- /dev/null
+++ b/Lib/plat-mac/Carbon/LaunchServices.py
@@ -0,0 +1,65 @@
+# Generated from 'LaunchServices.h'
+
+def FOUR_CHAR_CODE(x): return x
+kLSRequestAllInfo = -1
+kLSRolesAll = -1
+kLSUnknownErr = -10810
+kLSNotAnApplicationErr = -10811
+kLSNotInitializedErr = -10812
+kLSDataUnavailableErr = -10813
+kLSApplicationNotFoundErr = -10814
+kLSUnknownTypeErr = -10815
+kLSDataTooOldErr = -10816
+kLSDataErr = -10817
+kLSLaunchInProgressErr = -10818
+kLSNotRegisteredErr = -10819
+kLSAppDoesNotClaimTypeErr = -10820
+kLSAppDoesNotSupportSchemeWarning = -10821
+kLSServerCommunicationErr = -10822 
+kLSInitializeDefaults = 0x00000001
+kLSRequestExtension = 0x00000001
+kLSRequestTypeCreator = 0x00000002
+kLSRequestBasicFlagsOnly = 0x00000004
+kLSRequestAppTypeFlags = 0x00000008
+kLSRequestAllFlags = 0x00000010
+kLSRequestIconAndKind = 0x00000020
+# kLSRequestAllInfo = (unsigned long)0xFFFFFFFF 
+kLSItemInfoIsPlainFile = 0x00000001
+kLSItemInfoIsPackage = 0x00000002
+kLSItemInfoIsApplication = 0x00000004
+kLSItemInfoIsContainer = 0x00000008
+kLSItemInfoIsAliasFile = 0x00000010
+kLSItemInfoIsSymlink = 0x00000020
+kLSItemInfoIsInvisible = 0x00000040
+kLSItemInfoIsNativeApp = 0x00000080
+kLSItemInfoIsClassicApp = 0x00000100
+kLSItemInfoAppPrefersNative = 0x00000200
+kLSItemInfoAppPrefersClassic = 0x00000400
+kLSItemInfoAppIsScriptable = 0x00000800
+kLSItemInfoIsVolume = 0x00001000 
+kLSRolesNone = 0x00000001
+kLSRolesViewer = 0x00000002
+kLSRolesEditor = 0x00000004
+# kLSRolesAll = (unsigned long)0xFFFFFFFF
+kLSUnknownKindID = 0
+kLSUnknownType = 0
+kLSUnknownCreator = 0
+kLSAcceptDefault = 0x00000001
+kLSAcceptAllowLoginUI = 0x00000002
+kLSLaunchDefaults = 0x00000001
+kLSLaunchAndPrint = 0x00000002
+kLSLaunchReserved2 = 0x00000004
+kLSLaunchReserved3 = 0x00000008
+kLSLaunchReserved4 = 0x00000010
+kLSLaunchReserved5 = 0x00000020
+kLSLaunchReserved6 = 0x00000040
+kLSLaunchInhibitBGOnly = 0x00000080
+kLSLaunchDontAddToRecents = 0x00000100
+kLSLaunchDontSwitch = 0x00000200
+kLSLaunchNoParams = 0x00000800
+kLSLaunchAsync = 0x00010000
+kLSLaunchStartClassic = 0x00020000
+kLSLaunchInClassic = 0x00040000
+kLSLaunchNewInstance = 0x00080000
+kLSLaunchAndHide = 0x00100000
+kLSLaunchAndHideOthers = 0x00200000 
diff --git a/Mac/Modules/launch/_Launchmodule.c b/Mac/Modules/launch/_Launchmodule.c
new file mode 100644
index 0000000..165e45c
--- /dev/null
+++ b/Mac/Modules/launch/_Launchmodule.c
@@ -0,0 +1,401 @@
+
+/* ========================= Module _Launch ========================= */
+
+#include "Python.h"
+
+
+
+#include "pymactoolbox.h"
+
+/* Macro to test whether a weak-loaded CFM function exists */
+#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL )  {\
+        PyErr_SetString(PyExc_NotImplementedError, \
+        "Not available in this shared library/OS version"); \
+        return NULL; \
+    }} while(0)
+
+
+#include <ApplicationServices/ApplicationServices.h>
+
+/*
+** Optional CFStringRef. None will pass NULL
+*/
+static int
+OptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec)
+{
+	if (v == Py_None) {
+		*spec = NULL;
+		return 1;
+	}
+	return CFStringRefObj_Convert(v, spec);
+}
+
+PyObject *
+OptCFStringRefObj_New(CFStringRef it)
+{
+	if (it == NULL) {
+		Py_INCREF(Py_None);
+		return Py_None;
+	}
+	return CFStringRefObj_New(it);
+}
+
+/*
+** Convert LSItemInfoRecord to Python.
+*/
+PyObject *
+LSItemInfoRecord_New(LSItemInfoRecord *it)
+{
+	return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}", 
+		"flags", it->flags,
+		"filetype", PyMac_BuildOSType, it->filetype,
+		"creator", PyMac_BuildOSType, it->creator,
+		"extension", OptCFStringRefObj_New, it->extension,
+		"iconFileName", OptCFStringRefObj_New, it->iconFileName,
+		"kindID", it->kindID);
+}
+
+static PyObject *Launch_Error;
+
+static PyObject *Launch_LSInit(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	LSInitializeFlags inFlags;
+	if (!PyArg_ParseTuple(_args, "l",
+	                      &inFlags))
+		return NULL;
+	_err = LSInit(inFlags);
+	if (_err != noErr) return PyMac_Error(_err);
+	Py_INCREF(Py_None);
+	_res = Py_None;
+	return _res;
+}
+
+static PyObject *Launch_LSTerm(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	if (!PyArg_ParseTuple(_args, ""))
+		return NULL;
+	_err = LSTerm();
+	if (_err != noErr) return PyMac_Error(_err);
+	Py_INCREF(Py_None);
+	_res = Py_None;
+	return _res;
+}
+
+static PyObject *Launch_LSCopyItemInfoForRef(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	FSRef inItemRef;
+	LSRequestedInfo inWhichInfo;
+	LSItemInfoRecord outItemInfo;
+	if (!PyArg_ParseTuple(_args, "O&l",
+	                      PyMac_GetFSRef, &inItemRef,
+	                      &inWhichInfo))
+		return NULL;
+	_err = LSCopyItemInfoForRef(&inItemRef,
+	                            inWhichInfo,
+	                            &outItemInfo);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&",
+	                     LSItemInfoRecord_New, &outItemInfo);
+	return _res;
+}
+
+static PyObject *Launch_LSCopyItemInfoForURL(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	CFURLRef inURL;
+	LSRequestedInfo inWhichInfo;
+	LSItemInfoRecord outItemInfo;
+	if (!PyArg_ParseTuple(_args, "O&l",
+	                      CFURLRefObj_Convert, &inURL,
+	                      &inWhichInfo))
+		return NULL;
+	_err = LSCopyItemInfoForURL(inURL,
+	                            inWhichInfo,
+	                            &outItemInfo);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&",
+	                     LSItemInfoRecord_New, &outItemInfo);
+	return _res;
+}
+
+static PyObject *Launch_LSCopyKindStringForRef(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	FSRef inFSRef;
+	CFStringRef outKindString;
+	if (!PyArg_ParseTuple(_args, "O&",
+	                      PyMac_GetFSRef, &inFSRef))
+		return NULL;
+	_err = LSCopyKindStringForRef(&inFSRef,
+	                              &outKindString);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&",
+	                     CFStringRefObj_New, outKindString);
+	return _res;
+}
+
+static PyObject *Launch_LSCopyKindStringForURL(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	CFURLRef inURL;
+	CFStringRef outKindString;
+	if (!PyArg_ParseTuple(_args, "O&",
+	                      CFURLRefObj_Convert, &inURL))
+		return NULL;
+	_err = LSCopyKindStringForURL(inURL,
+	                              &outKindString);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&",
+	                     CFStringRefObj_New, outKindString);
+	return _res;
+}
+
+static PyObject *Launch_LSGetApplicationForItem(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	FSRef inItemRef;
+	LSRolesMask inRoleMask;
+	FSRef outAppRef;
+	CFURLRef outAppURL;
+	if (!PyArg_ParseTuple(_args, "O&l",
+	                      PyMac_GetFSRef, &inItemRef,
+	                      &inRoleMask))
+		return NULL;
+	_err = LSGetApplicationForItem(&inItemRef,
+	                               inRoleMask,
+	                               &outAppRef,
+	                               &outAppURL);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&O&",
+	                     PyMac_BuildFSRef, &outAppRef,
+	                     CFURLRefObj_New, outAppURL);
+	return _res;
+}
+
+static PyObject *Launch_LSGetApplicationForInfo(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	OSType inType;
+	OSType inCreator;
+	CFStringRef inExtension;
+	LSRolesMask inRoleMask;
+	FSRef outAppRef;
+	CFURLRef outAppURL;
+	if (!PyArg_ParseTuple(_args, "O&O&O&l",
+	                      PyMac_GetOSType, &inType,
+	                      PyMac_GetOSType, &inCreator,
+	                      OptCFStringRefObj_Convert, &inExtension,
+	                      &inRoleMask))
+		return NULL;
+	_err = LSGetApplicationForInfo(inType,
+	                               inCreator,
+	                               inExtension,
+	                               inRoleMask,
+	                               &outAppRef,
+	                               &outAppURL);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&O&",
+	                     PyMac_BuildFSRef, &outAppRef,
+	                     CFURLRefObj_New, outAppURL);
+	return _res;
+}
+
+static PyObject *Launch_LSGetApplicationForURL(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	CFURLRef inURL;
+	LSRolesMask inRoleMask;
+	FSRef outAppRef;
+	CFURLRef outAppURL;
+	if (!PyArg_ParseTuple(_args, "O&l",
+	                      CFURLRefObj_Convert, &inURL,
+	                      &inRoleMask))
+		return NULL;
+	_err = LSGetApplicationForURL(inURL,
+	                              inRoleMask,
+	                              &outAppRef,
+	                              &outAppURL);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&O&",
+	                     PyMac_BuildFSRef, &outAppRef,
+	                     CFURLRefObj_New, outAppURL);
+	return _res;
+}
+
+static PyObject *Launch_LSFindApplicationForInfo(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	OSType inCreator;
+	CFStringRef inBundleID;
+	CFStringRef inName;
+	FSRef outAppRef;
+	CFURLRef outAppURL;
+	if (!PyArg_ParseTuple(_args, "O&O&O&",
+	                      PyMac_GetOSType, &inCreator,
+	                      OptCFStringRefObj_Convert, &inBundleID,
+	                      OptCFStringRefObj_Convert, &inName))
+		return NULL;
+	_err = LSFindApplicationForInfo(inCreator,
+	                                inBundleID,
+	                                inName,
+	                                &outAppRef,
+	                                &outAppURL);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&O&",
+	                     PyMac_BuildFSRef, &outAppRef,
+	                     CFURLRefObj_New, outAppURL);
+	return _res;
+}
+
+static PyObject *Launch_LSCanRefAcceptItem(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	FSRef inItemFSRef;
+	FSRef inTargetRef;
+	LSRolesMask inRoleMask;
+	LSAcceptanceFlags inFlags;
+	Boolean outAcceptsItem;
+	if (!PyArg_ParseTuple(_args, "O&O&ll",
+	                      PyMac_GetFSRef, &inItemFSRef,
+	                      PyMac_GetFSRef, &inTargetRef,
+	                      &inRoleMask,
+	                      &inFlags))
+		return NULL;
+	_err = LSCanRefAcceptItem(&inItemFSRef,
+	                          &inTargetRef,
+	                          inRoleMask,
+	                          inFlags,
+	                          &outAcceptsItem);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("b",
+	                     outAcceptsItem);
+	return _res;
+}
+
+static PyObject *Launch_LSCanURLAcceptURL(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	CFURLRef inItemURL;
+	CFURLRef inTargetURL;
+	LSRolesMask inRoleMask;
+	LSAcceptanceFlags inFlags;
+	Boolean outAcceptsItem;
+	if (!PyArg_ParseTuple(_args, "O&O&ll",
+	                      CFURLRefObj_Convert, &inItemURL,
+	                      CFURLRefObj_Convert, &inTargetURL,
+	                      &inRoleMask,
+	                      &inFlags))
+		return NULL;
+	_err = LSCanURLAcceptURL(inItemURL,
+	                         inTargetURL,
+	                         inRoleMask,
+	                         inFlags,
+	                         &outAcceptsItem);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("b",
+	                     outAcceptsItem);
+	return _res;
+}
+
+static PyObject *Launch_LSOpenFSRef(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	FSRef inRef;
+	FSRef outLaunchedRef;
+	if (!PyArg_ParseTuple(_args, "O&",
+	                      PyMac_GetFSRef, &inRef))
+		return NULL;
+	_err = LSOpenFSRef(&inRef,
+	                   &outLaunchedRef);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&",
+	                     PyMac_BuildFSRef, &outLaunchedRef);
+	return _res;
+}
+
+static PyObject *Launch_LSOpenCFURLRef(PyObject *_self, PyObject *_args)
+{
+	PyObject *_res = NULL;
+	OSStatus _err;
+	CFURLRef inURL;
+	CFURLRef outLaunchedURL;
+	if (!PyArg_ParseTuple(_args, "O&",
+	                      CFURLRefObj_Convert, &inURL))
+		return NULL;
+	_err = LSOpenCFURLRef(inURL,
+	                      &outLaunchedURL);
+	if (_err != noErr) return PyMac_Error(_err);
+	_res = Py_BuildValue("O&",
+	                     CFURLRefObj_New, outLaunchedURL);
+	return _res;
+}
+
+static PyMethodDef Launch_methods[] = {
+	{"LSInit", (PyCFunction)Launch_LSInit, 1,
+	 PyDoc_STR("(LSInitializeFlags inFlags) -> None")},
+	{"LSTerm", (PyCFunction)Launch_LSTerm, 1,
+	 PyDoc_STR("() -> None")},
+	{"LSCopyItemInfoForRef", (PyCFunction)Launch_LSCopyItemInfoForRef, 1,
+	 PyDoc_STR("(FSRef inItemRef, LSRequestedInfo inWhichInfo) -> (LSItemInfoRecord outItemInfo)")},
+	{"LSCopyItemInfoForURL", (PyCFunction)Launch_LSCopyItemInfoForURL, 1,
+	 PyDoc_STR("(CFURLRef inURL, LSRequestedInfo inWhichInfo) -> (LSItemInfoRecord outItemInfo)")},
+	{"LSCopyKindStringForRef", (PyCFunction)Launch_LSCopyKindStringForRef, 1,
+	 PyDoc_STR("(FSRef inFSRef) -> (CFStringRef outKindString)")},
+	{"LSCopyKindStringForURL", (PyCFunction)Launch_LSCopyKindStringForURL, 1,
+	 PyDoc_STR("(CFURLRef inURL) -> (CFStringRef outKindString)")},
+	{"LSGetApplicationForItem", (PyCFunction)Launch_LSGetApplicationForItem, 1,
+	 PyDoc_STR("(FSRef inItemRef, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")},
+	{"LSGetApplicationForInfo", (PyCFunction)Launch_LSGetApplicationForInfo, 1,
+	 PyDoc_STR("(OSType inType, OSType inCreator, CFStringRef inExtension, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")},
+	{"LSGetApplicationForURL", (PyCFunction)Launch_LSGetApplicationForURL, 1,
+	 PyDoc_STR("(CFURLRef inURL, LSRolesMask inRoleMask) -> (FSRef outAppRef, CFURLRef outAppURL)")},
+	{"LSFindApplicationForInfo", (PyCFunction)Launch_LSFindApplicationForInfo, 1,
+	 PyDoc_STR("(OSType inCreator, CFStringRef inBundleID, CFStringRef inName) -> (FSRef outAppRef, CFURLRef outAppURL)")},
+	{"LSCanRefAcceptItem", (PyCFunction)Launch_LSCanRefAcceptItem, 1,
+	 PyDoc_STR("(FSRef inItemFSRef, FSRef inTargetRef, LSRolesMask inRoleMask, LSAcceptanceFlags inFlags) -> (Boolean outAcceptsItem)")},
+	{"LSCanURLAcceptURL", (PyCFunction)Launch_LSCanURLAcceptURL, 1,
+	 PyDoc_STR("(CFURLRef inItemURL, CFURLRef inTargetURL, LSRolesMask inRoleMask, LSAcceptanceFlags inFlags) -> (Boolean outAcceptsItem)")},
+	{"LSOpenFSRef", (PyCFunction)Launch_LSOpenFSRef, 1,
+	 PyDoc_STR("(FSRef inRef) -> (FSRef outLaunchedRef)")},
+	{"LSOpenCFURLRef", (PyCFunction)Launch_LSOpenCFURLRef, 1,
+	 PyDoc_STR("(CFURLRef inURL) -> (CFURLRef outLaunchedURL)")},
+	{NULL, NULL, 0}
+};
+
+
+
+
+void init_Launch(void)
+{
+	PyObject *m;
+	PyObject *d;
+
+
+
+
+	m = Py_InitModule("_Launch", Launch_methods);
+	d = PyModule_GetDict(m);
+	Launch_Error = PyMac_GetOSErrException();
+	if (Launch_Error == NULL ||
+	    PyDict_SetItemString(d, "Error", Launch_Error) != 0)
+		return;
+}
+
+/* ======================= End module _Launch ======================= */
+
diff --git a/Mac/Modules/launch/launchscan.py b/Mac/Modules/launch/launchscan.py
new file mode 100644
index 0000000..8dd6dfd
--- /dev/null
+++ b/Mac/Modules/launch/launchscan.py
@@ -0,0 +1,71 @@
+# Scan an Apple header file, generating a Python file of generator calls.
+
+import sys
+import os
+from bgenlocations import TOOLBOXDIR, BGENDIR
+sys.path.append(BGENDIR)
+from scantools import Scanner
+
+LONG = "LaunchServices"
+SHORT = "launch"
+OBJECT = "NOTUSED"
+
+def main():
+	input = LONG + ".h"
+	output = SHORT + "gen.py"
+	defsoutput = TOOLBOXDIR + LONG + ".py"
+	scanner = MyScanner(input, output, defsoutput)
+	scanner.scan()
+	scanner.close()
+	scanner.gentypetest(SHORT+"typetest.py")
+	print "=== Testing definitions output code ==="
+	execfile(defsoutput, {}, {})
+	print "=== Done scanning and generating, now importing the generated code... ==="
+	exec "import " + SHORT + "support"
+	print "=== Done.  It's up to you to compile it now! ==="
+
+class MyScanner(Scanner):
+
+	def destination(self, type, name, arglist):
+		classname = "Function"
+		listname = "functions"
+		if arglist:
+			t, n, m = arglist[0]
+			# This is non-functional today
+			if t == OBJECT and m == "InMode":
+				classname = "Method"
+				listname = "methods"
+		return classname, listname
+
+	def writeinitialdefs(self):
+		self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+		self.defsfile.write("kLSRequestAllInfo = -1\n")
+		self.defsfile.write("kLSRolesAll = -1\n")
+
+	def makeblacklistnames(self):
+		return [
+			"kLSRequestAllInfo",
+			"kLSRolesAll",
+			]
+
+	def makeblacklisttypes(self):
+		return [
+			"LSLaunchFSRefSpec_ptr",
+			"LSLaunchURLSpec_ptr",
+			]
+
+	def makerepairinstructions(self):
+		return [
+			# LSGetApplicationForInfo
+			([('CFStringRef', 'inExtension', 'InMode')],
+    		 [('OptCFStringRef', 'inExtension', 'InMode')]),
+    		 
+			# LSFindApplicationForInfo
+			([('CFStringRef', 'inBundleID', 'InMode')],
+    		 [('OptCFStringRef', 'inBundleID', 'InMode')]),
+			([('CFStringRef', 'inName', 'InMode')],
+    		 [('OptCFStringRef', 'inName', 'InMode')]),
+			]
+			
+if __name__ == "__main__":
+	main()
diff --git a/Mac/Modules/launch/launchsupport.py b/Mac/Modules/launch/launchsupport.py
new file mode 100644
index 0000000..066d3c6
--- /dev/null
+++ b/Mac/Modules/launch/launchsupport.py
@@ -0,0 +1,111 @@
+# This script generates a Python interface for an Apple Macintosh Manager.
+# It uses the "bgen" package to generate C code.
+# The function specifications are generated by scanning the mamager's header file,
+# using the "scantools" package (customized for this particular manager).
+
+import string
+
+# Declarations that change for each manager
+MODNAME = '_Launch'				# The name of the module
+OBJECTNAME = 'UNUSED'			# The basic name of the objects used here
+KIND = 'Record'				# Usually 'Ptr' or 'Handle'
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = 'Launch'			# The prefix for module-wide routines
+OBJECTTYPE = OBJECTNAME + KIND		# The C type used to represent them
+OBJECTPREFIX = MODPREFIX + 'Obj'	# The prefix for object methods
+INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
+OUTPUTFILE = MODNAME + "module.c"	# The file generated by this program
+
+from macsupport import *
+
+# Create the type objects
+LSAcceptanceFlags = Type("LSAcceptanceFlags", "l")
+LSInitializeFlags = Type("LSInitializeFlags", "l")
+LSRequestedInfo = Type("LSRequestedInfo", "l")
+LSRolesMask = Type("LSRolesMask", "l")
+OptCFStringRef = OpaqueByValueType("CFStringRef", "OptCFStringRefObj")
+LSItemInfoRecord = OpaqueType("LSItemInfoRecord", "LSItemInfoRecord")
+#MenuRef = OpaqueByValueType("MenuRef", "MenuObj")
+#MenuItemIndex = Type("MenuItemIndex", "H")
+
+#WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
+
+#RgnHandle = FakeType("(RgnHandle)0")
+# XXXX Should be next, but this will break a lot of code...
+# RgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
+
+#KeyMap = ArrayOutputBufferType("KeyMap")
+##MacOSEventKind = Type("MacOSEventKind", "h") # Old-style
+##MacOSEventMask = Type("MacOSEventMask", "h") # Old-style
+#EventMask = Type("EventMask", "H")
+#EventKind = Type("EventKind", "H")
+
+includestuff = includestuff + """
+#include <ApplicationServices/ApplicationServices.h>
+
+/*
+** Optional CFStringRef. None will pass NULL
+*/
+static int
+OptCFStringRefObj_Convert(PyObject *v, CFStringRef *spec)
+{
+	if (v == Py_None) {
+		*spec = NULL;
+		return 1;
+	}
+	return CFStringRefObj_Convert(v, spec);
+}
+
+PyObject *
+OptCFStringRefObj_New(CFStringRef it)
+{
+	if (it == NULL) {
+		Py_INCREF(Py_None);
+		return Py_None;
+	}
+	return CFStringRefObj_New(it);
+}
+
+/*
+** Convert LSItemInfoRecord to Python.
+*/
+PyObject *
+LSItemInfoRecord_New(LSItemInfoRecord *it)
+{
+	return Py_BuildValue("{s:is:O&s:O&s:O&s:O&s:i}", 
+		"flags", it->flags,
+		"filetype", PyMac_BuildOSType, it->filetype,
+		"creator", PyMac_BuildOSType, it->creator,
+		"extension", OptCFStringRefObj_New, it->extension,
+		"iconFileName", OptCFStringRefObj_New, it->iconFileName,
+		"kindID", it->kindID);
+}
+"""
+
+# From here on it's basically all boiler plate...
+execfile(string.lower(MODPREFIX) + 'typetest.py')
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
+##object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
+##module.addobject(object)
+
+# Create the generator classes used to populate the lists
+Function = OSErrFunctionGenerator
+##Method = OSErrMethodGenerator
+
+# Create and populate the lists
+functions = []
+##methods = []
+execfile(INPUTFILE)
+
+# add the populated lists to the generator groups
+# (in a different wordl the scan program would generate this)
+for f in functions: module.add(f)
+##for f in methods: object.add(f)
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()
+
diff --git a/setup.py b/setup.py
index 43c2c28..8c75ddc 100644
--- a/setup.py
+++ b/setup.py
@@ -828,6 +828,8 @@ class PyBuildExt(build_ext):
                     extra_link_args=['-framework', 'Carbon']) )
             exts.append( Extension('_IBCarbon', ['ibcarbon/_IBCarbon.c'],
                     extra_link_args=['-framework', 'Carbon']) )
+            exts.append( Extension('_Launch', ['launch/_Launchmodule.c'],
+                    extra_link_args=['-framework', 'ApplicationServices']) )
             exts.append( Extension('_List', ['list/_Listmodule.c'],
                     extra_link_args=['-framework', 'Carbon']) )
             exts.append( Extension('_Menu', ['menu/_Menumodule.c'],
-- 
cgit v0.12