summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/evt
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-01-30 11:53:55 (GMT)
committerGuido van Rossum <guido@python.org>1995-01-30 11:53:55 (GMT)
commit17448e24081eb713ac00d7bcb681f4f0d8abfcbf (patch)
tree4f9d6768ef326173e1141b1a92af63247a42b13a /Mac/Modules/evt
parent80ffd6683ca7b06ed743c629459b06b07defbfb3 (diff)
downloadcpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.zip
cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.gz
cpython-17448e24081eb713ac00d7bcb681f4f0d8abfcbf.tar.bz2
Committed a more or less working version.
Diffstat (limited to 'Mac/Modules/evt')
-rw-r--r--Mac/Modules/evt/Evtmodule.c228
-rw-r--r--Mac/Modules/evt/evtgen.py47
-rw-r--r--Mac/Modules/evt/evtscan.py59
-rw-r--r--Mac/Modules/evt/evtsupport.py74
4 files changed, 408 insertions, 0 deletions
diff --git a/Mac/Modules/evt/Evtmodule.c b/Mac/Modules/evt/Evtmodule.c
new file mode 100644
index 0000000..074a33e
--- /dev/null
+++ b/Mac/Modules/evt/Evtmodule.c
@@ -0,0 +1,228 @@
+
+/* =========================== Module Evt =========================== */
+
+#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 *);
+
+#include <Events.h>
+
+#define resNotFound -192 /* Can't include <Errors.h> because of Python's "errors.h" */
+
+static PyObject *Evt_Error;
+
+static PyObject *Evt_GetNextEvent(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ short eventMask;
+ EventRecord theEvent;
+ if (!PyArg_ParseTuple(_args, "h",
+ &eventMask))
+ return NULL;
+ _rv = GetNextEvent(eventMask,
+ &theEvent);
+ _res = Py_BuildValue("bO&",
+ _rv,
+ PyMac_BuildEventRecord, &theEvent);
+ return _res;
+}
+
+static PyObject *Evt_WaitNextEvent(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ short eventMask;
+ EventRecord theEvent;
+ unsigned long sleep;
+ if (!PyArg_ParseTuple(_args, "hl",
+ &eventMask,
+ &sleep))
+ return NULL;
+ _rv = WaitNextEvent(eventMask,
+ &theEvent,
+ sleep,
+ (RgnHandle)0);
+ _res = Py_BuildValue("bO&",
+ _rv,
+ PyMac_BuildEventRecord, &theEvent);
+ return _res;
+}
+
+static PyObject *Evt_EventAvail(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ short eventMask;
+ EventRecord theEvent;
+ if (!PyArg_ParseTuple(_args, "h",
+ &eventMask))
+ return NULL;
+ _rv = EventAvail(eventMask,
+ &theEvent);
+ _res = Py_BuildValue("bO&",
+ _rv,
+ PyMac_BuildEventRecord, &theEvent);
+ return _res;
+}
+
+static PyObject *Evt_GetMouse(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Point mouseLoc;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetMouse(&mouseLoc);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildPoint, mouseLoc);
+ return _res;
+}
+
+static PyObject *Evt_Button(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = Button();
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Evt_StillDown(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = StillDown();
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Evt_WaitMouseUp(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = WaitMouseUp();
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Evt_GetKeys(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ KeyMap theKeys__out__;
+ int theKeys__len__;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ GetKeys(theKeys__out__);
+ _res = Py_BuildValue("s#",
+ (char *)&theKeys__out__, sizeof(KeyMap));
+ theKeys__error__: ;
+ return _res;
+}
+
+static PyObject *Evt_TickCount(_self, _args)
+ PyObject *_self;
+ PyObject *_args;
+{
+ PyObject *_res = NULL;
+ long _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TickCount();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyMethodDef Evt_methods[] = {
+ {"GetNextEvent", (PyCFunction)Evt_GetNextEvent, 1,
+ "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"},
+ {"WaitNextEvent", (PyCFunction)Evt_WaitNextEvent, 1,
+ "(short eventMask, unsigned long sleep) -> (Boolean _rv, EventRecord theEvent)"},
+ {"EventAvail", (PyCFunction)Evt_EventAvail, 1,
+ "(short eventMask) -> (Boolean _rv, EventRecord theEvent)"},
+ {"GetMouse", (PyCFunction)Evt_GetMouse, 1,
+ "() -> (Point mouseLoc)"},
+ {"Button", (PyCFunction)Evt_Button, 1,
+ "() -> (Boolean _rv)"},
+ {"StillDown", (PyCFunction)Evt_StillDown, 1,
+ "() -> (Boolean _rv)"},
+ {"WaitMouseUp", (PyCFunction)Evt_WaitMouseUp, 1,
+ "() -> (Boolean _rv)"},
+ {"GetKeys", (PyCFunction)Evt_GetKeys, 1,
+ "() -> (KeyMap theKeys)"},
+ {"TickCount", (PyCFunction)Evt_TickCount, 1,
+ "() -> (long _rv)"},
+ {NULL, NULL, 0}
+};
+
+
+
+
+void initEvt()
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+
+ m = Py_InitModule("Evt", Evt_methods);
+ d = PyModule_GetDict(m);
+ Evt_Error = PyMac_GetOSErrException();
+ if (Evt_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Evt_Error) != 0)
+ Py_FatalError("can't initialize Evt.Error");
+}
+
+/* ========================= End module Evt ========================= */
+
diff --git a/Mac/Modules/evt/evtgen.py b/Mac/Modules/evt/evtgen.py
new file mode 100644
index 0000000..ff30b8d
--- /dev/null
+++ b/Mac/Modules/evt/evtgen.py
@@ -0,0 +1,47 @@
+# Generated from 'D:Development:THINK C:Mac #includes:Apple #includes:Events.h'
+
+f = Function(Boolean, 'GetNextEvent',
+ (short, 'eventMask', InMode),
+ (EventRecord, 'theEvent', OutMode),
+)
+functions.append(f)
+
+f = Function(Boolean, 'WaitNextEvent',
+ (short, 'eventMask', InMode),
+ (EventRecord, 'theEvent', OutMode),
+ (unsigned_long, 'sleep', InMode),
+ (RgnHandle, 'mouseRgn', InMode),
+)
+functions.append(f)
+
+f = Function(Boolean, 'EventAvail',
+ (short, 'eventMask', InMode),
+ (EventRecord, 'theEvent', OutMode),
+)
+functions.append(f)
+
+f = Function(void, 'GetMouse',
+ (Point, 'mouseLoc', OutMode),
+)
+functions.append(f)
+
+f = Function(Boolean, 'Button',
+)
+functions.append(f)
+
+f = Function(Boolean, 'StillDown',
+)
+functions.append(f)
+
+f = Function(Boolean, 'WaitMouseUp',
+)
+functions.append(f)
+
+f = Function(void, 'GetKeys',
+ (KeyMap, 'theKeys', OutMode),
+)
+functions.append(f)
+
+f = Function(long, 'TickCount',
+)
+functions.append(f)
diff --git a/Mac/Modules/evt/evtscan.py b/Mac/Modules/evt/evtscan.py
new file mode 100644
index 0000000..517db71
--- /dev/null
+++ b/Mac/Modules/evt/evtscan.py
@@ -0,0 +1,59 @@
+# Scan an Apple header file, generating a Python file of generator calls.
+
+from scantools import Scanner
+
+LONG = "Events"
+SHORT = "evt"
+OBJECT = "NOTUSED"
+
+def main():
+ input = LONG + ".h"
+ output = SHORT + "gen.py"
+ defsoutput = LONG + ".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"
+ 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 makeblacklistnames(self):
+ return [
+ ]
+
+ def makeblacklisttypes(self):
+ return [
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
+ [("InBuffer", "*", "*")]),
+
+ ([("void", "*", "OutMode"), ("long", "*", "InMode"),
+ ("long", "*", "OutMode")],
+ [("VarVarOutBuffer", "*", "InOutMode")]),
+
+ ([("void", "wStorage", "OutMode")],
+ [("NullStorage", "*", "InMode")]),
+
+ # GetKeys
+ ([('KeyMap', 'theKeys', 'InMode')],
+ [('*', '*', 'OutMode')]),
+ ]
+
+if __name__ == "__main__":
+ main()
diff --git a/Mac/Modules/evt/evtsupport.py b/Mac/Modules/evt/evtsupport.py
new file mode 100644
index 0000000..4798619
--- /dev/null
+++ b/Mac/Modules/evt/evtsupport.py
@@ -0,0 +1,74 @@
+# 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 = 'Events.h' # The Apple header file
+MODNAME = 'Evt' # The name of the module
+OBJECTNAME = 'Event' # 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 = MODNAME # 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
+
+WindowPtr = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
+WindowPeek = OpaqueByValueType("WindowPeek", OBJECTPREFIX)
+
+RgnHandle = FakeType("(RgnHandle)0") # XXX
+
+KeyMap = ArrayOutputBufferType("KeyMap")
+
+includestuff = includestuff + """
+#include <%s>""" % MACHEADERFILE + """
+
+#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; }
+ """)
+
+# 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)
+
+# 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()