[Python-checkins] CVS: python/dist/src/Mac/Modules/carbonevt CarbonEvtscan.py,1.2,1.3 CarbonEvtsupport.py,1.4,1.5 _CarbonEvtmodule.c,1.1,1.2

Just van Rossum jvr@users.sourceforge.net
2001年12月12日 12:48:56 -0800


Update of /cvsroot/python/python/dist/src/Mac/Modules/carbonevt
In directory usw-pr-cvs1:/tmp/cvs-serv19463
Modified Files:
	CarbonEvtscan.py CarbonEvtsupport.py _CarbonEvtmodule.c 
Log Message:
Exposed quite a few more calls.
Index: CarbonEvtscan.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/carbonevt/CarbonEvtscan.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CarbonEvtscan.py	2001年11月05日 16:15:40	1.2
--- CarbonEvtscan.py	2001年12月12日 20:48:53	1.3
***************
*** 36,40 ****
 				]
 
! class CarbonEvents_Scanner(Scanner):
 	def destination(self, type, name, arglist):
 		classname = "CarbonEventsFunction"
--- 36,40 ----
 				]
 
! class CarbonEvents_Scanner(Scanner_OSX):
 	def destination(self, type, name, arglist):
 		classname = "CarbonEventsFunction"
***************
*** 51,56 ****
--- 51,65 ----
 		return classname, listname
 
+ 	def writeinitialdefs(self):
+ 		self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+ 		self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+ 		self.defsfile.write("false = 0\n")
+ 		self.defsfile.write("true = 1\n")
+ 		self.defsfile.write("keyAEEventClass = FOUR_CHAR_CODE('evcl')\n")
+ 		self.defsfile.write("keyAEEventID = FOUR_CHAR_CODE('evti')\n")
+ 	
 	def makeblacklistnames(self):
 		return [
+ 			"sHandler",
 			"MacCreateEvent",
 			"TrackMouseLocationWithOptions",
***************
*** 65,68 ****
--- 74,83 ----
 			"InvokeEventComparatorUPP",
 			"InvokeEventLoopTimerUPP",
+ 			"NewEventComparatorUPP",
+ 			"NewEventLoopTimerUPP",
+ 			"NewEventHandlerUPP",
+ 			"DisposeEventComparatorUPP",
+ 			"DisposeEventLoopTimerUPP",
+ 			"DisposeEventHandlerUPP",
 
 			# Wrote by hand
Index: CarbonEvtsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/carbonevt/CarbonEvtsupport.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** CarbonEvtsupport.py	2001年12月11日 21:52:01	1.4
--- CarbonEvtsupport.py	2001年12月12日 20:48:53	1.5
***************
*** 12,28 ****
 	exec execstr
 
! # these types will have no methods and will merely be opaque blobs
! # should write getattr and setattr for them?
 
! StructObjectTypes = ["EventTypeSpec",
! 					"HIPoint",
! 					"HICommand",
! 					"EventHotKeyID",
! 					]
 
! for typ in StructObjectTypes:
! 	execstr = "%(name)s = OpaqueType('%(name)s')" % {"name": typ}
! 	exec execstr
 
 EventTypeSpec_ptr = OpaqueType("EventTypeSpec", "EventTypeSpec")
 
--- 12,30 ----
 	exec execstr
 
! if 0:
! 	# these types will have no methods and will merely be opaque blobs
! 	# should write getattr and setattr for them?
 
! 	StructObjectTypes = ["EventTypeSpec",
! 						"HIPoint",
! 						"HICommand",
! 						"EventHotKeyID",
! 						]
 
! 	for typ in StructObjectTypes:
! 		execstr = "%(name)s = OpaqueType('%(name)s')" % {"name": typ}
! 		exec execstr
 
+ EventHotKeyID = OpaqueByValueType("EventHotKeyID", "EventHotKeyID")
 EventTypeSpec_ptr = OpaqueType("EventTypeSpec", "EventTypeSpec")
 
***************
*** 52,56 ****
 CarbonEventsMethod = OSErrMethodGenerator
 
! includestuff = """
 #ifdef WITHOUT_FRAMEWORKS
 #include <CarbonEvents.h>
--- 54,58 ----
 CarbonEventsMethod = OSErrMethodGenerator
 
! includestuff = r"""
 #ifdef WITHOUT_FRAMEWORKS
 #include <CarbonEvents.h>
***************
*** 61,66 ****
 #include "macglue.h"
 
! #define USE_MAC_MP_MULTITHREADING 1
 
 #if USE_MAC_MP_MULTITHREADING
 static PyThreadState *_save;
--- 63,76 ----
 #include "macglue.h"
 
! /* Macro to test whether a weak-loaded CFM function exists */
! #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
! 	PyErr_SetString(PyExc_NotImplementedError, \
! 	"Not available in this shared library/OS version"); \
! 	return; \
! }} while(0)
 
