2001-08-23 11:02:09 -03:00
/* ========================== Module _Res =========================== */
# include "Python.h"
2001-12-18 11:39:38 -04:00
# ifdef _WIN32
# include "pywintoolbox.h"
# else
2001-08-23 11:02:09 -03:00
# include "macglue.h"
# include "pymactoolbox.h"
2001-12-18 11:39:38 -04:00
# endif
2001-08-23 11:02:09 -03:00
/* 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 NULL ; \
} } while ( 0 )
# ifdef WITHOUT_FRAMEWORKS
# include <Resources.h>
# include <string.h>
# else
# include <Carbon/Carbon.h>
# endif
# ifdef USE_TOOLBOX_OBJECT_GLUE
extern PyObject * _ResObj_New ( Handle ) ;
extern int _ResObj_Convert ( PyObject * , Handle * ) ;
extern PyObject * _OptResObj_New ( Handle ) ;
extern int _OptResObj_Convert ( PyObject * , Handle * ) ;
# define ResObj_New _ResObj_New
# define ResObj_Convert _ResObj_Convert
# define OptResObj_New _OptResObj_New
# define OptResObj_Convert _OptResObj_Convert
# endif
/* Function to dispose a resource, with a "normal" calling sequence */
static void
PyMac_AutoDisposeHandle ( Handle h )
{
DisposeHandle ( h ) ;
}
static PyObject * Res_Error ;
/* ---------------------- Object type Resource ---------------------- */
PyTypeObject Resource_Type ;
# define ResObj_Check(x) ((x)->ob_type == &Resource_Type)
typedef struct ResourceObject {
PyObject_HEAD
Handle ob_itself ;
void ( * ob_freeit ) ( Handle ptr ) ;
} ResourceObject ;
PyObject * ResObj_New ( Handle itself )
{
ResourceObject * it ;
if ( itself = = NULL ) return PyMac_Error ( resNotFound ) ;
it = PyObject_NEW ( ResourceObject , & Resource_Type ) ;
if ( it = = NULL ) return NULL ;
it - > ob_itself = itself ;
it - > ob_freeit = NULL ;
return ( PyObject * ) it ;
}
2001-09-04 19:19:18 -03:00
int ResObj_Convert ( PyObject * v , Handle * p_itself )
2001-08-23 11:02:09 -03:00
{
if ( ! ResObj_Check ( v ) )
{
PyObject * tmp ;
if ( ( tmp = PyObject_CallMethod ( v , " as_Resource " , " " ) ) )
{
* p_itself = ( ( ResourceObject * ) tmp ) - > ob_itself ;
Py_DECREF ( tmp ) ;
return 1 ;
}
PyErr_Clear ( ) ;
}
if ( ! ResObj_Check ( v ) )
{
PyErr_SetString ( PyExc_TypeError , " Resource required " ) ;
return 0 ;
}
* p_itself = ( ( ResourceObject * ) v ) - > ob_itself ;
return 1 ;
}
static void ResObj_dealloc ( ResourceObject * self )
{
if ( self - > ob_freeit & & self - > ob_itself )
{
self - > ob_freeit ( self - > ob_itself ) ;
}
self - > ob_itself = NULL ;
2002-04-23 19:46:01 -03:00
PyObject_Del ( self ) ;
2001-08-23 11:02:09 -03:00
}
static PyObject * ResObj_HomeResFile ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
2002-03-22 10:16:39 -04:00
# ifndef HomeResFile
PyMac_PRECHECK ( HomeResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = HomeResFile ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * ResObj_MacLoadResource ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-22 10:16:39 -04:00
# ifndef MacLoadResource
PyMac_PRECHECK ( MacLoadResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
MacLoadResource ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_ReleaseResource ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-22 10:16:39 -04:00
# ifndef ReleaseResource
PyMac_PRECHECK ( ReleaseResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
ReleaseResource ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_DetachResource ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-22 10:16:39 -04:00
# ifndef DetachResource
PyMac_PRECHECK ( DetachResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
DetachResource ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_GetResAttrs ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
2002-03-22 10:16:39 -04:00
# ifndef GetResAttrs
PyMac_PRECHECK ( GetResAttrs ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = GetResAttrs ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * ResObj_GetResInfo ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short theID ;
ResType theType ;
Str255 name ;
2002-03-22 10:16:39 -04:00
# ifndef GetResInfo
PyMac_PRECHECK ( GetResInfo ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
GetResInfo ( _self - > ob_itself ,
& theID ,
& theType ,
name ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " hO&O& " ,
theID ,
PyMac_BuildOSType , theType ,
PyMac_BuildStr255 , name ) ;
return _res ;
}
static PyObject * ResObj_SetResInfo ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short theID ;
Str255 name ;
2002-03-22 10:16:39 -04:00
# ifndef SetResInfo
PyMac_PRECHECK ( SetResInfo ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " hO& " ,
& theID ,
PyMac_GetStr255 , name ) )
return NULL ;
SetResInfo ( _self - > ob_itself ,
theID ,
name ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_AddResource ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
ResType theType ;
short theID ;
Str255 name ;
2002-03-22 10:16:39 -04:00
# ifndef AddResource
PyMac_PRECHECK ( AddResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&hO& " ,
PyMac_GetOSType , & theType ,
& theID ,
PyMac_GetStr255 , name ) )
return NULL ;
AddResource ( _self - > ob_itself ,
theType ,
theID ,
name ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_GetResourceSizeOnDisk ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
long _rv ;
2002-03-22 10:16:39 -04:00
# ifndef GetResourceSizeOnDisk
PyMac_PRECHECK ( GetResourceSizeOnDisk ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = GetResourceSizeOnDisk ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " l " ,
_rv ) ;
return _res ;
}
static PyObject * ResObj_GetMaxResourceSize ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
long _rv ;
2002-03-22 10:16:39 -04:00
# ifndef GetMaxResourceSize
PyMac_PRECHECK ( GetMaxResourceSize ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = GetMaxResourceSize ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " l " ,
_rv ) ;
return _res ;
}
# if TARGET_API_MAC_OS8
static PyObject * ResObj_RsrcMapEntry ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
long _rv ;
2002-03-22 10:16:39 -04:00
# ifndef RsrcMapEntry
PyMac_PRECHECK ( RsrcMapEntry ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = RsrcMapEntry ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " l " ,
_rv ) ;
return _res ;
}
# endif
static PyObject * ResObj_SetResAttrs ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short attrs ;
2002-03-22 10:16:39 -04:00
# ifndef SetResAttrs
PyMac_PRECHECK ( SetResAttrs ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& attrs ) )
return NULL ;
SetResAttrs ( _self - > ob_itself ,
attrs ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_ChangedResource ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-22 10:16:39 -04:00
# ifndef ChangedResource
PyMac_PRECHECK ( ChangedResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
ChangedResource ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_RemoveResource ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-22 10:16:39 -04:00
# ifndef RemoveResource
PyMac_PRECHECK ( RemoveResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
RemoveResource ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_WriteResource ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-22 10:16:39 -04:00
# ifndef WriteResource
PyMac_PRECHECK ( WriteResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
WriteResource ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_SetResourceSize ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
long newSize ;
2002-03-22 10:16:39 -04:00
# ifndef SetResourceSize
PyMac_PRECHECK ( SetResourceSize ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " l " ,
& newSize ) )
return NULL ;
SetResourceSize ( _self - > ob_itself ,
newSize ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_GetNextFOND ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Handle _rv ;
2002-03-22 10:16:39 -04:00
# ifndef GetNextFOND
PyMac_PRECHECK ( GetNextFOND ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = GetNextFOND ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
ResObj_New , _rv ) ;
return _res ;
}
static PyObject * ResObj_as_Control ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2001-09-05 07:31:52 -03:00
_res = CtlObj_New ( ( ControlHandle ) _self - > ob_itself ) ;
return _res ;
2001-08-23 11:02:09 -03:00
}
static PyObject * ResObj_as_Menu ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2001-09-05 07:31:52 -03:00
_res = MenuObj_New ( ( MenuHandle ) _self - > ob_itself ) ;
return _res ;
2001-08-23 11:02:09 -03:00
}
static PyObject * ResObj_LoadResource ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-22 10:16:39 -04:00
# ifndef LoadResource
PyMac_PRECHECK ( LoadResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
LoadResource ( _self - > ob_itself ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * ResObj_AutoDispose ( ResourceObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
int onoff , old = 0 ;
if ( ! PyArg_ParseTuple ( _args , " i " , & onoff ) )
return NULL ;
if ( _self - > ob_freeit )
old = 1 ;
if ( onoff )
_self - > ob_freeit = PyMac_AutoDisposeHandle ;
else
_self - > ob_freeit = NULL ;
2001-09-05 12:44:37 -03:00
_res = Py_BuildValue ( " i " , old ) ;
return _res ;
2001-08-23 11:02:09 -03:00
}
static PyMethodDef ResObj_methods [ ] = {
{ " HomeResFile " , ( PyCFunction ) ResObj_HomeResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " MacLoadResource " , ( PyCFunction ) ResObj_MacLoadResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " ReleaseResource " , ( PyCFunction ) ResObj_ReleaseResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " DetachResource " , ( PyCFunction ) ResObj_DetachResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetResAttrs " , ( PyCFunction ) ResObj_GetResAttrs , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetResInfo " , ( PyCFunction ) ResObj_GetResInfo , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (short theID, ResType theType, Str255 name) " ) } ,
2001-08-23 11:02:09 -03:00
{ " SetResInfo " , ( PyCFunction ) ResObj_SetResInfo , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short theID, Str255 name) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " AddResource " , ( PyCFunction ) ResObj_AddResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType, short theID, Str255 name) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetResourceSizeOnDisk " , ( PyCFunction ) ResObj_GetResourceSizeOnDisk , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (long _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetMaxResourceSize " , ( PyCFunction ) ResObj_GetMaxResourceSize , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (long _rv) " ) } ,
2001-08-23 11:02:09 -03:00
# if TARGET_API_MAC_OS8
{ " RsrcMapEntry " , ( PyCFunction ) ResObj_RsrcMapEntry , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (long _rv) " ) } ,
2001-08-23 11:02:09 -03:00
# endif
{ " SetResAttrs " , ( PyCFunction ) ResObj_SetResAttrs , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short attrs) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " ChangedResource " , ( PyCFunction ) ResObj_ChangedResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " RemoveResource " , ( PyCFunction ) ResObj_RemoveResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " WriteResource " , ( PyCFunction ) ResObj_WriteResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " SetResourceSize " , ( PyCFunction ) ResObj_SetResourceSize , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (long newSize) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetNextFOND " , ( PyCFunction ) ResObj_GetNextFOND , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (Handle _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " as_Control " , ( PyCFunction ) ResObj_as_Control , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " Return this resource/handle as a Control " ) } ,
2001-08-23 11:02:09 -03:00
{ " as_Menu " , ( PyCFunction ) ResObj_as_Menu , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " Return this resource/handle as a Menu " ) } ,
2001-08-23 11:02:09 -03:00
{ " LoadResource " , ( PyCFunction ) ResObj_LoadResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " AutoDispose " , ( PyCFunction ) ResObj_AutoDispose , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (int)->int. Automatically DisposeHandle the object on Python object cleanup " ) } ,
2001-08-23 11:02:09 -03:00
{ NULL , NULL , 0 }
} ;
PyMethodChain ResObj_chain = { ResObj_methods , NULL } ;
static PyObject * ResObj_getattr ( ResourceObject * self , char * name )
{
if ( strcmp ( name , " size " ) = = 0 )
return PyInt_FromLong ( GetHandleSize ( self - > ob_itself ) ) ;
if ( strcmp ( name , " data " ) = = 0 ) {
PyObject * res ;
char state ;
state = HGetState ( self - > ob_itself ) ;
HLock ( self - > ob_itself ) ;
res = PyString_FromStringAndSize (
* self - > ob_itself ,
GetHandleSize ( self - > ob_itself ) ) ;
HUnlock ( self - > ob_itself ) ;
HSetState ( self - > ob_itself , state ) ;
return res ;
}
if ( strcmp ( name , " __members__ " ) = = 0 )
return Py_BuildValue ( " [ss] " , " data " , " size " ) ;
return Py_FindMethodInChain ( & ResObj_chain , ( PyObject * ) self , name ) ;
}
static int
ResObj_setattr ( ResourceObject * self , char * name , PyObject * value )
{
char * data ;
long size ;
if ( strcmp ( name , " data " ) ! = 0 | | value = = NULL )
return - 1 ;
if ( ! PyString_Check ( value ) )
return - 1 ;
size = PyString_Size ( value ) ;
data = PyString_AsString ( value ) ;
/* XXXX Do I need the GetState/SetState calls? */
SetHandleSize ( self - > ob_itself , size ) ;
if ( MemError ( ) )
return - 1 ;
HLock ( self - > ob_itself ) ;
memcpy ( ( char * ) * self - > ob_itself , data , size ) ;
HUnlock ( self - > ob_itself ) ;
/* XXXX Should I do the Changed call immedeately? */
return 0 ;
}
# define ResObj_compare NULL
# define ResObj_repr NULL
# define ResObj_hash NULL
PyTypeObject Resource_Type = {
2001-11-30 10:16:36 -04:00
PyObject_HEAD_INIT ( NULL )
2001-08-23 11:02:09 -03:00
0 , /*ob_size*/
2001-12-08 14:02:58 -04:00
" _Res.Resource " , /*tp_name*/
2001-08-23 11:02:09 -03:00
sizeof ( ResourceObject ) , /*tp_basicsize*/
0 , /*tp_itemsize*/
/* methods */
( destructor ) ResObj_dealloc , /*tp_dealloc*/
0 , /*tp_print*/
( getattrfunc ) ResObj_getattr , /*tp_getattr*/
( setattrfunc ) ResObj_setattr , /*tp_setattr*/
( cmpfunc ) ResObj_compare , /*tp_compare*/
( reprfunc ) ResObj_repr , /*tp_repr*/
( PyNumberMethods * ) 0 , /* tp_as_number */
( PySequenceMethods * ) 0 , /* tp_as_sequence */
( PyMappingMethods * ) 0 , /* tp_as_mapping */
( hashfunc ) ResObj_hash , /*tp_hash*/
} ;
/* -------------------- End object type Resource -------------------- */
# if TARGET_API_MAC_OS8
static PyObject * Res_InitResources ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
2002-03-22 10:16:39 -04:00
# ifndef InitResources
PyMac_PRECHECK ( InitResources ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = InitResources ( ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
# endif
# if TARGET_API_MAC_OS8
static PyObject * Res_RsrcZoneInit ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-22 10:16:39 -04:00
# ifndef RsrcZoneInit
PyMac_PRECHECK ( RsrcZoneInit ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
RsrcZoneInit ( ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
# endif
static PyObject * Res_CloseResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short refNum ;
2002-03-22 10:16:39 -04:00
# ifndef CloseResFile
PyMac_PRECHECK ( CloseResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& refNum ) )
return NULL ;
CloseResFile ( refNum ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * Res_ResError ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-18 11:31:08 -04:00
OSErr _err ;
2002-03-22 10:16:39 -04:00
# ifndef ResError
PyMac_PRECHECK ( ResError ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
2002-03-18 11:31:08 -04:00
_err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
Py_INCREF ( Py_None ) ;
_res = Py_None ;
2001-08-23 11:02:09 -03:00
return _res ;
}
static PyObject * Res_CurResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
2002-03-22 10:16:39 -04:00
# ifndef CurResFile
PyMac_PRECHECK ( CurResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = CurResFile ( ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
# if TARGET_API_MAC_OS8
static PyObject * Res_CreateResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Str255 fileName ;
2002-03-22 10:16:39 -04:00
# ifndef CreateResFile
PyMac_PRECHECK ( CreateResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O& " ,
PyMac_GetStr255 , fileName ) )
return NULL ;
CreateResFile ( fileName ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
# endif
# if TARGET_API_MAC_OS8
static PyObject * Res_OpenResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
Str255 fileName ;
2002-03-22 10:16:39 -04:00
# ifndef OpenResFile
PyMac_PRECHECK ( OpenResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O& " ,
PyMac_GetStr255 , fileName ) )
return NULL ;
_rv = OpenResFile ( fileName ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
# endif
static PyObject * Res_UseResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short refNum ;
2002-03-22 10:16:39 -04:00
# ifndef UseResFile
PyMac_PRECHECK ( UseResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& refNum ) )
return NULL ;
UseResFile ( refNum ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * Res_CountTypes ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
2002-03-22 10:16:39 -04:00
# ifndef CountTypes
PyMac_PRECHECK ( CountTypes ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = CountTypes ( ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_Count1Types ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
2002-03-22 10:16:39 -04:00
# ifndef Count1Types
PyMac_PRECHECK ( Count1Types ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
_rv = Count1Types ( ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_GetIndType ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
ResType theType ;
short index ;
2002-03-22 10:16:39 -04:00
# ifndef GetIndType
PyMac_PRECHECK ( GetIndType ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& index ) )
return NULL ;
GetIndType ( & theType ,
index ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
PyMac_BuildOSType , theType ) ;
return _res ;
}
static PyObject * Res_Get1IndType ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
ResType theType ;
short index ;
2002-03-22 10:16:39 -04:00
# ifndef Get1IndType
PyMac_PRECHECK ( Get1IndType ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& index ) )
return NULL ;
Get1IndType ( & theType ,
index ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
PyMac_BuildOSType , theType ) ;
return _res ;
}
static PyObject * Res_SetResLoad ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Boolean load ;
2002-03-22 10:16:39 -04:00
# ifndef SetResLoad
PyMac_PRECHECK ( SetResLoad ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " b " ,
& load ) )
return NULL ;
SetResLoad ( load ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * Res_CountResources ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
ResType theType ;
2002-03-22 10:16:39 -04:00
# ifndef CountResources
PyMac_PRECHECK ( CountResources ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O& " ,
PyMac_GetOSType , & theType ) )
return NULL ;
_rv = CountResources ( theType ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_Count1Resources ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
ResType theType ;
2002-03-22 10:16:39 -04:00
# ifndef Count1Resources
PyMac_PRECHECK ( Count1Resources ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O& " ,
PyMac_GetOSType , & theType ) )
return NULL ;
_rv = Count1Resources ( theType ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_GetIndResource ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Handle _rv ;
ResType theType ;
short index ;
2002-03-22 10:16:39 -04:00
# ifndef GetIndResource
PyMac_PRECHECK ( GetIndResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&h " ,
PyMac_GetOSType , & theType ,
& index ) )
return NULL ;
_rv = GetIndResource ( theType ,
index ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
ResObj_New , _rv ) ;
return _res ;
}
static PyObject * Res_Get1IndResource ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Handle _rv ;
ResType theType ;
short index ;
2002-03-22 10:16:39 -04:00
# ifndef Get1IndResource
PyMac_PRECHECK ( Get1IndResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&h " ,
PyMac_GetOSType , & theType ,
& index ) )
return NULL ;
_rv = Get1IndResource ( theType ,
index ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
ResObj_New , _rv ) ;
return _res ;
}
static PyObject * Res_GetResource ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Handle _rv ;
ResType theType ;
short theID ;
2002-03-22 10:16:39 -04:00
# ifndef GetResource
PyMac_PRECHECK ( GetResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&h " ,
PyMac_GetOSType , & theType ,
& theID ) )
return NULL ;
_rv = GetResource ( theType ,
theID ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
ResObj_New , _rv ) ;
return _res ;
}
static PyObject * Res_Get1Resource ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Handle _rv ;
ResType theType ;
short theID ;
2002-03-22 10:16:39 -04:00
# ifndef Get1Resource
PyMac_PRECHECK ( Get1Resource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&h " ,
PyMac_GetOSType , & theType ,
& theID ) )
return NULL ;
_rv = Get1Resource ( theType ,
theID ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
ResObj_New , _rv ) ;
return _res ;
}
static PyObject * Res_GetNamedResource ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Handle _rv ;
ResType theType ;
Str255 name ;
2002-03-22 10:16:39 -04:00
# ifndef GetNamedResource
PyMac_PRECHECK ( GetNamedResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&O& " ,
PyMac_GetOSType , & theType ,
PyMac_GetStr255 , name ) )
return NULL ;
_rv = GetNamedResource ( theType ,
name ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
ResObj_New , _rv ) ;
return _res ;
}
static PyObject * Res_Get1NamedResource ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Handle _rv ;
ResType theType ;
Str255 name ;
2002-03-22 10:16:39 -04:00
# ifndef Get1NamedResource
PyMac_PRECHECK ( Get1NamedResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&O& " ,
PyMac_GetOSType , & theType ,
PyMac_GetStr255 , name ) )
return NULL ;
_rv = Get1NamedResource ( theType ,
name ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
ResObj_New , _rv ) ;
return _res ;
}
static PyObject * Res_UniqueID ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
ResType theType ;
2002-03-22 10:16:39 -04:00
# ifndef UniqueID
PyMac_PRECHECK ( UniqueID ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O& " ,
PyMac_GetOSType , & theType ) )
return NULL ;
_rv = UniqueID ( theType ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_Unique1ID ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
ResType theType ;
2002-03-22 10:16:39 -04:00
# ifndef Unique1ID
PyMac_PRECHECK ( Unique1ID ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O& " ,
PyMac_GetOSType , & theType ) )
return NULL ;
_rv = Unique1ID ( theType ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_UpdateResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short refNum ;
2002-03-22 10:16:39 -04:00
# ifndef UpdateResFile
PyMac_PRECHECK ( UpdateResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& refNum ) )
return NULL ;
UpdateResFile ( refNum ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * Res_SetResPurge ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Boolean install ;
2002-03-22 10:16:39 -04:00
# ifndef SetResPurge
PyMac_PRECHECK ( SetResPurge ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " b " ,
& install ) )
return NULL ;
SetResPurge ( install ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * Res_GetResFileAttrs ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
short refNum ;
2002-03-22 10:16:39 -04:00
# ifndef GetResFileAttrs
PyMac_PRECHECK ( GetResFileAttrs ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& refNum ) )
return NULL ;
_rv = GetResFileAttrs ( refNum ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_SetResFileAttrs ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short refNum ;
short attrs ;
2002-03-22 10:16:39 -04:00
# ifndef SetResFileAttrs
PyMac_PRECHECK ( SetResFileAttrs ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " hh " ,
& refNum ,
& attrs ) )
return NULL ;
SetResFileAttrs ( refNum ,
attrs ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * Res_OpenRFPerm ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
Str255 fileName ;
short vRefNum ;
SignedByte permission ;
2002-03-22 10:16:39 -04:00
# ifndef OpenRFPerm
PyMac_PRECHECK ( OpenRFPerm ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&hb " ,
PyMac_GetStr255 , fileName ,
& vRefNum ,
& permission ) )
return NULL ;
_rv = OpenRFPerm ( fileName ,
vRefNum ,
permission ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
# if TARGET_API_MAC_OS8
static PyObject * Res_RGetResource ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Handle _rv ;
ResType theType ;
short theID ;
2002-03-22 10:16:39 -04:00
# ifndef RGetResource
PyMac_PRECHECK ( RGetResource ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&h " ,
PyMac_GetOSType , & theType ,
& theID ) )
return NULL ;
_rv = RGetResource ( theType ,
theID ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O& " ,
ResObj_New , _rv ) ;
return _res ;
}
# endif
static PyObject * Res_HOpenResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
short vRefNum ;
long dirID ;
Str255 fileName ;
SignedByte permission ;
2002-03-22 10:16:39 -04:00
# ifndef HOpenResFile
PyMac_PRECHECK ( HOpenResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " hlO&b " ,
& vRefNum ,
& dirID ,
PyMac_GetStr255 , fileName ,
& permission ) )
return NULL ;
_rv = HOpenResFile ( vRefNum ,
dirID ,
fileName ,
permission ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_HCreateResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short vRefNum ;
long dirID ;
Str255 fileName ;
2002-03-22 10:16:39 -04:00
# ifndef HCreateResFile
PyMac_PRECHECK ( HCreateResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " hlO& " ,
& vRefNum ,
& dirID ,
PyMac_GetStr255 , fileName ) )
return NULL ;
HCreateResFile ( vRefNum ,
dirID ,
fileName ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
static PyObject * Res_FSpOpenResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
FSSpec spec ;
SignedByte permission ;
2002-03-22 10:16:39 -04:00
# ifndef FSpOpenResFile
PyMac_PRECHECK ( FSpOpenResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&b " ,
PyMac_GetFSSpec , & spec ,
& permission ) )
return NULL ;
_rv = FSpOpenResFile ( & spec ,
permission ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
static PyObject * Res_FSpCreateResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
FSSpec spec ;
OSType creator ;
OSType fileType ;
ScriptCode scriptTag ;
2002-03-22 10:16:39 -04:00
# ifndef FSpCreateResFile
PyMac_PRECHECK ( FSpCreateResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&O&O&h " ,
PyMac_GetFSSpec , & spec ,
PyMac_GetOSType , & creator ,
PyMac_GetOSType , & fileType ,
& scriptTag ) )
return NULL ;
FSpCreateResFile ( & spec ,
creator ,
fileType ,
scriptTag ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
Py_INCREF ( Py_None ) ;
_res = Py_None ;
return _res ;
}
# if TARGET_API_MAC_CARBON
static PyObject * Res_InsertResourceFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-18 11:31:08 -04:00
OSErr _err ;
2001-08-23 11:02:09 -03:00
SInt16 refNum ;
RsrcChainLocation where ;
2002-03-22 10:16:39 -04:00
# ifndef InsertResourceFile
PyMac_PRECHECK ( InsertResourceFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " hh " ,
& refNum ,
& where ) )
return NULL ;
2002-03-18 11:31:08 -04:00
_err = InsertResourceFile ( refNum ,
where ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
Py_INCREF ( Py_None ) ;
_res = Py_None ;
2001-08-23 11:02:09 -03:00
return _res ;
}
# endif
# if TARGET_API_MAC_CARBON
static PyObject * Res_DetachResourceFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-18 11:31:08 -04:00
OSErr _err ;
2001-08-23 11:02:09 -03:00
SInt16 refNum ;
2002-03-22 10:16:39 -04:00
# ifndef DetachResourceFile
PyMac_PRECHECK ( DetachResourceFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& refNum ) )
return NULL ;
2002-03-18 11:31:08 -04:00
_err = DetachResourceFile ( refNum ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
Py_INCREF ( Py_None ) ;
_res = Py_None ;
2001-08-23 11:02:09 -03:00
return _res ;
}
# endif
# if TARGET_API_MAC_CARBON
static PyObject * Res_FSpResourceFileAlreadyOpen ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Boolean _rv ;
FSSpec resourceFile ;
Boolean inChain ;
SInt16 refNum ;
2002-03-22 10:16:39 -04:00
# ifndef FSpResourceFileAlreadyOpen
PyMac_PRECHECK ( FSpResourceFileAlreadyOpen ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O& " ,
PyMac_GetFSSpec , & resourceFile ) )
return NULL ;
_rv = FSpResourceFileAlreadyOpen ( & resourceFile ,
& inChain ,
& refNum ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " bbh " ,
_rv ,
inChain ,
refNum ) ;
return _res ;
}
# endif
# if TARGET_API_MAC_CARBON
static PyObject * Res_FSpOpenOrphanResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-18 11:31:08 -04:00
OSErr _err ;
2001-08-23 11:02:09 -03:00
FSSpec spec ;
SignedByte permission ;
SInt16 refNum ;
2002-03-22 10:16:39 -04:00
# ifndef FSpOpenOrphanResFile
PyMac_PRECHECK ( FSpOpenOrphanResFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " O&b " ,
PyMac_GetFSSpec , & spec ,
& permission ) )
return NULL ;
2002-03-18 11:31:08 -04:00
_err = FSpOpenOrphanResFile ( & spec ,
permission ,
& refNum ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
_res = Py_BuildValue ( " h " ,
2001-08-23 11:02:09 -03:00
refNum ) ;
return _res ;
}
# endif
# if TARGET_API_MAC_CARBON
static PyObject * Res_GetTopResourceFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-18 11:31:08 -04:00
OSErr _err ;
2001-08-23 11:02:09 -03:00
SInt16 refNum ;
2002-03-22 10:16:39 -04:00
# ifndef GetTopResourceFile
PyMac_PRECHECK ( GetTopResourceFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " " ) )
return NULL ;
2002-03-18 11:31:08 -04:00
_err = GetTopResourceFile ( & refNum ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
_res = Py_BuildValue ( " h " ,
2001-08-23 11:02:09 -03:00
refNum ) ;
return _res ;
}
# endif
# if TARGET_API_MAC_CARBON
static PyObject * Res_GetNextResourceFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-18 11:31:08 -04:00
OSErr _err ;
2001-08-23 11:02:09 -03:00
SInt16 curRefNum ;
SInt16 nextRefNum ;
2002-03-22 10:16:39 -04:00
# ifndef GetNextResourceFile
PyMac_PRECHECK ( GetNextResourceFile ) ;
# endif
2001-08-23 11:02:09 -03:00
if ( ! PyArg_ParseTuple ( _args , " h " ,
& curRefNum ) )
return NULL ;
2002-03-18 11:31:08 -04:00
_err = GetNextResourceFile ( curRefNum ,
& nextRefNum ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
_res = Py_BuildValue ( " h " ,
2001-08-23 11:02:09 -03:00
nextRefNum ) ;
return _res ;
}
# endif
2001-12-18 11:39:38 -04:00
static PyObject * Res_FSOpenResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
short _rv ;
FSRef ref ;
SignedByte permission ;
2002-03-22 10:16:39 -04:00
# ifndef FSOpenResFile
PyMac_PRECHECK ( FSOpenResFile ) ;
# endif
2001-12-18 11:39:38 -04:00
if ( ! PyArg_ParseTuple ( _args , " O&b " ,
PyMac_GetFSRef , & ref ,
& permission ) )
return NULL ;
_rv = FSOpenResFile ( & ref ,
permission ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " h " ,
_rv ) ;
return _res ;
}
2002-01-01 18:43:13 -04:00
static PyObject * Res_FSCreateResFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
FSRef parentRef ;
UniChar * nameLength__in__ ;
UniCharCount nameLength__len__ ;
int nameLength__in_len__ ;
FSRef newRef ;
FSSpec newSpec ;
2002-03-22 10:16:39 -04:00
# ifndef FSCreateResFile
PyMac_PRECHECK ( FSCreateResFile ) ;
# endif
2002-01-01 18:43:13 -04:00
if ( ! PyArg_ParseTuple ( _args , " O&u# " ,
PyMac_GetFSRef , & parentRef ,
& nameLength__in__ , & nameLength__in_len__ ) )
return NULL ;
nameLength__len__ = nameLength__in_len__ ;
FSCreateResFile ( & parentRef ,
nameLength__len__ , nameLength__in__ ,
0 ,
( FSCatalogInfo * ) 0 ,
& newRef ,
& newSpec ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " O&O& " ,
2002-03-18 11:31:08 -04:00
PyMac_BuildFSRef , & newRef ,
PyMac_BuildFSSpec , & newSpec ) ;
2002-01-01 18:43:13 -04:00
return _res ;
}
2001-12-18 11:39:38 -04:00
static PyObject * Res_FSResourceFileAlreadyOpen ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
Boolean _rv ;
FSRef resourceFileRef ;
Boolean inChain ;
SInt16 refNum ;
2002-03-22 10:16:39 -04:00
# ifndef FSResourceFileAlreadyOpen
PyMac_PRECHECK ( FSResourceFileAlreadyOpen ) ;
# endif
2001-12-18 11:39:38 -04:00
if ( ! PyArg_ParseTuple ( _args , " O& " ,
PyMac_GetFSRef , & resourceFileRef ) )
return NULL ;
_rv = FSResourceFileAlreadyOpen ( & resourceFileRef ,
& inChain ,
& refNum ) ;
{
OSErr _err = ResError ( ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
}
_res = Py_BuildValue ( " bbh " ,
_rv ,
inChain ,
refNum ) ;
return _res ;
}
2002-01-04 12:00:27 -04:00
# if TARGET_API_MAC_CARBON
2002-01-01 18:43:13 -04:00
static PyObject * Res_FSCreateResourceFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-18 11:31:08 -04:00
OSErr _err ;
2002-01-01 18:43:13 -04:00
FSRef parentRef ;
UniChar * nameLength__in__ ;
UniCharCount nameLength__len__ ;
int nameLength__in_len__ ;
UniChar * forkNameLength__in__ ;
UniCharCount forkNameLength__len__ ;
int forkNameLength__in_len__ ;
FSRef newRef ;
FSSpec newSpec ;
2002-03-22 10:16:39 -04:00
# ifndef FSCreateResourceFile
PyMac_PRECHECK ( FSCreateResourceFile ) ;
# endif
2002-01-01 18:43:13 -04:00
if ( ! PyArg_ParseTuple ( _args , " O&u#u# " ,
PyMac_GetFSRef , & parentRef ,
& nameLength__in__ , & nameLength__in_len__ ,
& forkNameLength__in__ , & forkNameLength__in_len__ ) )
return NULL ;
nameLength__len__ = nameLength__in_len__ ;
forkNameLength__len__ = forkNameLength__in_len__ ;
2002-03-18 11:31:08 -04:00
_err = FSCreateResourceFile ( & parentRef ,
nameLength__len__ , nameLength__in__ ,
0 ,
( FSCatalogInfo * ) 0 ,
forkNameLength__len__ , forkNameLength__in__ ,
& newRef ,
& newSpec ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
_res = Py_BuildValue ( " O&O& " ,
PyMac_BuildFSRef , & newRef ,
PyMac_BuildFSSpec , & newSpec ) ;
2002-01-01 18:43:13 -04:00
return _res ;
}
2002-01-04 12:00:27 -04:00
# endif
# if TARGET_API_MAC_CARBON
2002-01-01 18:43:13 -04:00
static PyObject * Res_FSOpenResourceFile ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
2002-03-18 11:31:08 -04:00
OSErr _err ;
2002-01-01 18:43:13 -04:00
FSRef ref ;
UniChar * forkNameLength__in__ ;
UniCharCount forkNameLength__len__ ;
int forkNameLength__in_len__ ;
SignedByte permissions ;
SInt16 refNum ;
2002-03-22 10:16:39 -04:00
# ifndef FSOpenResourceFile
PyMac_PRECHECK ( FSOpenResourceFile ) ;
# endif
2002-01-01 18:43:13 -04:00
if ( ! PyArg_ParseTuple ( _args , " O&u#b " ,
PyMac_GetFSRef , & ref ,
& forkNameLength__in__ , & forkNameLength__in_len__ ,
& permissions ) )
return NULL ;
forkNameLength__len__ = forkNameLength__in_len__ ;
2002-03-18 11:31:08 -04:00
_err = FSOpenResourceFile ( & ref ,
forkNameLength__len__ , forkNameLength__in__ ,
permissions ,
& refNum ) ;
if ( _err ! = noErr ) return PyMac_Error ( _err ) ;
_res = Py_BuildValue ( " h " ,
2002-01-01 18:43:13 -04:00
refNum ) ;
return _res ;
}
2002-01-04 12:00:27 -04:00
# endif
2002-01-01 18:43:13 -04:00
2001-08-23 11:02:09 -03:00
static PyObject * Res_Resource ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
char * buf ;
int len ;
Handle h ;
if ( ! PyArg_ParseTuple ( _args , " s# " , & buf , & len ) )
return NULL ;
h = NewHandle ( len ) ;
if ( h = = NULL ) {
PyErr_NoMemory ( ) ;
return NULL ;
}
HLock ( h ) ;
memcpy ( * h , buf , len ) ;
HUnlock ( h ) ;
2001-09-05 12:44:37 -03:00
_res = ResObj_New ( h ) ;
return _res ;
2001-08-23 11:02:09 -03:00
}
static PyObject * Res_Handle ( PyObject * _self , PyObject * _args )
{
PyObject * _res = NULL ;
char * buf ;
int len ;
Handle h ;
ResourceObject * rv ;
if ( ! PyArg_ParseTuple ( _args , " s# " , & buf , & len ) )
return NULL ;
h = NewHandle ( len ) ;
if ( h = = NULL ) {
PyErr_NoMemory ( ) ;
return NULL ;
}
HLock ( h ) ;
memcpy ( * h , buf , len ) ;
HUnlock ( h ) ;
rv = ( ResourceObject * ) ResObj_New ( h ) ;
rv - > ob_freeit = PyMac_AutoDisposeHandle ;
2001-09-05 12:44:37 -03:00
_res = ( PyObject * ) rv ;
return _res ;
2001-08-23 11:02:09 -03:00
}
static PyMethodDef Res_methods [ ] = {
# if TARGET_API_MAC_OS8
{ " InitResources " , ( PyCFunction ) Res_InitResources , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
# endif
# if TARGET_API_MAC_OS8
{ " RsrcZoneInit " , ( PyCFunction ) Res_RsrcZoneInit , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
# endif
{ " CloseResFile " , ( PyCFunction ) Res_CloseResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short refNum) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " ResError " , ( PyCFunction ) Res_ResError , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " CurResFile " , ( PyCFunction ) Res_CurResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
# if TARGET_API_MAC_OS8
{ " CreateResFile " , ( PyCFunction ) Res_CreateResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (Str255 fileName) -> None " ) } ,
2001-08-23 11:02:09 -03:00
# endif
# if TARGET_API_MAC_OS8
{ " OpenResFile " , ( PyCFunction ) Res_OpenResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (Str255 fileName) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
# endif
{ " UseResFile " , ( PyCFunction ) Res_UseResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short refNum) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " CountTypes " , ( PyCFunction ) Res_CountTypes , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " Count1Types " , ( PyCFunction ) Res_Count1Types , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetIndType " , ( PyCFunction ) Res_GetIndType , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short index) -> (ResType theType) " ) } ,
2001-08-23 11:02:09 -03:00
{ " Get1IndType " , ( PyCFunction ) Res_Get1IndType , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short index) -> (ResType theType) " ) } ,
2001-08-23 11:02:09 -03:00
{ " SetResLoad " , ( PyCFunction ) Res_SetResLoad , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (Boolean load) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " CountResources " , ( PyCFunction ) Res_CountResources , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " Count1Resources " , ( PyCFunction ) Res_Count1Resources , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetIndResource " , ( PyCFunction ) Res_GetIndResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType, short index) -> (Handle _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " Get1IndResource " , ( PyCFunction ) Res_Get1IndResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType, short index) -> (Handle _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetResource " , ( PyCFunction ) Res_GetResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType, short theID) -> (Handle _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " Get1Resource " , ( PyCFunction ) Res_Get1Resource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType, short theID) -> (Handle _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetNamedResource " , ( PyCFunction ) Res_GetNamedResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType, Str255 name) -> (Handle _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " Get1NamedResource " , ( PyCFunction ) Res_Get1NamedResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType, Str255 name) -> (Handle _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " UniqueID " , ( PyCFunction ) Res_UniqueID , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " Unique1ID " , ( PyCFunction ) Res_Unique1ID , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " UpdateResFile " , ( PyCFunction ) Res_UpdateResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short refNum) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " SetResPurge " , ( PyCFunction ) Res_SetResPurge , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (Boolean install) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " GetResFileAttrs " , ( PyCFunction ) Res_GetResFileAttrs , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short refNum) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " SetResFileAttrs " , ( PyCFunction ) Res_SetResFileAttrs , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short refNum, short attrs) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " OpenRFPerm " , ( PyCFunction ) Res_OpenRFPerm , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (Str255 fileName, short vRefNum, SignedByte permission) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
# if TARGET_API_MAC_OS8
{ " RGetResource " , ( PyCFunction ) Res_RGetResource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (ResType theType, short theID) -> (Handle _rv) " ) } ,
2001-08-23 11:02:09 -03:00
# endif
{ " HOpenResFile " , ( PyCFunction ) Res_HOpenResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short vRefNum, long dirID, Str255 fileName, SignedByte permission) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " HCreateResFile " , ( PyCFunction ) Res_HCreateResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (short vRefNum, long dirID, Str255 fileName) -> None " ) } ,
2001-08-23 11:02:09 -03:00
{ " FSpOpenResFile " , ( PyCFunction ) Res_FSpOpenResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSSpec spec, SignedByte permission) -> (short _rv) " ) } ,
2001-08-23 11:02:09 -03:00
{ " FSpCreateResFile " , ( PyCFunction ) Res_FSpCreateResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSSpec spec, OSType creator, OSType fileType, ScriptCode scriptTag) -> None " ) } ,
2001-08-23 11:02:09 -03:00
# if TARGET_API_MAC_CARBON
{ " InsertResourceFile " , ( PyCFunction ) Res_InsertResourceFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (SInt16 refNum, RsrcChainLocation where) -> None " ) } ,
2001-08-23 11:02:09 -03:00
# endif
# if TARGET_API_MAC_CARBON
{ " DetachResourceFile " , ( PyCFunction ) Res_DetachResourceFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (SInt16 refNum) -> None " ) } ,
2001-08-23 11:02:09 -03:00
# endif
# if TARGET_API_MAC_CARBON
{ " FSpResourceFileAlreadyOpen " , ( PyCFunction ) Res_FSpResourceFileAlreadyOpen , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSSpec resourceFile) -> (Boolean _rv, Boolean inChain, SInt16 refNum) " ) } ,
2001-08-23 11:02:09 -03:00
# endif
# if TARGET_API_MAC_CARBON
{ " FSpOpenOrphanResFile " , ( PyCFunction ) Res_FSpOpenOrphanResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSSpec spec, SignedByte permission) -> (SInt16 refNum) " ) } ,
2001-08-23 11:02:09 -03:00
# endif
# if TARGET_API_MAC_CARBON
{ " GetTopResourceFile " , ( PyCFunction ) Res_GetTopResourceFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " () -> (SInt16 refNum) " ) } ,
2001-08-23 11:02:09 -03:00
# endif
# if TARGET_API_MAC_CARBON
{ " GetNextResourceFile " , ( PyCFunction ) Res_GetNextResourceFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (SInt16 curRefNum) -> (SInt16 nextRefNum) " ) } ,
2001-08-23 11:02:09 -03:00
# endif
2001-12-18 11:39:38 -04:00
{ " FSOpenResFile " , ( PyCFunction ) Res_FSOpenResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSRef ref, SignedByte permission) -> (short _rv) " ) } ,
2002-01-01 18:43:13 -04:00
{ " FSCreateResFile " , ( PyCFunction ) Res_FSCreateResFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSRef parentRef, Buffer nameLength) -> (FSRef newRef, FSSpec newSpec) " ) } ,
2001-12-18 11:39:38 -04:00
{ " FSResourceFileAlreadyOpen " , ( PyCFunction ) Res_FSResourceFileAlreadyOpen , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSRef resourceFileRef) -> (Boolean _rv, Boolean inChain, SInt16 refNum) " ) } ,
2002-01-04 12:00:27 -04:00
# if TARGET_API_MAC_CARBON
2002-01-01 18:43:13 -04:00
{ " FSCreateResourceFile " , ( PyCFunction ) Res_FSCreateResourceFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSRef parentRef, Buffer nameLength, Buffer forkNameLength) -> (FSRef newRef, FSSpec newSpec) " ) } ,
2002-01-04 12:00:27 -04:00
# endif
# if TARGET_API_MAC_CARBON
2002-01-01 18:43:13 -04:00
{ " FSOpenResourceFile " , ( PyCFunction ) Res_FSOpenResourceFile , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " (FSRef ref, Buffer forkNameLength, SignedByte permissions) -> (SInt16 refNum) " ) } ,
2002-01-04 12:00:27 -04:00
# endif
2001-08-23 11:02:09 -03:00
{ " Resource " , ( PyCFunction ) Res_Resource , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " Convert a string to a resource object. \n \n The created resource object is actually just a handle, \n apply AddResource() to write it to a resource file. \n See also the Handle() docstring. \n " ) } ,
2001-08-23 11:02:09 -03:00
{ " Handle " , ( PyCFunction ) Res_Handle , 1 ,
2002-08-16 06:09:31 -03:00
PyDoc_STR ( " Convert a string to a Handle object. \n \n Resource() and Handle() are very similar, but objects created with Handle() are \n by default automatically DisposeHandle()d upon object cleanup. Use AutoDispose() \n to change this. \n " ) } ,
2001-08-23 11:02:09 -03:00
{ NULL , NULL , 0 }
} ;
/* Alternative version of ResObj_New, which returns None for null argument */
PyObject * OptResObj_New ( Handle itself )
{
if ( itself = = NULL ) {
Py_INCREF ( Py_None ) ;
return Py_None ;
}
return ResObj_New ( itself ) ;
}
2001-09-05 07:31:52 -03:00
int OptResObj_Convert ( PyObject * v , Handle * p_itself )
2001-08-23 11:02:09 -03:00
{
PyObject * tmp ;
if ( v = = Py_None ) {
* p_itself = NULL ;
return 1 ;
}
if ( ResObj_Check ( v ) )
{
* p_itself = ( ( ResourceObject * ) v ) - > ob_itself ;
return 1 ;
}
/* If it isn't a resource yet see whether it is convertible */
if ( ( tmp = PyObject_CallMethod ( v , " as_Resource " , " " ) ) ) {
* p_itself = ( ( ResourceObject * ) tmp ) - > ob_itself ;
Py_DECREF ( tmp ) ;
return 1 ;
}
PyErr_Clear ( ) ;
PyErr_SetString ( PyExc_TypeError , " Resource required " ) ;
return 0 ;
}
void init_Res ( void )
{
PyObject * m ;
PyObject * d ;
PyMac_INIT_TOOLBOX_OBJECT_NEW ( Handle , ResObj_New ) ;
PyMac_INIT_TOOLBOX_OBJECT_CONVERT ( Handle , ResObj_Convert ) ;
PyMac_INIT_TOOLBOX_OBJECT_NEW ( Handle , OptResObj_New ) ;
PyMac_INIT_TOOLBOX_OBJECT_CONVERT ( Handle , OptResObj_Convert ) ;
m = Py_InitModule ( " _Res " , Res_methods ) ;
d = PyModule_GetDict ( m ) ;
Res_Error = PyMac_GetOSErrException ( ) ;
if ( Res_Error = = NULL | |
PyDict_SetItemString ( d , " Error " , Res_Error ) ! = 0 )
return ;
Resource_Type . ob_type = & PyType_Type ;
Py_INCREF ( & Resource_Type ) ;
if ( PyDict_SetItemString ( d , " ResourceType " , ( PyObject * ) & Resource_Type ) ! = 0 )
Py_FatalError ( " can't initialize ResourceType " ) ;
}
/* ======================== End module _Res ========================= */