summaryrefslogtreecommitdiffstats
path: root/Mac/Modules
diff options
context:
space:
mode:
authorJust van Rossum <just@letterror.com>2001-12-18 12:35:57 (GMT)
committerJust van Rossum <just@letterror.com>2001-12-18 12:35:57 (GMT)
commit820867662bf35a2d8d2234f8cd4c8ce316ebfd37 (patch)
treee736eccfaae8c580e0f6ef98e631e479ebf1884a /Mac/Modules
parent4befff95e91f649b10b6c763753cd44599fb56af (diff)
downloadcpython-820867662bf35a2d8d2234f8cd4c8ce316ebfd37.zip
cpython-820867662bf35a2d8d2234f8cd4c8ce316ebfd37.tar.gz
cpython-820867662bf35a2d8d2234f8cd4c8ce316ebfd37.tar.bz2
Patch #494553 by Donovan Preston: initial implementation
for GetEventParameter().
Diffstat (limited to 'Mac/Modules')
-rw-r--r--Mac/Modules/carbonevt/CarbonEvtsupport.py44
-rwxr-xr-xMac/Modules/carbonevt/_CarbonEvtmodule.c44
2 files changed, 84 insertions, 4 deletions
diff --git a/Mac/Modules/carbonevt/CarbonEvtsupport.py b/Mac/Modules/carbonevt/CarbonEvtsupport.py
index ef862ee..0ce2af8 100644
--- a/Mac/Modules/carbonevt/CarbonEvtsupport.py
+++ b/Mac/Modules/carbonevt/CarbonEvtsupport.py
@@ -105,7 +105,9 @@ EventTypeSpec_New(EventTypeSpec *in)
static int
EventTypeSpec_Convert(PyObject *v, EventTypeSpec *out)
{
- if (PyArg_Parse(v, "(O&l)", PyMac_GetOSType, &(out->eventClass), &(out->eventKind)))
+ if (PyArg_Parse(v, "(O&l)",
+ PyMac_GetOSType, &(out->eventClass),
+ &(out->eventKind)))
return 1;
return NULL;
}
@@ -164,7 +166,9 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject
PyEval_RestoreThread(_save);
#endif /* USE_MAC_MP_MULTITHREADING */
- retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
+ retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&",
+ EventHandlerCallRef_New, handlerRef,
+ EventRef_New, event);
if (retValue == NULL) {
PySys_WriteStderr("Error in event handler callback:\n");
PyErr_Print(); /* this also clears the error */
@@ -285,6 +289,42 @@ f = ManualGenerator("InstallEventHandler", installeventhandler);
f.docstring = lambda: "(EventTypeSpec inSpec, Method callback) -> (EventHandlerRef outRef)"
EventTargetRefobject.add(f)
+# This may not be the best, but at least it lets you get the raw data back into python as a string. You'll have to cut it up yourself and parse the result.
+
+geteventparameter = """
+UInt32 bufferSize;
+EventParamName inName;
+EventParamType inType;
+OSErr _err;
+void * buffer;
+
+if (!PyArg_ParseTuple(_args, "O&O&", PyMac_GetOSType, &inName, PyMac_GetOSType, &inType))
+ return NULL;
+
+/* Figure out the size by passing a null buffer to GetEventParameter */
+_err = GetEventParameter(_self->ob_itself, inName, inType, NULL, 0, &bufferSize, NULL);
+
+if (_err != noErr)
+ return PyMac_Error(_err);
+buffer = PyMem_NEW(char, bufferSize);
+if (buffer == NULL)
+ return PyErr_NoMemory();
+
+_err = GetEventParameter(_self->ob_itself, inName, inType, NULL, bufferSize, NULL, buffer);
+
+if (_err != noErr) {
+ PyMem_DEL(buffer);
+ return PyMac_Error(_err);
+}
+_res = Py_BuildValue("s#", buffer, bufferSize);
+PyMem_DEL(buffer);
+return _res;
+"""
+
+f = ManualGenerator("GetEventParameter", geteventparameter);
+f.docstring = lambda: "(EventParamName eventName, EventParamType eventType) -> (String eventParamData)"
+EventRefobject.add(f)
+
runappeventloop = """
#if USE_MAC_MP_MULTITHREADING
if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
diff --git a/Mac/Modules/carbonevt/_CarbonEvtmodule.c b/Mac/Modules/carbonevt/_CarbonEvtmodule.c
index f9f3886..eef1e3c 100755
--- a/Mac/Modules/carbonevt/_CarbonEvtmodule.c
+++ b/Mac/Modules/carbonevt/_CarbonEvtmodule.c
@@ -47,7 +47,9 @@ EventTypeSpec_New(EventTypeSpec *in)
static int
EventTypeSpec_Convert(PyObject *v, EventTypeSpec *out)
{
- if (PyArg_Parse(v, "(O&l)", PyMac_GetOSType, &(out->eventClass), &(out->eventKind)))
+ if (PyArg_Parse(v, "(O&l)",
+ PyMac_GetOSType, &(out->eventClass),
+ &(out->eventKind)))
return 1;
return NULL;
}
@@ -106,7 +108,9 @@ myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject
PyEval_RestoreThread(_save);
#endif /* USE_MAC_MP_MULTITHREADING */
- retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&", EventHandlerCallRef_New, handlerRef, EventRef_New, event);
+ retValue = PyObject_CallFunction((PyObject *)outPyObject, "O&O&",
+ EventHandlerCallRef_New, handlerRef,
+ EventRef_New, event);
if (retValue == NULL) {
PySys_WriteStderr("Error in event handler callback:\n");
PyErr_Print(); /* this also clears the error */
@@ -340,6 +344,40 @@ static PyObject *EventRef_SendEventToEventTarget(EventRefObject *_self, PyObject
return _res;
}
+static PyObject *EventRef_GetEventParameter(EventRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ UInt32 bufferSize;
+ EventParamName inName;
+ EventParamType inType;
+ OSErr _err;
+ void * buffer;
+
+ if (!PyArg_ParseTuple(_args, "O&O&", PyMac_GetOSType, &inName, PyMac_GetOSType, &inType))
+ return NULL;
+
+ /* Figure out the size by passing a null buffer to GetEventParameter */
+ _err = GetEventParameter(_self->ob_itself, inName, inType, NULL, 0, &bufferSize, NULL);
+
+ if (_err != noErr)
+ return PyMac_Error(_err);
+ buffer = PyMem_NEW(char, bufferSize);
+ if (buffer == NULL)
+ return PyErr_NoMemory();
+
+ _err = GetEventParameter(_self->ob_itself, inName, inType, NULL, bufferSize, NULL, buffer);
+
+ if (_err != noErr) {
+ PyMem_DEL(buffer);
+ return PyMac_Error(_err);
+ }
+ _res = Py_BuildValue("s#", buffer, bufferSize);
+ PyMem_DEL(buffer);
+ return _res;
+
+}
+
static PyMethodDef EventRef_methods[] = {
{"RetainEvent", (PyCFunction)EventRef_RetainEvent, 1,
"() -> (EventRef _rv)"},
@@ -365,6 +403,8 @@ static PyMethodDef EventRef_methods[] = {
"(UInt16 inMask) -> (Boolean _rv)"},
{"SendEventToEventTarget", (PyCFunction)EventRef_SendEventToEventTarget, 1,
"(EventTargetRef inTarget) -> None"},
+ {"GetEventParameter", (PyCFunction)EventRef_GetEventParameter, 1,
+ "(EventParamName eventName, EventParamType eventType) -> (String eventParamData)"},
{NULL, NULL, 0}
};