[Python-checkins] CVS: python/dist/src/Mac/Modules/menu _Menumodule.c,1.7,1.7.4.1 menuedit.py,1.8,1.8.20.1 menuscan.py,1.11,1.11.4.1 menusupport.py,1.14,1.14.4.1

Jack Jansen jackjansen@users.sourceforge.net
Wed, 27 Feb 2002 15:15:31 -0800


Update of /cvsroot/python/python/dist/src/Mac/Modules/menu
In directory usw-pr-cvs1:/tmp/cvs-serv2222/menu

Modified Files:
      Tag: release22-maint
	_Menumodule.c menuedit.py menuscan.py menusupport.py 
Log Message:
Backport of 1.8-1.10 (of _Menumodule.c):
- The output MenuRef of GetMenuItemHierarchicalMenu() may be NULL.
- Added support for optional MenuObj arguments
- Added a bunch of calls as functions with an optional
  MenuObj first argument. The same calls already
  exist as methods, but then the first arg isn't
  optional... The method versions could go as far as I'm
  concerned. Jack?



Index: _Menumodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/menu/_Menumodule.c,v
retrieving revision 1.7
retrieving revision 1.7.4.1
diff -C2 -d -r1.7 -r1.7.4.1
*** _Menumodule.c	18 Dec 2001 15:37:18 -0000	1.7
--- _Menumodule.c	27 Feb 2002 23:15:29 -0000	1.7.4.1
***************
*** 51,54 ****
--- 51,77 ----
  #define as_Resource(h) ((Handle)h)
  
+ 
+ /* Alternative version of MenuObj_New, which returns None for NULL argument */
+ PyObject *OptMenuObj_New(MenuRef itself)
+ {
+ 	if (itself == NULL) {
+ 		Py_INCREF(Py_None);
+ 		return Py_None;
+ 	}
+ 	return MenuObj_New(itself);
+ }
+ 
+ /* Alternative version of MenuObj_Convert, which returns NULL for a None argument */
+ int OptMenuObj_Convert(PyObject *v, MenuRef *p_itself)
+ {
+ 	PyObject *tmp;
+ 	
+ 	if ( v == Py_None ) {
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
+ 	return MenuObj_Convert(v, p_itself);
+ }
+ 
  static PyObject *Menu_Error;
  
***************
*** 1616,1620 ****
  	if (_err != noErr) return PyMac_Error(_err);
  	_res = Py_BuildValue("O&",
! 	                     MenuObj_New, outHierMenu);
  	return _res;
  }
--- 1639,1643 ----
  	if (_err != noErr) return PyMac_Error(_err);
  	_res = Py_BuildValue("O&",
! 	                     OptMenuObj_New, outHierMenu);
  	return _res;
  }