+ 
+ #define USE_MAC_MP_MULTITHREADING 0
+ 
 #if USE_MAC_MP_MULTITHREADING
 static PyThreadState *_save;
***************
*** 132,140 ****
 /********** end EventHotKeyID *******/
 
! /******** handlecommand ***********/
 
! static EventHandlerUPP gEventHandlerUPP;
 
! pascal OSStatus CarbonEvents_HandleEvent(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
 	PyObject *retValue;
 	int status;
--- 142,150 ----
 /********** end EventHotKeyID *******/
 
! /******** myEventHandler ***********/
 
! static EventHandlerUPP myEventHandlerUPP;
 
! pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
 	PyObject *retValue;
 	int status;
***************
*** 156,165 ****
 }
 
! /******** end handlecommand ***********/
 
 """
 
 initstuff = initstuff + """
! gEventHandlerUPP = NewEventHandlerUPP(CarbonEvents_HandleEvent);
 """
 module = MacModule('_CarbonEvt', 'CarbonEvents', includestuff, finalstuff, initstuff)
--- 166,176 ----
 }
 
! /******** end myEventHandler ***********/
 
 """
 
 initstuff = initstuff + """
! PyMac_PRECHECK(NewEventHandlerUPP); /* This can fail if CarbonLib is too old */
! myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
 """
 module = MacModule('_CarbonEvt', 'CarbonEvents', includestuff, finalstuff, initstuff)
***************
*** 198,202 ****
 	return NULL;
 
! _err = InstallEventHandler(_self->ob_itself, gEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
 if (_err != noErr) return PyMac_Error(_err);
 
--- 209,213 ----
 	return NULL;
 
! _err = InstallEventHandler(_self->ob_itself, myEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
 if (_err != noErr) return PyMac_Error(_err);
 
***************
*** 210,214 ****
 #if USE_MAC_MP_MULTITHREADING
 if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
! 	printf("lock failure\\n");
 	return NULL;
 }
--- 221,225 ----
 #if USE_MAC_MP_MULTITHREADING
 if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
! 	PySys_WriteStderr("lock failure\\n");
 	return NULL;
 }
Index: _CarbonEvtmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/carbonevt/_CarbonEvtmodule.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** _CarbonEvtmodule.c	2001年12月11日 21:52:02	1.1
--- _CarbonEvtmodule.c	2001年12月12日 20:48:53	1.2
***************
*** 14,18 ****
 #include "macglue.h"
 
! #define USE_MAC_MP_MULTITHREADING 1
 
 #if USE_MAC_MP_MULTITHREADING
--- 14,26 ----
 #include "macglue.h"
 
! /* Macro to test whether a weak-loaded CFM function exists */
! #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
! 	PyErr_SetString(PyExc_NotImplementedError, \
! 	"Not available in this shared library/OS version"); \
! 	return; \
! }} while(0)
! 
! 
! #define USE_MAC_MP_MULTITHREADING 0
 
 #if USE_MAC_MP_MULTITHREADING
***************
*** 85,93 ****
 /********** end EventHotKeyID *******/
 
! /******** handlecommand ***********/
 
! static EventHandlerUPP gEventHandlerUPP;
 
