summaryrefslogtreecommitdiffstats
path: root/Mac/Modules
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1996-04-12 16:25:30 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1996-04-12 16:25:30 (GMT)
commitda6a9719940925c3a6173434d7aa55b9a69c3b4d (patch)
tree6b02c02502978c6fd9b3ff7b7c42a99a3a8da4f9 /Mac/Modules
parente353215bf75a76d4f8f4040b551112bc4bb19c9a (diff)
downloadcpython-da6a9719940925c3a6173434d7aa55b9a69c3b4d.zip
cpython-da6a9719940925c3a6173434d7aa55b9a69c3b4d.tar.gz
cpython-da6a9719940925c3a6173434d7aa55b9a69c3b4d.tar.bz2
Interface to the scrap manager
Diffstat (limited to 'Mac/Modules')
-rw-r--r--Mac/Modules/scrap/Scrapmodule.c202
-rw-r--r--Mac/Modules/scrap/scrapscan.py46
-rw-r--r--Mac/Modules/scrap/scrapsupport.py60
3 files changed, 308 insertions, 0 deletions
diff --git a/Mac/Modules/scrap/Scrapmodule.c b/Mac/Modules/scrap/Scrapmodule.c
new file mode 100644
index 0000000..b44e7cd
--- /dev/null
+++ b/Mac/Modules/scrap/Scrapmodule.c
@@ -0,0 +1,202 @@
+
+/* ========================== Module Scrap ========================== */
+
+#include "Python.h"
+
+
+
+#define SystemSevenOrLater 1
+
+#include "macglue.h"
+#include <Memory.h>
+#include <Dialogs.h>
+#include <Menus.h>
+#include <Controls.h>
+
+extern PyObject *ResObj_New(Handle);
+extern int ResObj_Convert(PyObject *, Handle *);
+extern PyObject *OptResObj_New(Handle);
+extern int OptResObj_Convert(PyObject *, Handle *);
+
+extern PyObject *WinObj_New(WindowPtr);
+extern int WinObj_Convert(PyObject *, WindowPtr *);
+extern PyTypeObject Window_Type;
+#define WinObj_Check(x) ((x)->ob_type == &Window_Type)
+
+extern PyObject *DlgObj_New(DialogPtr);
+extern int DlgObj_Convert(PyObject *, DialogPtr *);
+extern PyTypeObject Dialog_Type;
+#define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
+
+extern PyObject *MenuObj_New(MenuHandle);
+extern int MenuObj_Convert(PyObject *, MenuHandle *);
+
+extern PyObject *CtlObj_New(ControlHandle);
+extern int CtlObj_Convert(PyObject *, ControlHandle *);
+
+extern PyObject *GrafObj_New(GrafPtr);
+extern int GrafObj_Convert(PyObject *, GrafPtr *);
+
+extern PyObject *BMObj_New(BitMapPtr);
+extern int BMObj_Convert(PyObject *, BitMapPtr *);
+
+extern PyObject *PMObj_New(PixMapHandle);
+extern int PMObj_Convert(PyObject *, PixMapHandle *);
+
+extern PyObject *WinObj_WhichWindow(WindowPtr);
+
+#include <Scrap.h>
+
+/*
+** Generate ScrapInfo records
+*/
+PyObject *SCRRec_New(itself)
+ ScrapStuff *itself;
+{
+
+ return Py_BuildValue("lO&hhO&", itself->scrapSize,
+ ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
+ PyMac_BuildStr255, itself->scrapName);
+}
+
+static PyObject *Scrap_Error;
+
+static PyObject *Scrap_InfoScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ ScrapStuffPtr _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = InfoScrap();
+ _res = Py_BuildValue("O&",
+ SCRRec_New, _rv);
+ return _res;
+}
+
+static PyObject *Scrap_UnloadScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = UnloadScrap();
+ if ( _rv ) return PyMac_Error((OSErr)_rv);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *Scrap_LoadScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = LoadScrap();
+ if ( _rv ) return PyMac_Error((OSErr)_rv);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *Scrap_GetScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ Handle hDest;
+ ResType theType;
+ long offset;
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ ResObj_Convert, &hDest,
+ PyMac_GetOSType, &theType))
+ return NULL;
+ _rv = GetScrap(hDest,
+ theType,
+ &offset);
+ _res = Py_BuildValue("ll",
+ _rv,
+ offset);
+ return _res;
+}
+
+static PyObject *Scrap_ZeroScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = ZeroScrap();
+ if ( _rv ) return PyMac_Error((OSErr)_rv);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *Scrap_PutScrap(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ long length;
+ ResType theType;
+ char *source__in__;
+ int source__len__;
+ int source__in_len__;
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ PyMac_GetOSType, &theType,
+ &source__in__, &source__in_len__))
+ return NULL;
+ length = source__in_len__;
+ _rv = PutScrap(length,
+ theType,
+ source__in__);
+ if ( _rv ) return PyMac_Error((OSErr)_rv);
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyMethodDef Scrap_methods[] = {
+ {"InfoScrap", (PyCFunction)Scrap_InfoScrap, 1,
+ "() -> (ScrapStuff _rv)"},
+ {"UnloadScrap", (PyCFunction)Scrap_UnloadScrap, 1,
+ "() -> (OSErr)"},
+ {"LoadScrap", (PyCFunction)Scrap_LoadScrap, 1,
+ "() -> (OSErr)"},
+ {"GetScrap", (PyCFunction)Scrap_GetScrap, 1,
+ "(Handle hDest, ResType theType) -> (long _rv, long offset)"},
+ {"ZeroScrap", (PyCFunction)Scrap_ZeroScrap, 1,
+ "() -> (OSErr)"},
+ {"PutScrap", (PyCFunction)Scrap_PutScrap, 1,
+ "(ResType theType, Buffer source) -> (OSErr)"},
+ {NULL, NULL, 0}
+};
+
+
+
+
+void initScrap()
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+
+ m = Py_InitModule("Scrap", Scrap_methods);
+ d = PyModule_GetDict(m);
+ Scrap_Error = PyMac_GetOSErrException();
+ if (Scrap_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Scrap_Error) != 0)
+ Py_FatalError("can't initialize Scrap.Error");
+}
+
+/* ======================== End module Scrap ======================== */
+
diff --git a/Mac/Modules/scrap/scrapscan.py b/Mac/Modules/scrap/scrapscan.py
new file mode 100644
index 0000000..0bad7c2
--- /dev/null
+++ b/Mac/Modules/scrap/scrapscan.py
@@ -0,0 +1,46 @@
+# Scan an Apple header file, generating a Python file of generator calls.
+#
+# Note that the scrap-manager include file is so weird that this
+# generates a boilerplate to be edited by hand.
+
+import addpack
+addpack.addpack(':tools:bgen:bgen')
+from scantools import Scanner
+from bgenlocations import TOOLBOXDIR
+
+LONG = "Scrap"
+SHORT = "Scrap"
+
+def main():
+ input = "Scrap.h"
+ output = SHORT + "gen.py"
+ defsoutput = "@Scrap.py"
+ scanner = MyScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ 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"
+ return classname, listname
+
+ def makeblacklistnames(self):
+ return [
+ ]
+
+ def makeblacklisttypes(self):
+ return [
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ([('void', '*', 'OutMode')], [('putscrapbuffer', '*', 'InMode')]),
+ ]
+
+if __name__ == "__main__":
+ main()
diff --git a/Mac/Modules/scrap/scrapsupport.py b/Mac/Modules/scrap/scrapsupport.py
new file mode 100644
index 0000000..701e197
--- /dev/null
+++ b/Mac/Modules/scrap/scrapsupport.py
@@ -0,0 +1,60 @@
+# 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).
+
+# NOTE: the scrap include file is so bad that the bgen output has to be
+# massaged by hand.
+
+import string
+
+# Declarations that change for each manager
+MACHEADERFILE = 'Scrap.h' # The Apple header file
+MODNAME = 'Scrap' # The name of the module
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = MODNAME # The prefix for module-wide routines
+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
+
+includestuff = includestuff + """
+#include <%s>""" % MACHEADERFILE + """
+
+/*
+** Generate ScrapInfo records
+*/
+PyObject *SCRRec_New(itself)
+ ScrapStuff *itself;
+{
+
+ return Py_BuildValue("lO&hhO&", itself->scrapSize,
+ ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
+ PyMac_BuildStr255, itself->scrapName;
+}
+"""
+
+ScrapStuffPtr = OpaqueType('ScrapStuff', 'SCRRec')
+putscrapbuffer = FixedInputBufferType('void *')
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
+
+# Create the generator classes used to populate the lists
+Function = OSErrFunctionGenerator
+
+# Create and populate the lists
+functions = []
+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)
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()
+