***************
*** 3679,3682 ****
--- 3702,3942 ----
  }
  
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_CountMenuItemsWithCommandID(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	ItemCount _rv;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ #ifndef CountMenuItemsWithCommandID
+ 	PyMac_PRECHECK(CountMenuItemsWithCommandID);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&l",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID))
+ 		return NULL;
+ 	_rv = CountMenuItemsWithCommandID(inMenu,
+ 	                                  inCommandID);
+ 	_res = Py_BuildValue("l",
+ 	                     _rv);
+ 	return _res;
+ }
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_GetIndMenuItemWithCommandID(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ 	UInt32 inItemIndex;
+ 	MenuHandle outMenu;
+ 	MenuItemIndex outIndex;
+ #ifndef GetIndMenuItemWithCommandID
+ 	PyMac_PRECHECK(GetIndMenuItemWithCommandID);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&ll",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID,
+ 	                      &inItemIndex))
+ 		return NULL;
+ 	_err = GetIndMenuItemWithCommandID(inMenu,
+ 	                                   inCommandID,
+ 	                                   inItemIndex,
+ 	                                   &outMenu,
+ 	                                   &outIndex);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	_res = Py_BuildValue("O&h",
+ 	                     MenuObj_New, outMenu,
+ 	                     outIndex);
+ 	return _res;
+ }
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_EnableMenuCommand(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ #ifndef EnableMenuCommand
+ 	PyMac_PRECHECK(EnableMenuCommand);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&l",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID))
+ 		return NULL;
+ 	EnableMenuCommand(inMenu,
+ 	                  inCommandID);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_DisableMenuCommand(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ #ifndef DisableMenuCommand
+ 	PyMac_PRECHECK(DisableMenuCommand);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&l",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID))
+ 		return NULL;
+ 	DisableMenuCommand(inMenu,
+ 	                   inCommandID);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_IsMenuCommandEnabled(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	Boolean _rv;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ #ifndef IsMenuCommandEnabled
+ 	PyMac_PRECHECK(IsMenuCommandEnabled);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&l",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID))
+ 		return NULL;
+ 	_rv = IsMenuCommandEnabled(inMenu,
+ 	                           inCommandID);
+ 	_res = Py_BuildValue("b",
+ 	                     _rv);
+ 	return _res;
+ }
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_SetMenuCommandMark(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ 	UniChar inMark;
+ #ifndef SetMenuCommandMark
+ 	PyMac_PRECHECK(SetMenuCommandMark);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&lh",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID,
+ 	                      &inMark))
+ 		return NULL;
+ 	_err = SetMenuCommandMark(inMenu,
+ 	                          inCommandID,
+ 	                          inMark);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_GetMenuCommandMark(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ 	UniChar outMark;
+ #ifndef GetMenuCommandMark
+ 	PyMac_PRECHECK(GetMenuCommandMark);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&l",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID))
+ 		return NULL;
+ 	_err = GetMenuCommandMark(inMenu,
+ 	                          inCommandID,
+ 	                          &outMark);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	_res = Py_BuildValue("h",
+ 	                     outMark);
+ 	return _res;
+ }
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_GetMenuCommandPropertySize(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ 	OSType inPropertyCreator;
+ 	OSType inPropertyTag;
+ 	ByteCount outSize;
+ #ifndef GetMenuCommandPropertySize
+ 	PyMac_PRECHECK(GetMenuCommandPropertySize);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&lO&O&",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID,
+ 	                      PyMac_GetOSType, &inPropertyCreator,
+ 	                      PyMac_GetOSType, &inPropertyTag))
+ 		return NULL;
+ 	_err = GetMenuCommandPropertySize(inMenu,
+ 	                                  inCommandID,
+ 	                                  inPropertyCreator,
+ 	                                  inPropertyTag,
+ 	                                  &outSize);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	_res = Py_BuildValue("l",
+ 	                     outSize);
+ 	return _res;
+ }
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 
+ static PyObject *Menu_RemoveMenuCommandProperty(PyObject *_self, PyObject *_args)
+ {
+ 	PyObject *_res = NULL;
+ 	OSStatus _err;
+ 	MenuHandle inMenu;
+ 	MenuCommand inCommandID;
+ 	OSType inPropertyCreator;
+ 	OSType inPropertyTag;
+ #ifndef RemoveMenuCommandProperty
+ 	PyMac_PRECHECK(RemoveMenuCommandProperty);
+ #endif
+ 	if (!PyArg_ParseTuple(_args, "O&lO&O&",
+ 	                      OptMenuObj_Convert, &inMenu,
+ 	                      &inCommandID,
+ 	                      PyMac_GetOSType, &inPropertyCreator,
+ 	                      PyMac_GetOSType, &inPropertyTag))
+ 		return NULL;
+ 	_err = RemoveMenuCommandProperty(inMenu,
+ 	                                 inCommandID,
+ 	                                 inPropertyCreator,
+ 	                                 inPropertyTag);
+ 	if (_err != noErr) return PyMac_Error(_err);
+ 	Py_INCREF(Py_None);
+ 	_res = Py_None;
+ 	return _res;
+ }
+ #endif
+ 
  static PyMethodDef Menu_methods[] = {
  
***************
*** 3788,3791 ****
--- 4048,4096 ----
  	{"DrawMenuBar", (PyCFunction)Menu_DrawMenuBar, 1,
  	 "() -> None"},
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"CountMenuItemsWithCommandID", (PyCFunction)Menu_CountMenuItemsWithCommandID, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID) -> (ItemCount _rv)"},
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"GetIndMenuItemWithCommandID", (PyCFunction)Menu_GetIndMenuItemWithCommandID, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID, UInt32 inItemIndex) -> (MenuHandle outMenu, MenuItemIndex outIndex)"},
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"EnableMenuCommand", (PyCFunction)Menu_EnableMenuCommand, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID) -> None"},
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"DisableMenuCommand", (PyCFunction)Menu_DisableMenuCommand, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID) -> None"},
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"IsMenuCommandEnabled", (PyCFunction)Menu_IsMenuCommandEnabled, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID) -> (Boolean _rv)"},
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"SetMenuCommandMark", (PyCFunction)Menu_SetMenuCommandMark, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID, UniChar inMark) -> None"},
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"GetMenuCommandMark", (PyCFunction)Menu_GetMenuCommandMark, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID) -> (UniChar outMark)"},
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"GetMenuCommandPropertySize", (PyCFunction)Menu_GetMenuCommandPropertySize, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID, OSType inPropertyCreator, OSType inPropertyTag) -> (ByteCount outSize)"},
+ #endif
+ 
+ #if TARGET_API_MAC_CARBON
+ 	{"RemoveMenuCommandProperty", (PyCFunction)Menu_RemoveMenuCommandProperty, 1,
+ 	 "(MenuHandle inMenu, MenuCommand inCommandID, OSType inPropertyCreator, OSType inPropertyTag) -> None"},
+ #endif
  	{NULL, NULL, 0}
  };