! pascal OSStatus CarbonEvents_HandleEvent(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
 	PyObject *retValue;
 	int status;
--- 93,101 ----
 /********** end EventHotKeyID *******/
 
! /******** myEventHandler ***********/
 
! static EventHandlerUPP myEventHandlerUPP;
 
! pascal OSStatus myEventHandler(EventHandlerCallRef handlerRef, EventRef event, void *outPyObject) {
 	PyObject *retValue;
 	int status;
***************
*** 109,113 ****
 }
 
! /******** end handlecommand ***********/
 
 
--- 117,121 ----
 }
 
! /******** end myEventHandler ***********/
 
 
***************
*** 1060,1064 ****
 		return NULL;
 
! 	_err = InstallEventHandler(_self->ob_itself, gEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
 	if (_err != noErr) return PyMac_Error(_err);
 
--- 1068,1072 ----
 		return NULL;
 
! 	_err = InstallEventHandler(_self->ob_itself, myEventHandlerUPP, 1, &inSpec, (void *)callback, &outRef);
 	if (_err != noErr) return PyMac_Error(_err);
 
***************
*** 1147,1151 ****
--- 1155,1174 ----
 }
 
+ static PyObject *EventHotKeyRef_UnregisterEventHotKey(EventHotKeyRefObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	if (!PyArg_ParseTuple(_args, ""))
+ 		return NULL;
+ 	_err = UnregisterEventHotKey(_self->ob_itself);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ 
 static PyMethodDef EventHotKeyRef_methods[] = {
+ 	{"UnregisterEventHotKey", (PyCFunction)EventHotKeyRef_UnregisterEventHotKey, 1,
+ 	 "() -> None"},
 	{NULL, NULL, 0}
 };
***************
*** 1367,1370 ****
--- 1390,1405 ----
 }
 
+ static PyObject *CarbonEvents_GetEventDispatcherTarget(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	EventTargetRef _rv;
+ 	if (!PyArg_ParseTuple(_args, ""))
+ 		return NULL;
+ 	_rv = GetEventDispatcherTarget();
+ 	_res = Py_BuildValue("O&",
+ 	 EventTargetRef_New, _rv);
+ 	return _res;
+ }
+ 
 static PyObject *CarbonEvents_QuitApplicationEventLoop(PyObject *_self, PyObject *_args)
 {
***************
*** 1378,1381 ****
--- 1413,1476 ----
 }
 
