diff options
author | Guido van Rossum <guido@python.org> | 1995-01-30 11:53:55 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-01-30 11:53:55 (GMT) |
commit | 17448e24081eb713ac00d7bcb681f4f0d8abfcbf (patch) | |
tree | 4f9d6768ef326173e1141b1a92af63247a42b13a /Mac/Modules/qd | |
parent | 80ffd6683ca7b06ed743c629459b06b07defbfb3 (diff) | |
download | cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.zip cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.gz cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.bz2 |
Committed a more or less working version.
Diffstat (limited to 'Mac/Modules/qd')
-rw-r--r-- | Mac/Modules/qd/Qdmodule.c | 168 | ||||
-rw-r--r-- | Mac/Modules/qd/qdedit.py | 29 | ||||
-rw-r--r-- | Mac/Modules/qd/qdsupport.py | 72 |
3 files changed, 269 insertions, 0 deletions
diff --git a/Mac/Modules/qd/Qdmodule.c b/Mac/Modules/qd/Qdmodule.c new file mode 100644 index 0000000..2f88857 --- /dev/null +++ b/Mac/Modules/qd/Qdmodule.c @@ -0,0 +1,168 @@ + +/* =========================== Module Qd ============================ */ + +#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 *WinObj_New(WindowPtr); +extern int WinObj_Convert(PyObject *, WindowPtr *); + +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 *WinObj_WhichWindow(WindowPtr); + +#include <QuickDraw.h> +#include <Desk.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ + +static PyObject *Qd_Error; + +static PyObject *Qd_GlobalToLocal(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point thePoint; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + GlobalToLocal(&thePoint); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, thePoint); + return _res; +} + +static PyObject *Qd_LocalToGlobal(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Point thePoint; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetPoint, &thePoint)) + return NULL; + LocalToGlobal(&thePoint); + _res = Py_BuildValue("O&", + PyMac_BuildPoint, thePoint); + return _res; +} + +static PyObject *Qd_SetPort(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + WindowPtr thePort; + if (!PyArg_ParseTuple(_args, "O&", + WinObj_Convert, &thePort)) + return NULL; + SetPort(thePort); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_ClipRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect r; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &r)) + return NULL; + ClipRect(&r); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_EraseRect(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Rect r; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetRect, &r)) + return NULL; + EraseRect(&r); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyObject *Qd_OpenDeskAcc(_self, _args) + PyObject *_self; + PyObject *_args; +{ + PyObject *_res = NULL; + Str255 name; + if (!PyArg_ParseTuple(_args, "O&", + PyMac_GetStr255, name)) + return NULL; + OpenDeskAcc(name); + Py_INCREF(Py_None); + _res = Py_None; + return _res; +} + +static PyMethodDef Qd_methods[] = { + {"GlobalToLocal", (PyCFunction)Qd_GlobalToLocal, 1, + "(Point thePoint) -> (Point thePoint)"}, + {"LocalToGlobal", (PyCFunction)Qd_LocalToGlobal, 1, + "(Point thePoint) -> (Point thePoint)"}, + {"SetPort", (PyCFunction)Qd_SetPort, 1, + "(WindowPtr thePort) -> None"}, + {"ClipRect", (PyCFunction)Qd_ClipRect, 1, + "(Rect r) -> None"}, + {"EraseRect", (PyCFunction)Qd_EraseRect, 1, + "(Rect r) -> None"}, + {"OpenDeskAcc", (PyCFunction)Qd_OpenDeskAcc, 1, + "(Str255 name) -> None"}, + {NULL, NULL, 0} +}; + + + + +void initQd() +{ + PyObject *m; + PyObject *d; + + + + + m = Py_InitModule("Qd", Qd_methods); + d = PyModule_GetDict(m); + Qd_Error = PyMac_GetOSErrException(); + if (Qd_Error == NULL || + PyDict_SetItemString(d, "Error", Qd_Error) != 0) + Py_FatalError("can't initialize Qd.Error"); +} + +/* ========================= End module Qd ========================== */ + diff --git a/Mac/Modules/qd/qdedit.py b/Mac/Modules/qd/qdedit.py new file mode 100644 index 0000000..2242c5a --- /dev/null +++ b/Mac/Modules/qd/qdedit.py @@ -0,0 +1,29 @@ +f = Function(void, 'GlobalToLocal', + (Point, 'thePoint', InOutMode), +) +functions.append(f) + +f = Function(void, 'LocalToGlobal', + (Point, 'thePoint', InOutMode), +) +functions.append(f) + +f = Function(void, 'SetPort', + (WindowPtr, 'thePort', InMode), +) +functions.append(f) + +f = Function(void, 'ClipRect', + (Rect, 'r', InMode), +) +functions.append(f) + +f = Function(void, 'EraseRect', + (Rect, 'r', InMode), +) +functions.append(f) + +f = Function(void, 'OpenDeskAcc', + (Str255, 'name', InMode), +) +functions.append(f) diff --git a/Mac/Modules/qd/qdsupport.py b/Mac/Modules/qd/qdsupport.py new file mode 100644 index 0000000..e98b27a --- /dev/null +++ b/Mac/Modules/qd/qdsupport.py @@ -0,0 +1,72 @@ +# 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 +MACHEADERFILE = 'QuickDraw.h' # The Apple header file +MODNAME = 'Qd' # The name of the module +OBJECTNAME = 'Graf' # The basic name of the objects used here + +# The following is *usually* unchanged but may still require tuning +MODPREFIX = MODNAME # The prefix for module-wide routines +OBJECTTYPE = OBJECTNAME + 'Ptr' # 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 +EXTRAFILE = string.lower(MODPREFIX) + 'edit.py' # A similar file but hand-made +OUTPUTFILE = MODNAME + "module.c" # The file generated by this program + +from macsupport import * + +# Create the type objects + +includestuff = includestuff + """ +#include <%s>""" % MACHEADERFILE + """ +#include <Desk.h> + +#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */ +""" + +class MyObjectDefinition(GlobalObjectDefinition): + def outputCheckNewArg(self): + Output("if (itself == NULL) return PyMac_Error(resNotFound);") + def outputCheckConvertArg(self): + OutLbrace("if (DlgObj_Check(v))") + Output("*p_itself = ((WindowObject *)v)->ob_itself;") + Output("return 1;") + OutRbrace() + Out(""" + if (v == Py_None) { *p_itself = NULL; return 1; } + if (PyInt_Check(v)) { *p_itself = (WindowPtr)PyInt_AsLong(v); return 1; } + """) + def outputFreeIt(self, itselfname): + Output("DisposeWindow(%s);", itselfname) + +# From here on it's basically all boiler plate... + +# 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) +execfile(EXTRAFILE) + +# 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() +SetOutputFile() # Close it |