2 /* ========================= Module _Folder ========================= */
8 #include "pymactoolbox.h"
10 /* Macro to test whether a weak-loaded CFM function exists */
11 #define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
12 PyErr_SetString(PyExc_NotImplementedError, \
13 "Not available in this shared library/OS version"); \
18 #include <Carbon/Carbon.h>
21 static PyObject
*Folder_Error
;
23 static PyObject
*Folder_FindFolder(PyObject
*_self
, PyObject
*_args
)
25 PyObject
*_res
= NULL
;
30 FSVolumeRefNum foundVRefNum
;
32 if (!PyArg_ParseTuple(_args
, "hO&b",
34 PyMac_GetOSType
, &folderType
,
37 _err
= FindFolder(vRefNum
,
42 if (_err
!= noErr
) return PyMac_Error(_err
);
43 _res
= Py_BuildValue("hl",
49 static PyObject
*Folder_ReleaseFolder(PyObject
*_self
, PyObject
*_args
)
51 PyObject
*_res
= NULL
;
55 if (!PyArg_ParseTuple(_args
, "hO&",
57 PyMac_GetOSType
, &folderType
))
59 _err
= ReleaseFolder(vRefNum
,
61 if (_err
!= noErr
) return PyMac_Error(_err
);
67 static PyObject
*Folder_FSFindFolder(PyObject
*_self
, PyObject
*_args
)
69 PyObject
*_res
= NULL
;
75 if (!PyArg_ParseTuple(_args
, "hO&b",
77 PyMac_GetOSType
, &folderType
,
80 _err
= FSFindFolder(vRefNum
,
84 if (_err
!= noErr
) return PyMac_Error(_err
);
85 _res
= Py_BuildValue("O&",
86 PyMac_BuildFSRef
, &foundRef
);
90 static PyObject
*Folder_AddFolderDescriptor(PyObject
*_self
, PyObject
*_args
)
92 PyObject
*_res
= NULL
;
95 FolderDescFlags flags
;
96 FolderClass foldClass
;
97 FolderLocation foldLocation
;
98 OSType badgeSignature
;
102 if (!PyArg_ParseTuple(_args
, "O&lO&O&O&O&O&b",
103 PyMac_GetOSType
, &foldType
,
105 PyMac_GetOSType
, &foldClass
,
106 PyMac_GetOSType
, &foldLocation
,
107 PyMac_GetOSType
, &badgeSignature
,
108 PyMac_GetOSType
, &badgeType
,
109 PyMac_GetStr255
, name
,
112 _err
= AddFolderDescriptor(foldType
,
120 if (_err
!= noErr
) return PyMac_Error(_err
);
126 static PyObject
*Folder_GetFolderTypes(PyObject
*_self
, PyObject
*_args
)
128 PyObject
*_res
= NULL
;
130 UInt32 requestedTypeCount
;
131 UInt32 totalTypeCount
;
133 if (!PyArg_ParseTuple(_args
, "l",
134 &requestedTypeCount
))
136 _err
= GetFolderTypes(requestedTypeCount
,
139 if (_err
!= noErr
) return PyMac_Error(_err
);
140 _res
= Py_BuildValue("lO&",
142 PyMac_BuildOSType
, theTypes
);
146 static PyObject
*Folder_RemoveFolderDescriptor(PyObject
*_self
, PyObject
*_args
)
148 PyObject
*_res
= NULL
;
151 if (!PyArg_ParseTuple(_args
, "O&",
152 PyMac_GetOSType
, &foldType
))
154 _err
= RemoveFolderDescriptor(foldType
);
155 if (_err
!= noErr
) return PyMac_Error(_err
);
162 static PyObject
*Folder_GetFolderName(PyObject
*_self
, PyObject
*_args
)
164 PyObject
*_res
= NULL
;
170 if (!PyArg_ParseTuple(_args
, "hO&O&",
172 PyMac_GetOSType
, &foldType
,
173 PyMac_GetStr255
, name
))
175 _err
= GetFolderName(vRefNum
,
179 if (_err
!= noErr
) return PyMac_Error(_err
);
180 _res
= Py_BuildValue("h",
185 static PyObject
*Folder_AddFolderRouting(PyObject
*_self
, PyObject
*_args
)
187 PyObject
*_res
= NULL
;
190 FolderType routeFromFolder
;
191 FolderType routeToFolder
;
194 if (!PyArg_ParseTuple(_args
, "O&O&O&lb",
195 PyMac_GetOSType
, &fileType
,
196 PyMac_GetOSType
, &routeFromFolder
,
197 PyMac_GetOSType
, &routeToFolder
,
201 _err
= AddFolderRouting(fileType
,
206 if (_err
!= noErr
) return PyMac_Error(_err
);
212 static PyObject
*Folder_RemoveFolderRouting(PyObject
*_self
, PyObject
*_args
)
214 PyObject
*_res
= NULL
;
217 FolderType routeFromFolder
;
218 if (!PyArg_ParseTuple(_args
, "O&O&",
219 PyMac_GetOSType
, &fileType
,
220 PyMac_GetOSType
, &routeFromFolder
))
222 _err
= RemoveFolderRouting(fileType
,
224 if (_err
!= noErr
) return PyMac_Error(_err
);
230 static PyObject
*Folder_FindFolderRouting(PyObject
*_self
, PyObject
*_args
)
232 PyObject
*_res
= NULL
;
235 FolderType routeFromFolder
;
236 FolderType routeToFolder
;
238 if (!PyArg_ParseTuple(_args
, "O&O&",
239 PyMac_GetOSType
, &fileType
,
240 PyMac_GetOSType
, &routeFromFolder
))
242 _err
= FindFolderRouting(fileType
,
246 if (_err
!= noErr
) return PyMac_Error(_err
);
247 _res
= Py_BuildValue("O&l",
248 PyMac_BuildOSType
, routeToFolder
,
252 #endif /* !__LP64__ */
254 static PyObject
*Folder_InvalidateFolderDescriptorCache(PyObject
*_self
, PyObject
*_args
)
256 PyObject
*_res
= NULL
;
260 if (!PyArg_ParseTuple(_args
, "hl",
264 _err
= InvalidateFolderDescriptorCache(vRefNum
,
266 if (_err
!= noErr
) return PyMac_Error(_err
);
272 static PyObject
*Folder_IdentifyFolder(PyObject
*_self
, PyObject
*_args
)
274 PyObject
*_res
= NULL
;
279 if (!PyArg_ParseTuple(_args
, "hl",
283 _err
= IdentifyFolder(vRefNum
,
286 if (_err
!= noErr
) return PyMac_Error(_err
);
287 _res
= Py_BuildValue("O&",
288 PyMac_BuildOSType
, foldType
);
292 static PyMethodDef Folder_methods
[] = {
293 {"FindFolder", (PyCFunction
)Folder_FindFolder
, 1,
294 PyDoc_STR("(short vRefNum, OSType folderType, Boolean createFolder) -> (short foundVRefNum, long foundDirID)")},
295 {"ReleaseFolder", (PyCFunction
)Folder_ReleaseFolder
, 1,
296 PyDoc_STR("(short vRefNum, OSType folderType) -> None")},
297 {"FSFindFolder", (PyCFunction
)Folder_FSFindFolder
, 1,
298 PyDoc_STR("(short vRefNum, OSType folderType, Boolean createFolder) -> (FSRef foundRef)")},
299 {"AddFolderDescriptor", (PyCFunction
)Folder_AddFolderDescriptor
, 1,
300 PyDoc_STR("(FolderType foldType, FolderDescFlags flags, FolderClass foldClass, FolderLocation foldLocation, OSType badgeSignature, OSType badgeType, Str255 name, Boolean replaceFlag) -> None")},
301 {"GetFolderTypes", (PyCFunction
)Folder_GetFolderTypes
, 1,
302 PyDoc_STR("(UInt32 requestedTypeCount) -> (UInt32 totalTypeCount, FolderType theTypes)")},
303 {"RemoveFolderDescriptor", (PyCFunction
)Folder_RemoveFolderDescriptor
, 1,
304 PyDoc_STR("(FolderType foldType) -> None")},
306 {"GetFolderName", (PyCFunction
)Folder_GetFolderName
, 1,
307 PyDoc_STR("(short vRefNum, OSType foldType, Str255 name) -> (short foundVRefNum)")},
308 {"AddFolderRouting", (PyCFunction
)Folder_AddFolderRouting
, 1,
309 PyDoc_STR("(OSType fileType, FolderType routeFromFolder, FolderType routeToFolder, RoutingFlags flags, Boolean replaceFlag) -> None")},
310 {"RemoveFolderRouting", (PyCFunction
)Folder_RemoveFolderRouting
, 1,
311 PyDoc_STR("(OSType fileType, FolderType routeFromFolder) -> None")},
312 {"FindFolderRouting", (PyCFunction
)Folder_FindFolderRouting
, 1,
313 PyDoc_STR("(OSType fileType, FolderType routeFromFolder) -> (FolderType routeToFolder, RoutingFlags flags)")},
314 #endif /* !__LP64__ */
315 {"InvalidateFolderDescriptorCache", (PyCFunction
)Folder_InvalidateFolderDescriptorCache
, 1,
316 PyDoc_STR("(short vRefNum, long dirID) -> None")},
317 {"IdentifyFolder", (PyCFunction
)Folder_IdentifyFolder
, 1,
318 PyDoc_STR("(short vRefNum, long dirID) -> (FolderType foldType)")},
325 void init_Folder(void)
333 m
= Py_InitModule("_Folder", Folder_methods
);
334 d
= PyModule_GetDict(m
);
335 Folder_Error
= PyMac_GetOSErrException();
336 if (Folder_Error
== NULL
||
337 PyDict_SetItemString(d
, "Error", Folder_Error
) != 0)
341 /* ======================= End module _Folder ======================= */