2 /* ========================== Module Scrap ========================== */
9 #include "pymactoolbox.h"
14 ** Generate ScrapInfo records
21 return Py_BuildValue("lO&hhO&", itself
->scrapSize
,
22 ResObj_New
, itself
->scrapHandle
, itself
->scrapCount
, itself
->scrapState
,
23 PyMac_BuildStr255
, itself
->scrapName
);
26 static PyObject
*Scrap_Error
;
28 static PyObject
*Scrap_LoadScrap(_self
, _args
)
32 PyObject
*_res
= NULL
;
34 if (!PyArg_ParseTuple(_args
, ""))
37 if (_err
!= noErr
) return PyMac_Error(_err
);
43 static PyObject
*Scrap_UnloadScrap(_self
, _args
)
47 PyObject
*_res
= NULL
;
49 if (!PyArg_ParseTuple(_args
, ""))
52 if (_err
!= noErr
) return PyMac_Error(_err
);
58 #if !TARGET_API_MAC_CARBON
60 static PyObject
*Scrap_InfoScrap(_self
, _args
)
64 PyObject
*_res
= NULL
;
66 if (!PyArg_ParseTuple(_args
, ""))
69 _res
= Py_BuildValue("O&",
75 #if !TARGET_API_MAC_CARBON
77 static PyObject
*Scrap_GetScrap(_self
, _args
)
81 PyObject
*_res
= NULL
;
84 ScrapFlavorType flavorType
;
86 if (!PyArg_ParseTuple(_args
, "O&O&",
87 ResObj_Convert
, &destination
,
88 PyMac_GetOSType
, &flavorType
))
90 _rv
= GetScrap(destination
,
93 _res
= Py_BuildValue("ll",
101 static PyObject
*Scrap_ZeroScrap(_self
, _args
)
105 PyObject
*_res
= NULL
;
107 if (!PyArg_ParseTuple(_args
, ""))
109 #if TARGET_API_MAC_CARBON
113 _err
= ClearCurrentScrap();
114 if (_err
!= noErr
) return PyMac_Error(_err
);
115 _err
= GetCurrentScrap(&scrap
);
120 if (_err
!= noErr
) return PyMac_Error(_err
);
126 static PyObject
*Scrap_PutScrap(_self
, _args
)
130 PyObject
*_res
= NULL
;
132 SInt32 sourceBufferByteCount
;
133 ScrapFlavorType flavorType
;
134 char *sourceBuffer__in__
;
135 int sourceBuffer__len__
;
136 int sourceBuffer__in_len__
;
137 #if TARGET_API_MAC_CARBON
141 if (!PyArg_ParseTuple(_args
, "O&s#",
142 PyMac_GetOSType
, &flavorType
,
143 &sourceBuffer__in__
, &sourceBuffer__in_len__
))
145 sourceBufferByteCount
= sourceBuffer__in_len__
;
146 sourceBuffer__len__
= sourceBuffer__in_len__
;
147 #if TARGET_API_MAC_CARBON
148 _err
= GetCurrentScrap(&scrap
);
149 if (_err
!= noErr
) return PyMac_Error(_err
);
150 _err
= PutScrapFlavor(scrap
, flavorType
, 0, sourceBufferByteCount
, sourceBuffer__in__
);
152 _err
= PutScrap(sourceBufferByteCount
,
156 if (_err
!= noErr
) return PyMac_Error(_err
);
159 sourceBuffer__error__
: ;
163 #if TARGET_API_MAC_CARBON
165 static PyObject
*Scrap_ClearCurrentScrap(_self
, _args
)
169 PyObject
*_res
= NULL
;
171 if (!PyArg_ParseTuple(_args
, ""))
173 _err
= ClearCurrentScrap();
174 if (_err
!= noErr
) return PyMac_Error(_err
);
181 #if TARGET_API_MAC_CARBON
183 static PyObject
*Scrap_CallInScrapPromises(_self
, _args
)
187 PyObject
*_res
= NULL
;
189 if (!PyArg_ParseTuple(_args
, ""))
191 _err
= CallInScrapPromises();
192 if (_err
!= noErr
) return PyMac_Error(_err
);
199 static PyMethodDef Scrap_methods
[] = {
200 {"LoadScrap", (PyCFunction
)Scrap_LoadScrap
, 1,
202 {"UnloadScrap", (PyCFunction
)Scrap_UnloadScrap
, 1,
205 #if !TARGET_API_MAC_CARBON
206 {"InfoScrap", (PyCFunction
)Scrap_InfoScrap
, 1,
207 "() -> (ScrapStuffPtr _rv)"},
210 #if !TARGET_API_MAC_CARBON
211 {"GetScrap", (PyCFunction
)Scrap_GetScrap
, 1,
212 "(Handle destination, ScrapFlavorType flavorType) -> (long _rv, SInt32 offset)"},
215 {"ZeroScrap", (PyCFunction
)Scrap_ZeroScrap
, 1,
218 {"PutScrap", (PyCFunction
)Scrap_PutScrap
, 1,
219 "(ScrapFlavorType flavorType, Buffer sourceBuffer) -> None"},
221 #if TARGET_API_MAC_CARBON
222 {"ClearCurrentScrap", (PyCFunction
)Scrap_ClearCurrentScrap
, 1,
226 #if TARGET_API_MAC_CARBON
227 {"CallInScrapPromises", (PyCFunction
)Scrap_CallInScrapPromises
, 1,
244 m
= Py_InitModule("Scrap", Scrap_methods
);
245 d
= PyModule_GetDict(m
);
246 Scrap_Error
= PyMac_GetOSErrException();
247 if (Scrap_Error
== NULL
||
248 PyDict_SetItemString(d
, "Error", Scrap_Error
) != 0)
252 /* ======================== End module Scrap ======================== */