+ static PyObject *CarbonEvents_RunAppModalLoopForWindow(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	WindowPtr inWindow;
+ 	if (!PyArg_ParseTuple(_args, "O&",
+ 	 WinObj_Convert, &inWindow))
+ 		return NULL;
+ 	_err = RunAppModalLoopForWindow(inWindow);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ 
+ static PyObject *CarbonEvents_QuitAppModalLoopForWindow(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	WindowPtr inWindow;
+ 	if (!PyArg_ParseTuple(_args, "O&",
+ 	 WinObj_Convert, &inWindow))
+ 		return NULL;
+ 	_err = QuitAppModalLoopForWindow(inWindow);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ 
+ static PyObject *CarbonEvents_BeginAppModalStateForWindow(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	WindowPtr inWindow;
+ 	if (!PyArg_ParseTuple(_args, "O&",
+ 	 WinObj_Convert, &inWindow))
+ 		return NULL;
+ 	_err = BeginAppModalStateForWindow(inWindow);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ 
+ static PyObject *CarbonEvents_EndAppModalStateForWindow(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	WindowPtr inWindow;
+ 	if (!PyArg_ParseTuple(_args, "O&",
+ 	 WinObj_Convert, &inWindow))
+ 		return NULL;
+ 	_err = EndAppModalStateForWindow(inWindow);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ 
 static PyObject *CarbonEvents_SetUserFocusWindow(PyObject *_self, PyObject *_args)
 {
***************
*** 1475,1478 ****
--- 1570,1602 ----
 }
 
+ static PyObject *CarbonEvents_RegisterEventHotKey(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	UInt32 inHotKeyCode;
+ 	UInt32 inHotKeyModifiers;
+ 	EventHotKeyID inHotKeyID;
+ 	EventTargetRef inTarget;
+ 	OptionBits inOptions;
+ 	EventHotKeyRef outRef;
+ 	if (!PyArg_ParseTuple(_args, "llO&O&l",
+ 	 &inHotKeyCode,
+ 	 &inHotKeyModifiers,
+ 	 EventHotKeyID_Convert, &inHotKeyID,
+ 	 EventTargetRef_Convert, &inTarget,
+ 	 &inOptions))
+ 		return NULL;
+ 	_err = RegisterEventHotKey(inHotKeyCode,
+ 	 inHotKeyModifiers,
+ 	 inHotKeyID,
+ 	 inTarget,
+ 	 inOptions,
+ 	 &outRef);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	_res = Py_BuildValue("O&",
+ 	 EventHotKeyRef_New, outRef);
+ 	return _res;
+ }
+ 
 static PyObject *CarbonEvents_RunApplicationEventLoop(PyObject *_self, PyObject *_args)
 {
***************
*** 1481,1485 ****
 #if USE_MAC_MP_MULTITHREADING
 	if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
! 		printf("lock failure\n");
 		return NULL;
 	}
--- 1605,1609 ----
 #if USE_MAC_MP_MULTITHREADING
 	if (MPCreateCriticalRegion(&reentrantLock) != noErr) {
! 		PySys_WriteStderr("lock failure\n");
 		return NULL;
 	}
***************
*** 1528,1533 ****
--- 1652,1667 ----
 	{"GetUserFocusEventTarget", (PyCFunction)CarbonEvents_GetUserFocusEventTarget, 1,
 	 "() -> (EventTargetRef _rv)"},
+ 	{"GetEventDispatcherTarget", (PyCFunction)CarbonEvents_GetEventDispatcherTarget, 1,
+ 	 "() -> (EventTargetRef _rv)"},
 	{"QuitApplicationEventLoop", (PyCFunction)CarbonEvents_QuitApplicationEventLoop, 1,
 	 "() -> None"},
+ 	{"RunAppModalLoopForWindow", (PyCFunction)CarbonEvents_RunAppModalLoopForWindow, 1,
+ 	 "(WindowPtr inWindow) -> None"},
+ 	{"QuitAppModalLoopForWindow", (PyCFunction)CarbonEvents_QuitAppModalLoopForWindow, 1,
+ 	 "(WindowPtr inWindow) -> None"},
+ 	{"BeginAppModalStateForWindow", (PyCFunction)CarbonEvents_BeginAppModalStateForWindow, 1,
+ 	 "(WindowPtr inWindow) -> None"},
+ 	{"EndAppModalStateForWindow", (PyCFunction)CarbonEvents_EndAppModalStateForWindow, 1,
+ 	 "(WindowPtr inWindow) -> None"},
 	{"SetUserFocusWindow", (PyCFunction)CarbonEvents_SetUserFocusWindow, 1,
 	 "(WindowPtr inWindow) -> None"},
***************
*** 1542,1545 ****
--- 1676,1681 ----
 	{"GetWindowCancelButton", (PyCFunction)CarbonEvents_GetWindowCancelButton, 1,
 	 "(WindowPtr inWindow) -> (ControlHandle outControl)"},
+ 	{"RegisterEventHotKey", (PyCFunction)CarbonEvents_RegisterEventHotKey, 1,
+ 	 "(UInt32 inHotKeyCode, UInt32 inHotKeyModifiers, EventHotKeyID inHotKeyID, EventTargetRef inTarget, OptionBits inOptions) -> (EventHotKeyRef outRef)"},
 	{"RunApplicationEventLoop", (PyCFunction)CarbonEvents_RunApplicationEventLoop, 1,
 	 "() -> ()"},
***************
*** 1557,1561 ****
 
 
! 	gEventHandlerUPP = NewEventHandlerUPP(CarbonEvents_HandleEvent);
 
 
--- 1693,1698 ----
 
 
! 	PyMac_PRECHECK(NewEventHandlerUPP); /* This can fail if CarbonLib is too old */
! 	myEventHandlerUPP = NewEventHandlerUPP(myEventHandler);
 
 

AltStyle によって変換されたページ (->オリジナル) /