Index: menuedit.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/menu/menuedit.py,v
retrieving revision 1.8
retrieving revision 1.8.20.1
diff -C2 -d -r1.8 -r1.8.20.1
*** menuedit.py	29 Jan 2001 13:32:10 -0000	1.8
--- menuedit.py	27 Feb 2002 23:15:29 -0000	1.8.20.1
***************
*** 60,61 ****
--- 60,139 ----
  functions.append(f)
  
+ 
+ #
+ # The following functions take an *optional* MenuRef as their first argument
+ #
+ 
+ f = Function(ItemCount, 'CountMenuItemsWithCommandID',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 
+ f = Function(OSStatus, 'GetIndMenuItemWithCommandID',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     (UInt32, 'inItemIndex', InMode),
+     (MenuRef, 'outMenu', OutMode),
+     (MenuItemIndex, 'outIndex', OutMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 
+ f = Function(void, 'EnableMenuCommand',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 
+ f = Function(void, 'DisableMenuCommand',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 
+ f = Function(Boolean, 'IsMenuCommandEnabled',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 
+ f = Function(OSStatus, 'SetMenuCommandMark',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     (UniChar, 'inMark', InMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 
+ f = Function(OSStatus, 'GetMenuCommandMark',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     (UniChar, 'outMark', OutMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 
+ f = Function(OSStatus, 'GetMenuCommandPropertySize',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     (OSType, 'inPropertyCreator', InMode),
+     (OSType, 'inPropertyTag', InMode),
+     (ByteCount, 'outSize', OutMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 
+ f = Function(OSStatus, 'RemoveMenuCommandProperty',
+     (OptMenuRef, 'inMenu', InMode),
+     (MenuCommand, 'inCommandID', InMode),
+     (OSType, 'inPropertyCreator', InMode),
+     (OSType, 'inPropertyTag', InMode),
+     condition='#if TARGET_API_MAC_CARBON',
+ )
+ functions.append(f)
+ 

Index: menuscan.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/menu/menuscan.py,v
retrieving revision 1.11
retrieving revision 1.11.4.1
diff -C2 -d -r1.11 -r1.11.4.1
*** menuscan.py	16 Dec 2001 20:15:47 -0000	1.11
--- menuscan.py	27 Feb 2002 23:15:29 -0000	1.11.4.1
***************
*** 145,148 ****
--- 145,150 ----
  			                            ("long", "*", "OutMode")],
  			 [("VarVarOutBuffer", "*", "InOutMode")]),
+ 			([("MenuRef", 'outHierMenu', "OutMode")],
+ 			 [("OptMenuRef", 'outHierMenu', "OutMode")]),
  			]
  

Index: menusupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/menu/menusupport.py,v
retrieving revision 1.14
retrieving revision 1.14.4.1
diff -C2 -d -r1.14 -r1.14.4.1
*** menusupport.py	16 Dec 2001 20:15:51 -0000	1.14
--- menusupport.py	27 Feb 2002 23:15:29 -0000	1.14.4.1
***************
*** 25,28 ****
--- 25,29 ----
  MenuHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
  MenuRef = MenuHandle
+ OptMenuRef = OpaqueByValueType(OBJECTTYPE, "Opt" + OBJECTPREFIX)
  Handle = OpaqueByValueType("Handle", "ResObj")
  MenuBarHandle = OpaqueByValueType("MenuBarHandle", "ResObj")
***************
*** 69,72 ****
--- 70,96 ----
  #define as_Menu(h) ((MenuHandle)h)
  #define as_Resource(h) ((Handle)h)
+ 
+ 
+ /* Alternative version of MenuObj_New, which returns None for NULL argument */
+ PyObject *OptMenuObj_New(MenuRef itself)
+ {
+ 	if (itself == NULL) {
+ 		Py_INCREF(Py_None);
+ 		return Py_None;
+ 	}
+ 	return MenuObj_New(itself);
+ }
+ 
+ /* Alternative version of MenuObj_Convert, which returns NULL for a None argument */
+ int OptMenuObj_Convert(PyObject *v, MenuRef *p_itself)
+ {
+ 	PyObject *tmp;
+ 	
+ 	if ( v == Py_None ) {
+ 		*p_itself = NULL;
+ 		return 1;
+ 	}
+ 	return MenuObj_Convert(v, p_itself);
+ }
  """