Commit 3aedee1e authored by Just van Rossum's avatar Just van Rossum

Patch #494553 by Donovan Preston: initial implementation

for GetEventParameter().
parent 0b1de84b
......@@ -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) {
......
......@@ -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}
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment