Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8d6473

Browse files
committed
Exposed quite a few more calls.
1 parent 1990943 commit f8d6473

3 files changed

Lines changed: 191 additions & 28 deletions

File tree

Mac/Modules/carbonevt/CarbonEvtscan.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def main():
3535
"EventHotKeyRef",
3636
]
3737

38-
class CarbonEvents_Scanner(Scanner):
38+
class CarbonEvents_Scanner(Scanner_OSX):
3939
def destination(self, type, name, arglist):
4040
classname = "CarbonEventsFunction"
4141
listname = "functions"
@@ -50,8 +50,17 @@ def destination(self, type, name, arglist):
5050
print "not method"
5151
return classname, listname
5252

53+
def writeinitialdefs(self):
54+
self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
55+
self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
56+
self.defsfile.write("false = 0\n")
57+
self.defsfile.write("true = 1\n")
58+
self.defsfile.write("keyAEEventClass = FOUR_CHAR_CODE('evcl')\n")
59+
self.defsfile.write("keyAEEventID = FOUR_CHAR_CODE('evti')\n")
60+
5361
def makeblacklistnames(self):
5462
return [
63+
"sHandler",
5564
"MacCreateEvent",
5665
"TrackMouseLocationWithOptions",
5766
"TrackMouseLocation",
@@ -64,6 +73,12 @@ def makeblacklistnames(self):
6473
"InvokeEventHandlerUPP",
6574
"InvokeEventComparatorUPP",
6675
"InvokeEventLoopTimerUPP",
76+
"NewEventComparatorUPP",
77+
"NewEventLoopTimerUPP",
78+
"NewEventHandlerUPP",
79+
"DisposeEventComparatorUPP",
80+
"DisposeEventLoopTimerUPP",
81+
"DisposeEventHandlerUPP",
6782

6883
# Wrote by hand
6984
"InstallEventHandler",

Mac/Modules/carbonevt/CarbonEvtsupport.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@
1111
execstr = "%(name)s = OpaqueByValueType('%(name)s')" % {"name": typ}
1212
exec execstr
1313

14-
# these types will have no methods and will merely be opaque blobs
15-
# should write getattr and setattr for them?
14+
if 0:
15+
# these types will have no methods and will merely be opaque blobs
16+
# should write getattr and setattr for them?
1617

17-
StructObjectTypes = ["EventTypeSpec",
18-
"HIPoint",
19-
"HICommand",
20-
"EventHotKeyID",
21-
]
18+
StructObjectTypes = ["EventTypeSpec",
19+
"HIPoint",
20+
"HICommand",
21+
"EventHotKeyID",
22+
]
2223

23-
for typ in StructObjectTypes:
24-
execstr = "%(name)s = OpaqueType('%(name)s')" % {"name": typ}
25-
exec execstr
24+
for typ in StructObjectTypes:
25+
execstr = "%(name)s = OpaqueType('%(name)s')" % {"name": typ}
26+
exec execstr
2627

28+
EventHotKeyID = OpaqueByValueType("EventHotKeyID", "EventHotKeyID")
2729
EventTypeSpec_ptr = OpaqueType("EventTypeSpec", "EventTypeSpec")
2830

2931
# is this the right type for the void * in GetEventParameter
@@ -51,7 +53,7 @@
5153
CarbonEventsFunction = OSErrFunctionGenerator
5254
CarbonEventsMethod = OSErrMethodGenerator
5355

54-
includestuff = """
56+
includestuff = r"""
5557
#ifdef WITHOUT_FRAMEWORKS
5658
#include <CarbonEvents.h>
5759
#else
@@ -60,7 +62,15 @@
6062
6163
#include "macglue.h"
6264
63-
#define USE_MAC_MP_MULTITHREADING 1
65+
/* Macro to test whether a weak-loaded CFM function exists */
66+
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
67+
PyErr_SetString(PyExc_NotImplementedError, \
68+
"Not available in this shared library/OS version"); \
69+
return; \
70+
}} while(0)
71+
72+
73+
#define USE_MAC_MP_MULTITHREADING 0
6474
6575
#if USE_MAC_MP_MULTITHREADING
6676
static PyThreadState *_save;
@@ -131,11 +141,11 @@
131141
132142
/********** end EventHotKeyID *******/
133143
134-
/******** handlecommand ***********/
144+
/******** myEventHandler ***********/
135145
136-
static EventHandlerUPP gEventHandlerUPP;
146+
static EventHandlerUPP myEventHandlerUPP;
137147
138-
pascal OSStatus CarbonEvents_HandleEvent(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
148+
pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
139149
PyObject *retValue;
140150
int status;
141151
@@ -155,12 +165,13 @@
155165
return status;
156166
}
157167
158-
/******** end handlecommand ***********/
168+
/******** end myEventHandler ***********/
159169
160170
"""
161171

162172
initstuff = initstuff + """
163-
gEventHandlerUPP = NewEventHandlerUPP(CarbonEvents_HandleEvent);
173+
PyMac_PRECHECK(NewEventHandlerUPP); /* This can fail if CarbonLib is too old */
174+
myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
164175
"""
165176
module = MacModule('_CarbonEvt', 'CarbonEvents', includestuff, finalstuff, initstuff)
166177

@@ -197,7 +208,7 @@
197208
if (!PyArg_ParseTuple(_args, "O&O", EventTypeSpec_Convert, &inSpec, &callback))
198209
return NULL;
199210
200-
_err = InstallEventHandler(_self->ob_itself, gEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
211+
_err = InstallEventHandler(_self->ob_itself, myEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
201212
if (_err != noErr) return PyMac_Error(_err);
202213
203214
return Py_BuildValue("O&", EventHandlerRef_New, outRef);"""
@@ -209,7 +220,7 @@
209220
runappeventloop = """
210221
#if USE_MAC_MP_MULTITHREADING
211222
if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
212-
printf("lock failure\\n");
223+
PySys_WriteStderr("lock failure\\n");
213224
return NULL;
214225
}
215226
_save = PyEval_SaveThread();

Mac/Modules/carbonevt/_CarbonEvtmodule.c

Lines changed: 145 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@
1313

1414
#include "macglue.h"
1515

16-
#define USE_MAC_MP_MULTITHREADING 1
16+
/* Macro to test whether a weak-loaded CFM function exists */
17+
#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
18+
PyErr_SetString(PyExc_NotImplementedError, \
19+
"Not available in this shared library/OS version"); \
20+
return; \
21+
}} while(0)
22+
23+
24+
#define USE_MAC_MP_MULTITHREADING 0
1725

1826
#if USE_MAC_MP_MULTITHREADING
1927
static PyThreadState *_save;
@@ -84,11 +92,11 @@ EventHotKeyID_Convert(PyObject *v, EventHotKeyID *out)
8492

8593
/********** end EventHotKeyID *******/
8694

87-
/******** handlecommand ***********/
95+
/******** myEventHandler ***********/
8896

89-
static EventHandlerUPP gEventHandlerUPP;
97+
static EventHandlerUPP myEventHandlerUPP;
9098

91-
pascal OSStatus CarbonEvents_HandleEvent(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
99+
pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
92100
PyObject *retValue;
93101
int status;
94102

@@ -108,7 +116,7 @@ pascal OSStatus CarbonEvents_HandleEvent(EventHandlerCallRef handlerRef, EventRe
108116
return status;
109117
}
110118

111-
/******** end handlecommand ***********/
119+
/******** end myEventHandler ***********/
112120

113121

114122
static PyObject *CarbonEvents_Error;
@@ -1059,7 +1067,7 @@ static PyObject *EventTargetRef_InstallEventHandler(EventTargetRefObject *_self,
10591067
if (!PyArg_ParseTuple(_args, "O&O", EventTypeSpec_Convert, &inSpec, &callback))
10601068
return NULL;
10611069

1062-
_err = InstallEventHandler(_self->ob_itself, gEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
1070+
_err = InstallEventHandler(_self->ob_itself, myEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
10631071
if (_err != noErr) return PyMac_Error(_err);
10641072

10651073
return Py_BuildValue("O&", EventHandlerRef_New, outRef);
@@ -1146,7 +1154,22 @@ static void EventHotKeyRef_dealloc(EventHotKeyRefObject *self)
11461154
PyMem_DEL(self);
11471155
}
11481156

1157+
static PyObject *EventHotKeyRef_UnregisterEventHotKey(EventHotKeyRefObject *_self, PyObject *_args)
1158+
{
1159+
PyObject *_res = NULL;
1160+
OSStatus _err;
1161+
if (!PyArg_ParseTuple(_args, ""))
1162+
return NULL;
1163+
_err = UnregisterEventHotKey(_self->ob_itself);
1164+
if (_err != noErr) return PyMac_Error(_err);
1165+
Py_INCREF(Py_None);
1166+
_res = Py_None;
1167+
return _res;
1168+
}
1169+
11491170
static PyMethodDef EventHotKeyRef_methods[] = {
1171+
{"UnregisterEventHotKey", (PyCFunction)EventHotKeyRef_UnregisterEventHotKey, 1,
1172+
"() -> None"},
11501173
{NULL, NULL, 0}
11511174
};
11521175

@@ -1366,6 +1389,18 @@ static PyObject *CarbonEvents_GetUserFocusEventTarget(PyObject *_self, PyObject
13661389
return _res;
13671390
}
13681391

1392+
static PyObject *CarbonEvents_GetEventDispatcherTarget(PyObject *_self, PyObject *_args)
1393+
{
1394+
PyObject *_res = NULL;
1395+
EventTargetRef _rv;
1396+
if (!PyArg_ParseTuple(_args, ""))
1397+
return NULL;
1398+
_rv = GetEventDispatcherTarget();
1399+
_res = Py_BuildValue("O&",
1400+
EventTargetRef_New, _rv);
1401+
return _res;
1402+
}
1403+
13691404
static PyObject *CarbonEvents_QuitApplicationEventLoop(PyObject *_self, PyObject *_args)
13701405
{
13711406
PyObject *_res = NULL;
@@ -1377,6 +1412,66 @@ static PyObject *CarbonEvents_QuitApplicationEventLoop(PyObject *_self, PyObject
13771412
return _res;
13781413
}
13791414

1415+
static PyObject *CarbonEvents_RunAppModalLoopForWindow(PyObject *_self, PyObject *_args)
1416+
{
1417+
PyObject *_res = NULL;
1418+
OSStatus _err;
1419+
WindowPtr inWindow;
1420+
if (!PyArg_ParseTuple(_args, "O&",
1421+
WinObj_Convert, &inWindow))
1422+
return NULL;
1423+
_err = RunAppModalLoopForWindow(inWindow);
1424+
if (_err != noErr) return PyMac_Error(_err);
1425+
Py_INCREF(Py_None);
1426+
_res = Py_None;
1427+
return _res;
1428+
}
1429+
1430+
static PyObject *CarbonEvents_QuitAppModalLoopForWindow(PyObject *_self, PyObject *_args)
1431+
{
1432+
PyObject *_res = NULL;
1433+
OSStatus _err;
1434+
WindowPtr inWindow;
1435+
if (!PyArg_ParseTuple(_args, "O&",
1436+
WinObj_Convert, &inWindow))
1437+
return NULL;
1438+
_err = QuitAppModalLoopForWindow(inWindow);
1439+
if (_err != noErr) return PyMac_Error(_err);
1440+
Py_INCREF(Py_None);
1441+
_res = Py_None;
1442+
return _res;
1443+
}
1444+
1445+
static PyObject *CarbonEvents_BeginAppModalStateForWindow(PyObject *_self, PyObject *_args)
1446+
{
1447+
PyObject *_res = NULL;
1448+
OSStatus _err;
1449+
WindowPtr inWindow;
1450+
if (!PyArg_ParseTuple(_args, "O&",
1451+
WinObj_Convert, &inWindow))
1452+
return NULL;
1453+
_err = BeginAppModalStateForWindow(inWindow);
1454+
if (_err != noErr) return PyMac_Error(_err);
1455+
Py_INCREF(Py_None);
1456+
_res = Py_None;
1457+
return _res;
1458+
}
1459+
1460+
static PyObject *CarbonEvents_EndAppModalStateForWindow(PyObject *_self, PyObject *_args)
1461+
{
1462+
PyObject *_res = NULL;
1463+
OSStatus _err;
1464+
WindowPtr inWindow;
1465+
if (!PyArg_ParseTuple(_args, "O&",
1466+
WinObj_Convert, &inWindow))
1467+
return NULL;
1468+
_err = EndAppModalStateForWindow(inWindow);
1469+
if (_err != noErr) return PyMac_Error(_err);
1470+
Py_INCREF(Py_None);
1471+
_res = Py_None;
1472+
return _res;
1473+
}
1474+
13801475
static PyObject *CarbonEvents_SetUserFocusWindow(PyObject *_self, PyObject *_args)
13811476
{
13821477
PyObject *_res = NULL;
@@ -1474,13 +1569,42 @@ static PyObject *CarbonEvents_GetWindowCancelButton(PyObject *_self, PyObject *_
14741569
return _res;
14751570
}
14761571

1572+
static PyObject *CarbonEvents_RegisterEventHotKey(PyObject *_self, PyObject *_args)
1573+
{
1574+
PyObject *_res = NULL;
1575+
OSStatus _err;
1576+
UInt32 inHotKeyCode;
1577+
UInt32 inHotKeyModifiers;
1578+
EventHotKeyID inHotKeyID;
1579+
EventTargetRef inTarget;
1580+
OptionBits inOptions;
1581+
EventHotKeyRef outRef;
1582+
if (!PyArg_ParseTuple(_args, "llO&O&l",
1583+
&inHotKeyCode,
1584+
&inHotKeyModifiers,
1585+
EventHotKeyID_Convert, &inHotKeyID,
1586+
EventTargetRef_Convert, &inTarget,
1587+
&inOptions))
1588+
return NULL;
1589+
_err = RegisterEventHotKey(inHotKeyCode,
1590+
inHotKeyModifiers,
1591+
inHotKeyID,
1592+
inTarget,
1593+
inOptions,
1594+
&outRef);
1595+
if (_err != noErr) return PyMac_Error(_err);
1596+
_res = Py_BuildValue("O&",
1597+
EventHotKeyRef_New, outRef);
1598+
return _res;
1599+
}
1600+
14771601
static PyObject *CarbonEvents_RunApplicationEventLoop(PyObject *_self, PyObject *_args)
14781602
{
14791603
PyObject *_res = NULL;
14801604

14811605
#if USE_MAC_MP_MULTITHREADING
14821606
if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
1483-
printf("lock failure\n");
1607+
PySys_WriteStderr("lock failure\n");
14841608
return NULL;
14851609
}
14861610
_save = PyEval_SaveThread();
@@ -1527,8 +1651,18 @@ static PyMethodDef CarbonEvents_methods[] = {
15271651
"() -> (EventTargetRef _rv)"},
15281652
{"GetUserFocusEventTarget", (PyCFunction)CarbonEvents_GetUserFocusEventTarget, 1,
15291653
"() -> (EventTargetRef _rv)"},
1654+
{"GetEventDispatcherTarget", (PyCFunction)CarbonEvents_GetEventDispatcherTarget, 1,
1655+
"() -> (EventTargetRef _rv)"},
15301656
{"QuitApplicationEventLoop", (PyCFunction)CarbonEvents_QuitApplicationEventLoop, 1,
15311657
"() -> None"},
1658+
{"RunAppModalLoopForWindow", (PyCFunction)CarbonEvents_RunAppModalLoopForWindow, 1,
1659+
"(WindowPtr inWindow) -> None"},
1660+
{"QuitAppModalLoopForWindow", (PyCFunction)CarbonEvents_QuitAppModalLoopForWindow, 1,
1661+
"(WindowPtr inWindow) -> None"},
1662+
{"BeginAppModalStateForWindow", (PyCFunction)CarbonEvents_BeginAppModalStateForWindow, 1,
1663+
"(WindowPtr inWindow) -> None"},
1664+
{"EndAppModalStateForWindow", (PyCFunction)CarbonEvents_EndAppModalStateForWindow, 1,
1665+
"(WindowPtr inWindow) -> None"},
15321666
{"SetUserFocusWindow", (PyCFunction)CarbonEvents_SetUserFocusWindow, 1,
15331667
"(WindowPtr inWindow) -> None"},
15341668
{"GetUserFocusWindow", (PyCFunction)CarbonEvents_GetUserFocusWindow, 1,
@@ -1541,6 +1675,8 @@ static PyMethodDef CarbonEvents_methods[] = {
15411675
"(WindowPtr inWindow) -> (ControlHandle outControl)"},
15421676
{"GetWindowCancelButton", (PyCFunction)CarbonEvents_GetWindowCancelButton, 1,
15431677
"(WindowPtr inWindow) -> (ControlHandle outControl)"},
1678+
{"RegisterEventHotKey", (PyCFunction)CarbonEvents_RegisterEventHotKey, 1,
1679+
"(UInt32 inHotKeyCode, UInt32 inHotKeyModifiers, EventHotKeyID inHotKeyID, EventTargetRef inTarget, OptionBits inOptions) -> (EventHotKeyRef outRef)"},
15441680
{"RunApplicationEventLoop", (PyCFunction)CarbonEvents_RunApplicationEventLoop, 1,
15451681
"() -> ()"},
15461682
{NULL, NULL, 0}
@@ -1556,7 +1692,8 @@ void init_CarbonEvt(void)
15561692

15571693

15581694

1559-
gEventHandlerUPP = NewEventHandlerUPP(CarbonEvents_HandleEvent);
1695+
PyMac_PRECHECK(NewEventHandlerUPP); /* This can fail if CarbonLib is too old */
1696+
myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
15601697

15611698

15621699
m = Py_InitModule("_CarbonEvt", CarbonEvents_methods);

0 commit comments

Comments
 (0)