2 /* ========================= Module _Folder ========================= */
9 #include "pywintoolbox.h"
12 #include "pymactoolbox.h"
15 /* Macro to test whether a weak-loaded CFM function exists */
16 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
17 PyErr_SetString(PyExc_NotImplementedError, \
18 "Not available in this shared library/OS version"); \
23 #ifdef WITHOUT_FRAMEWORKS
26 #include <Carbon/Carbon.h>
30 static PyObject
*Folder_Error
;
32 static PyObject
*Folder_FindFolder(PyObject
*_self
, PyObject
*_args
)
34 PyObject
*_res
= NULL
;
41 if (!PyArg_ParseTuple(_args
, "hO&b",
43 PyMac_GetOSType
, &folderType
,
46 _err
= FindFolder(vRefNum
,
51 if (_err
!= noErr
) return PyMac_Error(_err
);
52 _res
= Py_BuildValue("hl",
58 static PyObject
*Folder_ReleaseFolder(PyObject
*_self
, PyObject
*_args
)
60 PyObject
*_res
= NULL
;
64 if (!PyArg_ParseTuple(_args
, "hO&",
66 PyMac_GetOSType
, &folderType
))
68 _err
= ReleaseFolder(vRefNum
,
70 if (_err
!= noErr
) return PyMac_Error(_err
);
76 static PyObject
*Folder_FSFindFolder(PyObject
*_self
, PyObject
*_args
)
78 PyObject
*_res
= NULL
;
84 if (!PyArg_ParseTuple(_args
, "hO&b",
86 PyMac_GetOSType
, &folderType
,
89 _err
= FSFindFolder(vRefNum
,
93 if (_err
!= noErr
) return PyMac_Error(_err
);
94 _res
= Py_BuildValue("O&",
95 PyMac_BuildFSRef
, &foundRef
);
99 static PyObject
*Folder_AddFolderDescriptor(PyObject
*_self
, PyObject
*_args
)
101 PyObject
*_res
= NULL
;
104 FolderDescFlags flags
;
105 FolderClass foldClass
;
106 FolderLocation foldLocation
;
107 OSType badgeSignature
;
111 if (!PyArg_ParseTuple(_args
, "O&lO&O&O&O&O&b",
112 PyMac_GetOSType
, &foldType
,
114 PyMac_GetOSType
, &foldClass
,
115 PyMac_GetOSType
, &foldLocation
,
116 PyMac_GetOSType
, &badgeSignature
,
117 PyMac_GetOSType
, &badgeType
,
118 PyMac_GetStr255
, name
,
121 _err
= AddFolderDescriptor(foldType
,
129 if (_err
!= noErr
) return PyMac_Error(_err
);
135 static PyObject
*Folder_GetFolderTypes(PyObject
*_self
, PyObject
*_args
)
137 PyObject
*_res
= NULL
;
139 UInt32 requestedTypeCount
;
140 UInt32 totalTypeCount
;
142 if (!PyArg_ParseTuple(_args
, "l",
143 &requestedTypeCount
))
145 _err
= GetFolderTypes(requestedTypeCount
,
148 if (_err
!= noErr
) return PyMac_Error(_err
);
149 _res
= Py_BuildValue("lO&",
151 PyMac_BuildOSType
, theTypes
);
155 static PyObject
*Folder_RemoveFolderDescriptor(PyObject
*_self
, PyObject
*_args
)
157 PyObject
*_res
= NULL
;
160 if (!PyArg_ParseTuple(_args
, "O&",
161 PyMac_GetOSType
, &foldType
))
163 _err
= RemoveFolderDescriptor(foldType
);
164 if (_err
!= noErr
) return PyMac_Error(_err
);
170 static PyObject
*Folder_GetFolderName(PyObject
*_self
, PyObject
*_args
)
172 PyObject
*_res
= NULL
;
178 if (!PyArg_ParseTuple(_args
, "hO&O&",
180 PyMac_GetOSType
, &foldType
,
181 PyMac_GetStr255
, name
))
183 _err
= GetFolderName(vRefNum
,
187 if (_err
!= noErr
) return PyMac_Error(_err
);
188 _res
= Py_BuildValue("h",
193 static PyObject
*Folder_AddFolderRouting(PyObject
*_self
, PyObject
*_args
)
195 PyObject
*_res
= NULL
;
198 FolderType routeFromFolder
;
199 FolderType routeToFolder
;
202 if (!PyArg_ParseTuple(_args
, "O&O&O&lb",
203 PyMac_GetOSType
, &fileType
,
204 PyMac_GetOSType
, &routeFromFolder
,
205 PyMac_GetOSType
, &routeToFolder
,
209 _err
= AddFolderRouting(fileType
,
214 if (_err
!= noErr
) return PyMac_Error(_err
);
220 static PyObject
*Folder_RemoveFolderRouting(PyObject
*_self
, PyObject
*_args
)
222 PyObject
*_res
= NULL
;
225 FolderType routeFromFolder
;
226 if (!PyArg_ParseTuple(_args
, "O&O&",
227 PyMac_GetOSType
, &fileType
,
228 PyMac_GetOSType
, &routeFromFolder
))
230 _err
= RemoveFolderRouting(fileType
,
232 if (_err
!= noErr
) return PyMac_Error(_err
);
238 static PyObject
*Folder_FindFolderRouting(PyObject
*_self
, PyObject
*_args
)
240 PyObject
*_res
= NULL
;
243 FolderType routeFromFolder
;
244 FolderType routeToFolder
;
246 if (!PyArg_ParseTuple(_args
, "O&O&",
247 PyMac_GetOSType
, &fileType
,
248 PyMac_GetOSType
, &routeFromFolder
))
250 _err
= FindFolderRouting(fileType
,
254 if (_err
!= noErr
) return PyMac_Error(_err
);
255 _res
= Py_BuildValue("O&l",
256 PyMac_BuildOSType
, routeToFolder
,
261 static PyObject
*Folder_InvalidateFolderDescriptorCache(PyObject
*_self
, PyObject
*_args
)
263 PyObject
*_res
= NULL
;
267 if (!PyArg_ParseTuple(_args
, "hl",
271 _err
= InvalidateFolderDescriptorCache(vRefNum
,
273 if (_err
!= noErr
) return PyMac_Error(_err
);
279 static PyObject
*Folder_IdentifyFolder(PyObject
*_self
, PyObject
*_args
)
281 PyObject
*_res
= NULL
;
286 if (!PyArg_ParseTuple(_args
, "hl",
290 _err
= IdentifyFolder(vRefNum
,
293 if (_err
!= noErr
) return PyMac_Error(_err
);
294 _res
= Py_BuildValue("O&",
295 PyMac_BuildOSType
, foldType
);
299 static PyMethodDef Folder_methods
[] = {
300 {"FindFolder", (PyCFunction
)Folder_FindFolder
, 1,
301 PyDoc_STR("(short vRefNum, OSType folderType, Boolean createFolder) -> (short foundVRefNum, long foundDirID)")},
302 {"ReleaseFolder", (PyCFunction
)Folder_ReleaseFolder
, 1,
303 PyDoc_STR("(short vRefNum, OSType folderType) -> None")},
304 {"FSFindFolder", (PyCFunction
)Folder_FSFindFolder
, 1,
305 PyDoc_STR("(short vRefNum, OSType folderType, Boolean createFolder) -> (FSRef foundRef)")},
306 {"AddFolderDescriptor", (PyCFunction
)Folder_AddFolderDescriptor
, 1,
307 PyDoc_STR("(FolderType foldType, FolderDescFlags flags, FolderClass foldClass, FolderLocation foldLocation, OSType badgeSignature, OSType badgeType, Str255 name, Boolean replaceFlag) -> None")},
308 {"GetFolderTypes", (PyCFunction
)Folder_GetFolderTypes
, 1,
309 PyDoc_STR("(UInt32 requestedTypeCount) -> (UInt32 totalTypeCount, FolderType theTypes)")},
310 {"RemoveFolderDescriptor", (PyCFunction
)Folder_RemoveFolderDescriptor
, 1,
311 PyDoc_STR("(FolderType foldType) -> None")},
312 {"GetFolderName", (PyCFunction
)Folder_GetFolderName
, 1,
313 PyDoc_STR("(short vRefNum, OSType foldType, Str255 name) -> (short foundVRefNum)")},
314 {"AddFolderRouting", (PyCFunction
)Folder_AddFolderRouting
, 1,
315 PyDoc_STR("(OSType fileType, FolderType routeFromFolder, FolderType routeToFolder, RoutingFlags flags, Boolean replaceFlag) -> None")},
316 {"RemoveFolderRouting", (PyCFunction
)Folder_RemoveFolderRouting
, 1,
317 PyDoc_STR("(OSType fileType, FolderType routeFromFolder) -> None")},
318 {"FindFolderRouting", (PyCFunction
)Folder_FindFolderRouting
, 1,
319 PyDoc_STR("(OSType fileType, FolderType routeFromFolder) -> (FolderType routeToFolder, RoutingFlags flags)")},
320 {"InvalidateFolderDescriptorCache", (PyCFunction
)Folder_InvalidateFolderDescriptorCache
, 1,
321 PyDoc_STR("(short vRefNum, long dirID) -> None")},
322 {"IdentifyFolder", (PyCFunction
)Folder_IdentifyFolder
, 1,
323 PyDoc_STR("(short vRefNum, long dirID) -> (FolderType foldType)")},
330 void init_Folder(void)
338 m
= Py_InitModule("_Folder", Folder_methods
);
339 d
= PyModule_GetDict(m
);
340 Folder_Error
= PyMac_GetOSErrException();
341 if (Folder_Error
== NULL
||
342 PyDict_SetItemString(d
, "Error", Folder_Error
) != 0)
346 /* ======================= End module _Folder ======================= */