| 1 | n/a | /*********************************************************** |
|---|
| 2 | n/a | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
|---|
| 3 | n/a | The Netherlands. |
|---|
| 4 | n/a | |
|---|
| 5 | n/a | All Rights Reserved |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | Permission to use, copy, modify, and distribute this software and its |
|---|
| 8 | n/a | documentation for any purpose and without fee is hereby granted, |
|---|
| 9 | n/a | provided that the above copyright notice appear in all copies and that |
|---|
| 10 | n/a | both that copyright notice and this permission notice appear in |
|---|
| 11 | n/a | supporting documentation, and that the names of Stichting Mathematisch |
|---|
| 12 | n/a | Centrum or CWI or Corporation for National Research Initiatives or |
|---|
| 13 | n/a | CNRI not be used in advertising or publicity pertaining to |
|---|
| 14 | n/a | distribution of the software without specific, written prior |
|---|
| 15 | n/a | permission. |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | While CWI is the initial source for this software, a modified version |
|---|
| 18 | n/a | is made available by the Corporation for National Research Initiatives |
|---|
| 19 | n/a | (CNRI) at the Internet address ftp://ftp.python.org. |
|---|
| 20 | n/a | |
|---|
| 21 | n/a | STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH |
|---|
| 22 | n/a | REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF |
|---|
| 23 | n/a | MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH |
|---|
| 24 | n/a | CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL |
|---|
| 25 | n/a | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
|---|
| 26 | n/a | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
|---|
| 27 | n/a | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
|---|
| 28 | n/a | PERFORMANCE OF THIS SOFTWARE. |
|---|
| 29 | n/a | |
|---|
| 30 | n/a | ******************************************************************/ |
|---|
| 31 | n/a | |
|---|
| 32 | n/a | #include "Python.h" |
|---|
| 33 | n/a | #include "pymactoolbox.h" |
|---|
| 34 | n/a | #include <Carbon/Carbon.h> |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | #ifndef __LP64__ |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | static PyObject *ErrorObject; |
|---|
| 39 | n/a | |
|---|
| 40 | n/a | static NavEventUPP my_eventProcUPP; |
|---|
| 41 | n/a | static NavPreviewUPP my_previewProcUPP; |
|---|
| 42 | n/a | static NavObjectFilterUPP my_filterProcUPP; |
|---|
| 43 | n/a | |
|---|
| 44 | n/a | /* Callback functions */ |
|---|
| 45 | n/a | static pascal void |
|---|
| 46 | n/a | my_eventProc(NavEventCallbackMessage callBackSelector, |
|---|
| 47 | n/a | NavCBRecPtr callBackParms, |
|---|
| 48 | n/a | NavCallBackUserData callbackUD) |
|---|
| 49 | n/a | { |
|---|
| 50 | n/a | PyObject *dict = (PyObject *)callbackUD; |
|---|
| 51 | n/a | PyObject *pyfunc; |
|---|
| 52 | n/a | PyObject *rv; |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | if (!dict) return; |
|---|
| 55 | n/a | if ( (pyfunc = PyDict_GetItemString(dict, "eventProc")) == NULL ) { |
|---|
| 56 | n/a | PyErr_Print(); |
|---|
| 57 | n/a | return; |
|---|
| 58 | n/a | } |
|---|
| 59 | n/a | if ( pyfunc == Py_None ) { |
|---|
| 60 | n/a | return; |
|---|
| 61 | n/a | } |
|---|
| 62 | n/a | rv = PyObject_CallFunction(pyfunc, "ls#", (long)callBackSelector, |
|---|
| 63 | n/a | (void *)callBackParms, sizeof(NavCBRec)); |
|---|
| 64 | n/a | if ( rv ) |
|---|
| 65 | n/a | Py_DECREF(rv); |
|---|
| 66 | n/a | else { |
|---|
| 67 | n/a | PySys_WriteStderr("Nav: exception in eventProc callback\n"); |
|---|
| 68 | n/a | PyErr_Print(); |
|---|
| 69 | n/a | } |
|---|
| 70 | n/a | } |
|---|
| 71 | n/a | |
|---|
| 72 | n/a | static pascal Boolean |
|---|
| 73 | n/a | my_previewProc(NavCBRecPtr callBackParms, |
|---|
| 74 | n/a | NavCallBackUserData callbackUD) |
|---|
| 75 | n/a | { |
|---|
| 76 | n/a | PyObject *dict = (PyObject *)callbackUD; |
|---|
| 77 | n/a | PyObject *pyfunc; |
|---|
| 78 | n/a | PyObject *rv; |
|---|
| 79 | n/a | Boolean c_rv = false; |
|---|
| 80 | n/a | |
|---|
| 81 | n/a | if (!dict) return false; |
|---|
| 82 | n/a | if ( (pyfunc = PyDict_GetItemString(dict, "previewProc")) == NULL ) { |
|---|
| 83 | n/a | PyErr_Print(); |
|---|
| 84 | n/a | return false; |
|---|
| 85 | n/a | } |
|---|
| 86 | n/a | rv = PyObject_CallFunction(pyfunc, "s#", (void *)callBackParms, sizeof(NavCBRec)); |
|---|
| 87 | n/a | if ( rv ) { |
|---|
| 88 | n/a | c_rv = PyObject_IsTrue(rv); |
|---|
| 89 | n/a | Py_DECREF(rv); |
|---|
| 90 | n/a | } else { |
|---|
| 91 | n/a | PySys_WriteStderr("Nav: exception in previewProc callback\n"); |
|---|
| 92 | n/a | PyErr_Print(); |
|---|
| 93 | n/a | } |
|---|
| 94 | n/a | return c_rv; |
|---|
| 95 | n/a | } |
|---|
| 96 | n/a | |
|---|
| 97 | n/a | static pascal Boolean |
|---|
| 98 | n/a | my_filterProc(AEDesc *theItem, void *info, |
|---|
| 99 | n/a | NavCallBackUserData callbackUD, |
|---|
| 100 | n/a | NavFilterModes filterMode) |
|---|
| 101 | n/a | { |
|---|
| 102 | n/a | PyObject *dict = (PyObject *)callbackUD; |
|---|
| 103 | n/a | PyObject *pyfunc; |
|---|
| 104 | n/a | PyObject *rv; |
|---|
| 105 | n/a | Boolean c_rv = false; |
|---|
| 106 | n/a | |
|---|
| 107 | n/a | if (!dict) return false; |
|---|
| 108 | n/a | if ( (pyfunc = PyDict_GetItemString(dict, "filterProc")) == NULL ) { |
|---|
| 109 | n/a | PyErr_Print(); |
|---|
| 110 | n/a | return false; |
|---|
| 111 | n/a | } |
|---|
| 112 | n/a | rv = PyObject_CallFunction(pyfunc, "O&s#h", |
|---|
| 113 | n/a | AEDesc_NewBorrowed, theItem, info, sizeof(NavFileOrFolderInfo), (short)filterMode); |
|---|
| 114 | n/a | if ( rv ) { |
|---|
| 115 | n/a | c_rv = PyObject_IsTrue(rv); |
|---|
| 116 | n/a | Py_DECREF(rv); |
|---|
| 117 | n/a | } else { |
|---|
| 118 | n/a | PySys_WriteStderr("Nav: exception in filterProc callback\n"); |
|---|
| 119 | n/a | PyErr_Print(); |
|---|
| 120 | n/a | } |
|---|
| 121 | n/a | return c_rv; |
|---|
| 122 | n/a | } |
|---|
| 123 | n/a | |
|---|
| 124 | n/a | /* ----------------------------------------------------- */ |
|---|
| 125 | n/a | static int |
|---|
| 126 | n/a | filldialogoptions(PyObject *d, |
|---|
| 127 | n/a | AEDesc **defaultLocationP, |
|---|
| 128 | n/a | NavDialogOptions *opt, |
|---|
| 129 | n/a | NavEventUPP *eventProcP, |
|---|
| 130 | n/a | NavPreviewUPP *previewProcP, |
|---|
| 131 | n/a | NavObjectFilterUPP *filterProcP, |
|---|
| 132 | n/a | NavTypeListHandle *typeListP, |
|---|
| 133 | n/a | OSType *fileTypeP, |
|---|
| 134 | n/a | OSType *fileCreatorP) |
|---|
| 135 | n/a | { |
|---|
| 136 | n/a | Py_ssize_t pos = 0; |
|---|
| 137 | n/a | PyObject *key, *value; |
|---|
| 138 | n/a | char *keystr; |
|---|
| 139 | n/a | AEDesc *defaultLocation_storage; |
|---|
| 140 | n/a | |
|---|
| 141 | n/a | NavGetDefaultDialogOptions(opt); |
|---|
| 142 | n/a | |
|---|
| 143 | n/a | while ( PyDict_Next(d, &pos, &key, &value) ) { |
|---|
| 144 | n/a | if ( !key || !value || !PyString_Check(key) ) { |
|---|
| 145 | n/a | PyErr_SetString(ErrorObject, "DialogOption has non-string key"); |
|---|
| 146 | n/a | return 0; |
|---|
| 147 | n/a | } |
|---|
| 148 | n/a | keystr = PyString_AsString(key); |
|---|
| 149 | n/a | if( strcmp(keystr, "defaultLocation") == 0 ) { |
|---|
| 150 | n/a | if ( (defaultLocation_storage = PyMem_NEW(AEDesc, 1)) == NULL ) { |
|---|
| 151 | n/a | PyErr_NoMemory(); |
|---|
| 152 | n/a | return 0; |
|---|
| 153 | n/a | } |
|---|
| 154 | n/a | if ( !PyArg_Parse(value, "O&", AEDesc_Convert, defaultLocation_storage) ) { |
|---|
| 155 | n/a | PyMem_DEL(defaultLocation_storage); |
|---|
| 156 | n/a | return 0; |
|---|
| 157 | n/a | } |
|---|
| 158 | n/a | *defaultLocationP = defaultLocation_storage; |
|---|
| 159 | n/a | } else if( strcmp(keystr, "version") == 0 ) { |
|---|
| 160 | n/a | if ( !PyArg_Parse(value, "H", &opt->version) ) |
|---|
| 161 | n/a | return 0; |
|---|
| 162 | n/a | } else if( strcmp(keystr, "dialogOptionFlags") == 0 ) { |
|---|
| 163 | n/a | if ( !PyArg_Parse(value, "k", &opt->dialogOptionFlags) ) |
|---|
| 164 | n/a | return 0; |
|---|
| 165 | n/a | } else if( strcmp(keystr, "location") == 0 ) { |
|---|
| 166 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetPoint, &opt->location) ) |
|---|
| 167 | n/a | return 0; |
|---|
| 168 | n/a | } else if( strcmp(keystr, "clientName") == 0 ) { |
|---|
| 169 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->clientName) ) |
|---|
| 170 | n/a | return 0; |
|---|
| 171 | n/a | } else if( strcmp(keystr, "windowTitle") == 0 ) { |
|---|
| 172 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->windowTitle) ) |
|---|
| 173 | n/a | return 0; |
|---|
| 174 | n/a | } else if( strcmp(keystr, "actionButtonLabel") == 0 ) { |
|---|
| 175 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->actionButtonLabel) ) |
|---|
| 176 | n/a | return 0; |
|---|
| 177 | n/a | } else if( strcmp(keystr, "cancelButtonLabel") == 0 ) { |
|---|
| 178 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->cancelButtonLabel) ) |
|---|
| 179 | n/a | return 0; |
|---|
| 180 | n/a | } else if( strcmp(keystr, "savedFileName") == 0 ) { |
|---|
| 181 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->savedFileName) ) |
|---|
| 182 | n/a | return 0; |
|---|
| 183 | n/a | } else if( strcmp(keystr, "message") == 0 ) { |
|---|
| 184 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetStr255, &opt->message) ) |
|---|
| 185 | n/a | return 0; |
|---|
| 186 | n/a | } else if( strcmp(keystr, "preferenceKey") == 0 ) { |
|---|
| 187 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetOSType, &opt->preferenceKey) ) |
|---|
| 188 | n/a | return 0; |
|---|
| 189 | n/a | } else if( strcmp(keystr, "popupExtension") == 0 ) { |
|---|
| 190 | n/a | if ( !PyArg_Parse(value, "O&", ResObj_Convert, &opt->popupExtension) ) |
|---|
| 191 | n/a | return 0; |
|---|
| 192 | n/a | } else if( eventProcP && strcmp(keystr, "eventProc") == 0 ) { |
|---|
| 193 | n/a | *eventProcP = my_eventProcUPP; |
|---|
| 194 | n/a | } else if( previewProcP && strcmp(keystr, "previewProc") == 0 ) { |
|---|
| 195 | n/a | *previewProcP = my_previewProcUPP; |
|---|
| 196 | n/a | } else if( filterProcP && strcmp(keystr, "filterProc") == 0 ) { |
|---|
| 197 | n/a | *filterProcP = my_filterProcUPP; |
|---|
| 198 | n/a | } else if( typeListP && strcmp(keystr, "typeList") == 0 ) { |
|---|
| 199 | n/a | if ( !PyArg_Parse(value, "O&", ResObj_Convert, typeListP) ) |
|---|
| 200 | n/a | return 0; |
|---|
| 201 | n/a | } else if( fileTypeP && strcmp(keystr, "fileType") == 0 ) { |
|---|
| 202 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetOSType, fileTypeP) ) |
|---|
| 203 | n/a | return 0; |
|---|
| 204 | n/a | } else if( fileCreatorP && strcmp(keystr, "fileCreator") == 0 ) { |
|---|
| 205 | n/a | if ( !PyArg_Parse(value, "O&", PyMac_GetOSType, fileCreatorP) ) |
|---|
| 206 | n/a | return 0; |
|---|
| 207 | n/a | } else { |
|---|
| 208 | n/a | PyErr_Format(ErrorObject, "Unknown DialogOption key: %s", keystr); |
|---|
| 209 | n/a | return 0; |
|---|
| 210 | n/a | } |
|---|
| 211 | n/a | } |
|---|
| 212 | n/a | return 1; |
|---|
| 213 | n/a | } |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | /* ----------------------------------------------------- */ |
|---|
| 216 | n/a | |
|---|
| 217 | n/a | /* Declarations for objects of type NavReplyRecord */ |
|---|
| 218 | n/a | |
|---|
| 219 | n/a | typedef struct { |
|---|
| 220 | n/a | PyObject_HEAD |
|---|
| 221 | n/a | NavReplyRecord itself; |
|---|
| 222 | n/a | } navrrobject; |
|---|
| 223 | n/a | |
|---|
| 224 | n/a | static PyTypeObject Navrrtype; |
|---|
| 225 | n/a | |
|---|
| 226 | n/a | |
|---|
| 227 | n/a | |
|---|
| 228 | n/a | /* ---------------------------------------------------------------- */ |
|---|
| 229 | n/a | |
|---|
| 230 | n/a | static char nav_NavTranslateFile__doc__[] = |
|---|
| 231 | n/a | "(NavTranslationOptions)->None" |
|---|
| 232 | n/a | ; |
|---|
| 233 | n/a | |
|---|
| 234 | n/a | static PyObject * |
|---|
| 235 | n/a | nav_NavTranslateFile(navrrobject *self, PyObject *args) |
|---|
| 236 | n/a | { |
|---|
| 237 | n/a | NavTranslationOptions howToTranslate; |
|---|
| 238 | n/a | OSErr err; |
|---|
| 239 | n/a | |
|---|
| 240 | n/a | if (!PyArg_ParseTuple(args, "k", &howToTranslate)) |
|---|
| 241 | n/a | return NULL; |
|---|
| 242 | n/a | err = NavTranslateFile(&self->itself, howToTranslate); |
|---|
| 243 | n/a | if ( err ) { |
|---|
| 244 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 245 | n/a | return NULL; |
|---|
| 246 | n/a | } |
|---|
| 247 | n/a | Py_INCREF(Py_None); |
|---|
| 248 | n/a | return Py_None; |
|---|
| 249 | n/a | } |
|---|
| 250 | n/a | |
|---|
| 251 | n/a | static char nav_NavCompleteSave__doc__[] = |
|---|
| 252 | n/a | "(NavTranslationOptions)->None" |
|---|
| 253 | n/a | ; |
|---|
| 254 | n/a | |
|---|
| 255 | n/a | static PyObject * |
|---|
| 256 | n/a | nav_NavCompleteSave(navrrobject *self, PyObject *args) |
|---|
| 257 | n/a | { |
|---|
| 258 | n/a | NavTranslationOptions howToTranslate; |
|---|
| 259 | n/a | OSErr err; |
|---|
| 260 | n/a | |
|---|
| 261 | n/a | if (!PyArg_ParseTuple(args, "k", &howToTranslate)) |
|---|
| 262 | n/a | return NULL; |
|---|
| 263 | n/a | err = NavCompleteSave(&self->itself, howToTranslate); |
|---|
| 264 | n/a | if ( err ) { |
|---|
| 265 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 266 | n/a | return NULL; |
|---|
| 267 | n/a | } |
|---|
| 268 | n/a | Py_INCREF(Py_None); |
|---|
| 269 | n/a | return Py_None; |
|---|
| 270 | n/a | } |
|---|
| 271 | n/a | |
|---|
| 272 | n/a | |
|---|
| 273 | n/a | static struct PyMethodDef navrr_methods[] = { |
|---|
| 274 | n/a | {"NavTranslateFile", (PyCFunction)nav_NavTranslateFile, METH_VARARGS, nav_NavTranslateFile__doc__}, |
|---|
| 275 | n/a | {"NavCompleteSave", (PyCFunction)nav_NavCompleteSave, METH_VARARGS, nav_NavCompleteSave__doc__}, |
|---|
| 276 | n/a | |
|---|
| 277 | n/a | {NULL, NULL} /* sentinel */ |
|---|
| 278 | n/a | }; |
|---|
| 279 | n/a | |
|---|
| 280 | n/a | /* ---------- */ |
|---|
| 281 | n/a | |
|---|
| 282 | n/a | |
|---|
| 283 | n/a | static navrrobject * |
|---|
| 284 | n/a | newnavrrobject(NavReplyRecord *itself) |
|---|
| 285 | n/a | { |
|---|
| 286 | n/a | navrrobject *self; |
|---|
| 287 | n/a | |
|---|
| 288 | n/a | self = PyObject_NEW(navrrobject, &Navrrtype); |
|---|
| 289 | n/a | if (self == NULL) |
|---|
| 290 | n/a | return NULL; |
|---|
| 291 | n/a | self->itself = *itself; |
|---|
| 292 | n/a | return self; |
|---|
| 293 | n/a | } |
|---|
| 294 | n/a | |
|---|
| 295 | n/a | |
|---|
| 296 | n/a | static void |
|---|
| 297 | n/a | navrr_dealloc(navrrobject *self) |
|---|
| 298 | n/a | { |
|---|
| 299 | n/a | NavDisposeReply(&self->itself); |
|---|
| 300 | n/a | PyObject_DEL(self); |
|---|
| 301 | n/a | } |
|---|
| 302 | n/a | |
|---|
| 303 | n/a | static PyObject * |
|---|
| 304 | n/a | navrr_getattr(navrrobject *self, char *name) |
|---|
| 305 | n/a | { |
|---|
| 306 | n/a | FSRef fsr; |
|---|
| 307 | n/a | FSSpec fss; |
|---|
| 308 | n/a | |
|---|
| 309 | n/a | if( strcmp(name, "__members__") == 0 ) |
|---|
| 310 | n/a | return Py_BuildValue( |
|---|
| 311 | n/a | "ssssssssss", |
|---|
| 312 | n/a | "version", "validRecord", "replacing", |
|---|
| 313 | n/a | "isStationery", "translationNeeded", |
|---|
| 314 | n/a | "selection", |
|---|
| 315 | n/a | "selection_fsr", |
|---|
| 316 | n/a | "fileTranslation", "keyScript", "saveFileName"); |
|---|
| 317 | n/a | |
|---|
| 318 | n/a | if( strcmp(name, "version") == 0 ) |
|---|
| 319 | n/a | return Py_BuildValue("h", self->itself.version); |
|---|
| 320 | n/a | if( strcmp(name, "validRecord") == 0 ) |
|---|
| 321 | n/a | return Py_BuildValue("l", (long)self->itself.validRecord); |
|---|
| 322 | n/a | if( strcmp(name, "replacing") == 0 ) |
|---|
| 323 | n/a | return Py_BuildValue("l", (long)self->itself.replacing); |
|---|
| 324 | n/a | if( strcmp(name, "isStationery") == 0 ) |
|---|
| 325 | n/a | return Py_BuildValue("l", (long)self->itself.isStationery); |
|---|
| 326 | n/a | if( strcmp(name, "translationNeeded") == 0 ) |
|---|
| 327 | n/a | return Py_BuildValue("l", (long)self->itself.translationNeeded); |
|---|
| 328 | n/a | if( strcmp(name, "selection") == 0 ) { |
|---|
| 329 | n/a | SInt32 i; |
|---|
| 330 | n/a | long count; |
|---|
| 331 | n/a | OSErr err; |
|---|
| 332 | n/a | PyObject *rv, *rvitem; |
|---|
| 333 | n/a | AEDesc desc; |
|---|
| 334 | n/a | |
|---|
| 335 | n/a | if ((err=AECountItems(&self->itself.selection, &count))) { |
|---|
| 336 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 337 | n/a | return NULL; |
|---|
| 338 | n/a | } |
|---|
| 339 | n/a | if ( (rv=PyList_New(count)) == NULL ) |
|---|
| 340 | n/a | return NULL; |
|---|
| 341 | n/a | for(i=0; i<count; i++) { |
|---|
| 342 | n/a | desc.dataHandle = NULL; |
|---|
| 343 | n/a | if ((err=AEGetNthDesc(&self->itself.selection, i+1, typeFSS, NULL, &desc))) { |
|---|
| 344 | n/a | Py_DECREF(rv); |
|---|
| 345 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 346 | n/a | return NULL; |
|---|
| 347 | n/a | } |
|---|
| 348 | n/a | if ((err=AEGetDescData(&desc, &fss, sizeof(FSSpec)))) { |
|---|
| 349 | n/a | Py_DECREF(rv); |
|---|
| 350 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 351 | n/a | return NULL; |
|---|
| 352 | n/a | } |
|---|
| 353 | n/a | rvitem = PyMac_BuildFSSpec(&fss); |
|---|
| 354 | n/a | PyList_SetItem(rv, i, rvitem); |
|---|
| 355 | n/a | AEDisposeDesc(&desc); |
|---|
| 356 | n/a | } |
|---|
| 357 | n/a | return rv; |
|---|
| 358 | n/a | } |
|---|
| 359 | n/a | if( strcmp(name, "selection_fsr") == 0 ) { |
|---|
| 360 | n/a | SInt32 i; |
|---|
| 361 | n/a | long count; |
|---|
| 362 | n/a | OSErr err; |
|---|
| 363 | n/a | PyObject *rv, *rvitem; |
|---|
| 364 | n/a | AEDesc desc; |
|---|
| 365 | n/a | |
|---|
| 366 | n/a | if ((err=AECountItems(&self->itself.selection, &count))) { |
|---|
| 367 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 368 | n/a | return NULL; |
|---|
| 369 | n/a | } |
|---|
| 370 | n/a | if ( (rv=PyList_New(count)) == NULL ) |
|---|
| 371 | n/a | return NULL; |
|---|
| 372 | n/a | for(i=0; i<count; i++) { |
|---|
| 373 | n/a | desc.dataHandle = NULL; |
|---|
| 374 | n/a | if ((err=AEGetNthDesc(&self->itself.selection, i+1, typeFSRef, NULL, &desc))) { |
|---|
| 375 | n/a | Py_DECREF(rv); |
|---|
| 376 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 377 | n/a | return NULL; |
|---|
| 378 | n/a | } |
|---|
| 379 | n/a | if ((err=AEGetDescData(&desc, &fsr, sizeof(FSRef)))) { |
|---|
| 380 | n/a | Py_DECREF(rv); |
|---|
| 381 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 382 | n/a | return NULL; |
|---|
| 383 | n/a | } |
|---|
| 384 | n/a | rvitem = PyMac_BuildFSRef(&fsr); |
|---|
| 385 | n/a | PyList_SetItem(rv, i, rvitem); |
|---|
| 386 | n/a | AEDisposeDesc(&desc); |
|---|
| 387 | n/a | } |
|---|
| 388 | n/a | return rv; |
|---|
| 389 | n/a | } |
|---|
| 390 | n/a | if( strcmp(name, "fileTranslation") == 0 ) |
|---|
| 391 | n/a | return ResObj_New((Handle)self->itself.fileTranslation); |
|---|
| 392 | n/a | if( strcmp(name, "keyScript") == 0 ) |
|---|
| 393 | n/a | return Py_BuildValue("h", (short)self->itself.keyScript); |
|---|
| 394 | n/a | if( strcmp(name, "saveFileName") == 0 ) |
|---|
| 395 | n/a | return Py_BuildValue("O&", CFStringRefObj_New, self->itself.saveFileName); |
|---|
| 396 | n/a | |
|---|
| 397 | n/a | |
|---|
| 398 | n/a | return Py_FindMethod(navrr_methods, (PyObject *)self, name); |
|---|
| 399 | n/a | } |
|---|
| 400 | n/a | |
|---|
| 401 | n/a | static int |
|---|
| 402 | n/a | navrr_setattr(navrrobject *self, char *name, PyObject *v) |
|---|
| 403 | n/a | { |
|---|
| 404 | n/a | /* Set attribute 'name' to value 'v'. v==NULL means delete */ |
|---|
| 405 | n/a | |
|---|
| 406 | n/a | /* XXXX Add your own setattr code here */ |
|---|
| 407 | n/a | return -1; |
|---|
| 408 | n/a | } |
|---|
| 409 | n/a | |
|---|
| 410 | n/a | static char Navrrtype__doc__[] = |
|---|
| 411 | n/a | "Record containing result of a Nav file selection call. Use dir() for member names." |
|---|
| 412 | n/a | ; |
|---|
| 413 | n/a | |
|---|
| 414 | n/a | static PyTypeObject Navrrtype = { |
|---|
| 415 | n/a | PyObject_HEAD_INIT(&PyType_Type) |
|---|
| 416 | n/a | 0, /*ob_size*/ |
|---|
| 417 | n/a | "Nav.NavReplyRecord", /*tp_name*/ |
|---|
| 418 | n/a | sizeof(navrrobject), /*tp_basicsize*/ |
|---|
| 419 | n/a | 0, /*tp_itemsize*/ |
|---|
| 420 | n/a | /* methods */ |
|---|
| 421 | n/a | (destructor)navrr_dealloc, /*tp_dealloc*/ |
|---|
| 422 | n/a | (printfunc)0, /*tp_print*/ |
|---|
| 423 | n/a | (getattrfunc)navrr_getattr, /*tp_getattr*/ |
|---|
| 424 | n/a | (setattrfunc)navrr_setattr, /*tp_setattr*/ |
|---|
| 425 | n/a | (cmpfunc)0, /*tp_compare*/ |
|---|
| 426 | n/a | (reprfunc)0, /*tp_repr*/ |
|---|
| 427 | n/a | 0, /*tp_as_number*/ |
|---|
| 428 | n/a | 0, /*tp_as_sequence*/ |
|---|
| 429 | n/a | 0, /*tp_as_mapping*/ |
|---|
| 430 | n/a | (hashfunc)0, /*tp_hash*/ |
|---|
| 431 | n/a | (ternaryfunc)0, /*tp_call*/ |
|---|
| 432 | n/a | (reprfunc)0, /*tp_str*/ |
|---|
| 433 | n/a | |
|---|
| 434 | n/a | /* Space for future expansion */ |
|---|
| 435 | n/a | 0L,0L,0L,0L, |
|---|
| 436 | n/a | Navrrtype__doc__ /* Documentation string */ |
|---|
| 437 | n/a | }; |
|---|
| 438 | n/a | |
|---|
| 439 | n/a | /* End of code for NavReplyRecord objects */ |
|---|
| 440 | n/a | |
|---|
| 441 | n/a | /* ----------------------------------------------------- */ |
|---|
| 442 | n/a | |
|---|
| 443 | n/a | static char nav_NavGetFile__doc__[] = |
|---|
| 444 | n/a | "(DialogOptions dict or kwargs+defaultLocation,eventProc,previewProc,filterProc,typeList) -> NavReplyRecord" |
|---|
| 445 | n/a | ; |
|---|
| 446 | n/a | |
|---|
| 447 | n/a | static PyObject * |
|---|
| 448 | n/a | nav_NavGetFile(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 449 | n/a | { |
|---|
| 450 | n/a | PyObject *dict; |
|---|
| 451 | n/a | AEDesc *defaultLocation = NULL; |
|---|
| 452 | n/a | NavReplyRecord reply; |
|---|
| 453 | n/a | NavDialogOptions dialogOptions; |
|---|
| 454 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 455 | n/a | NavPreviewUPP previewProc = NULL; |
|---|
| 456 | n/a | NavObjectFilterUPP filterProc = NULL; |
|---|
| 457 | n/a | NavTypeListHandle typeList = NULL; |
|---|
| 458 | n/a | OSErr err; |
|---|
| 459 | n/a | |
|---|
| 460 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 461 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 462 | n/a | return NULL; |
|---|
| 463 | n/a | dict = kw; |
|---|
| 464 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 465 | n/a | return NULL; |
|---|
| 466 | n/a | if (!filldialogoptions(dict, &defaultLocation, &dialogOptions, &eventProc, &previewProc, &filterProc, &typeList, NULL, NULL)) |
|---|
| 467 | n/a | return NULL; |
|---|
| 468 | n/a | err = NavGetFile(defaultLocation, &reply, &dialogOptions, |
|---|
| 469 | n/a | eventProc, previewProc, filterProc, typeList, (void *)dict); |
|---|
| 470 | n/a | PyMem_DEL(defaultLocation); |
|---|
| 471 | n/a | if ( err ) { |
|---|
| 472 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 473 | n/a | return NULL; |
|---|
| 474 | n/a | } |
|---|
| 475 | n/a | return (PyObject *)newnavrrobject(&reply); |
|---|
| 476 | n/a | } |
|---|
| 477 | n/a | |
|---|
| 478 | n/a | static char nav_NavPutFile__doc__[] = |
|---|
| 479 | n/a | "(DialogOptions dict or kwargs+defaultLocation,eventProc,fileCreator,fileType) -> NavReplyRecord" |
|---|
| 480 | n/a | ; |
|---|
| 481 | n/a | |
|---|
| 482 | n/a | static PyObject * |
|---|
| 483 | n/a | nav_NavPutFile(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 484 | n/a | { |
|---|
| 485 | n/a | PyObject *dict; |
|---|
| 486 | n/a | AEDesc *defaultLocation = NULL; |
|---|
| 487 | n/a | NavReplyRecord reply; |
|---|
| 488 | n/a | NavDialogOptions dialogOptions; |
|---|
| 489 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 490 | n/a | OSType fileType; |
|---|
| 491 | n/a | OSType fileCreator; |
|---|
| 492 | n/a | OSErr err; |
|---|
| 493 | n/a | |
|---|
| 494 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 495 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 496 | n/a | return NULL; |
|---|
| 497 | n/a | dict = kw; |
|---|
| 498 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 499 | n/a | return NULL; |
|---|
| 500 | n/a | if (!filldialogoptions(dict, &defaultLocation, &dialogOptions, &eventProc, NULL, NULL, NULL, &fileType, &fileCreator)) |
|---|
| 501 | n/a | return NULL; |
|---|
| 502 | n/a | err = NavPutFile(defaultLocation, &reply, &dialogOptions, |
|---|
| 503 | n/a | eventProc, fileType, fileCreator, (void *)dict); |
|---|
| 504 | n/a | PyMem_DEL(defaultLocation); |
|---|
| 505 | n/a | if ( err ) { |
|---|
| 506 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 507 | n/a | return NULL; |
|---|
| 508 | n/a | } |
|---|
| 509 | n/a | return (PyObject *)newnavrrobject(&reply); |
|---|
| 510 | n/a | } |
|---|
| 511 | n/a | |
|---|
| 512 | n/a | static char nav_NavAskSaveChanges__doc__[] = |
|---|
| 513 | n/a | "(NavAskSaveChangesAction, DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult" |
|---|
| 514 | n/a | |
|---|
| 515 | n/a | ; |
|---|
| 516 | n/a | |
|---|
| 517 | n/a | static PyObject * |
|---|
| 518 | n/a | nav_NavAskSaveChanges(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 519 | n/a | { |
|---|
| 520 | n/a | PyObject *dict; |
|---|
| 521 | n/a | NavDialogOptions dialogOptions; |
|---|
| 522 | n/a | NavAskSaveChangesAction action; |
|---|
| 523 | n/a | NavAskSaveChangesResult reply; |
|---|
| 524 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 525 | n/a | OSErr err; |
|---|
| 526 | n/a | |
|---|
| 527 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 528 | n/a | if (!PyArg_ParseTuple(args, "k", &action)) |
|---|
| 529 | n/a | return NULL; |
|---|
| 530 | n/a | dict = kw; |
|---|
| 531 | n/a | } else if (!PyArg_ParseTuple(args, "lO!", &action, &PyDict_Type, &dict)) |
|---|
| 532 | n/a | return NULL; |
|---|
| 533 | n/a | if (!filldialogoptions(dict, NULL, &dialogOptions, &eventProc, NULL, NULL, NULL, NULL, NULL)) |
|---|
| 534 | n/a | return NULL; |
|---|
| 535 | n/a | err = NavAskSaveChanges(&dialogOptions, action, &reply, eventProc, (void *)dict); |
|---|
| 536 | n/a | if ( err ) { |
|---|
| 537 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 538 | n/a | return NULL; |
|---|
| 539 | n/a | } |
|---|
| 540 | n/a | return Py_BuildValue("l", (long)reply); |
|---|
| 541 | n/a | } |
|---|
| 542 | n/a | |
|---|
| 543 | n/a | static char nav_NavCustomAskSaveChanges__doc__[] = |
|---|
| 544 | n/a | "(DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult" |
|---|
| 545 | n/a | ; |
|---|
| 546 | n/a | |
|---|
| 547 | n/a | static PyObject * |
|---|
| 548 | n/a | nav_NavCustomAskSaveChanges(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 549 | n/a | { |
|---|
| 550 | n/a | PyObject *dict; |
|---|
| 551 | n/a | NavDialogOptions dialogOptions; |
|---|
| 552 | n/a | NavAskSaveChangesResult reply; |
|---|
| 553 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 554 | n/a | OSErr err; |
|---|
| 555 | n/a | |
|---|
| 556 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 557 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 558 | n/a | return NULL; |
|---|
| 559 | n/a | dict = kw; |
|---|
| 560 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 561 | n/a | return NULL; |
|---|
| 562 | n/a | if (!filldialogoptions(dict, NULL, &dialogOptions, &eventProc, NULL, NULL, NULL, NULL, NULL)) |
|---|
| 563 | n/a | return NULL; |
|---|
| 564 | n/a | err = NavCustomAskSaveChanges(&dialogOptions, &reply, eventProc, (void *)dict); |
|---|
| 565 | n/a | if ( err ) { |
|---|
| 566 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 567 | n/a | return NULL; |
|---|
| 568 | n/a | } |
|---|
| 569 | n/a | return Py_BuildValue("l", (long)reply); |
|---|
| 570 | n/a | } |
|---|
| 571 | n/a | |
|---|
| 572 | n/a | static char nav_NavAskDiscardChanges__doc__[] = |
|---|
| 573 | n/a | "(DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult" |
|---|
| 574 | n/a | ; |
|---|
| 575 | n/a | |
|---|
| 576 | n/a | static PyObject * |
|---|
| 577 | n/a | nav_NavAskDiscardChanges(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 578 | n/a | { |
|---|
| 579 | n/a | PyObject *dict; |
|---|
| 580 | n/a | NavDialogOptions dialogOptions; |
|---|
| 581 | n/a | NavAskSaveChangesResult reply; |
|---|
| 582 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 583 | n/a | OSErr err; |
|---|
| 584 | n/a | |
|---|
| 585 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 586 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 587 | n/a | return NULL; |
|---|
| 588 | n/a | dict = kw; |
|---|
| 589 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 590 | n/a | return NULL; |
|---|
| 591 | n/a | if (!filldialogoptions(dict, NULL, &dialogOptions, &eventProc, NULL, NULL, NULL, NULL, NULL)) |
|---|
| 592 | n/a | return NULL; |
|---|
| 593 | n/a | err = NavAskDiscardChanges(&dialogOptions, &reply, eventProc, (void *)dict); |
|---|
| 594 | n/a | if ( err ) { |
|---|
| 595 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 596 | n/a | return NULL; |
|---|
| 597 | n/a | } |
|---|
| 598 | n/a | return Py_BuildValue("l", (long)reply); |
|---|
| 599 | n/a | } |
|---|
| 600 | n/a | |
|---|
| 601 | n/a | static char nav_NavChooseFile__doc__[] = |
|---|
| 602 | n/a | "(DialogOptions dict or kwargs+defaultLocation,eventProc,previewProc,filterProc,typeList) -> NavReplyRecord" |
|---|
| 603 | n/a | ; |
|---|
| 604 | n/a | |
|---|
| 605 | n/a | static PyObject * |
|---|
| 606 | n/a | nav_NavChooseFile(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 607 | n/a | { |
|---|
| 608 | n/a | PyObject *dict; |
|---|
| 609 | n/a | AEDesc *defaultLocation = NULL; |
|---|
| 610 | n/a | NavReplyRecord reply; |
|---|
| 611 | n/a | NavDialogOptions dialogOptions; |
|---|
| 612 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 613 | n/a | NavPreviewUPP previewProc = NULL; |
|---|
| 614 | n/a | NavObjectFilterUPP filterProc = NULL; |
|---|
| 615 | n/a | NavTypeListHandle typeList = NULL; |
|---|
| 616 | n/a | OSErr err; |
|---|
| 617 | n/a | |
|---|
| 618 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 619 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 620 | n/a | return NULL; |
|---|
| 621 | n/a | dict = kw; |
|---|
| 622 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 623 | n/a | return NULL; |
|---|
| 624 | n/a | if (!filldialogoptions(dict, &defaultLocation, &dialogOptions, &eventProc, &previewProc, &filterProc, &typeList, NULL, NULL)) |
|---|
| 625 | n/a | return NULL; |
|---|
| 626 | n/a | err = NavChooseFile(defaultLocation, &reply, &dialogOptions, |
|---|
| 627 | n/a | eventProc, previewProc, filterProc, typeList, (void *)dict); |
|---|
| 628 | n/a | PyMem_DEL(defaultLocation); |
|---|
| 629 | n/a | if ( err ) { |
|---|
| 630 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 631 | n/a | return NULL; |
|---|
| 632 | n/a | } |
|---|
| 633 | n/a | return (PyObject *)newnavrrobject(&reply); |
|---|
| 634 | n/a | } |
|---|
| 635 | n/a | |
|---|
| 636 | n/a | static char nav_NavChooseFolder__doc__[] = |
|---|
| 637 | n/a | "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord" |
|---|
| 638 | n/a | ; |
|---|
| 639 | n/a | |
|---|
| 640 | n/a | static PyObject * |
|---|
| 641 | n/a | nav_NavChooseFolder(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 642 | n/a | { |
|---|
| 643 | n/a | PyObject *dict; |
|---|
| 644 | n/a | AEDesc *defaultLocation = NULL; |
|---|
| 645 | n/a | NavReplyRecord reply; |
|---|
| 646 | n/a | NavDialogOptions dialogOptions; |
|---|
| 647 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 648 | n/a | NavObjectFilterUPP filterProc = NULL; |
|---|
| 649 | n/a | OSErr err; |
|---|
| 650 | n/a | |
|---|
| 651 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 652 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 653 | n/a | return NULL; |
|---|
| 654 | n/a | dict = kw; |
|---|
| 655 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 656 | n/a | return NULL; |
|---|
| 657 | n/a | if (!filldialogoptions(dict, &defaultLocation, &dialogOptions, &eventProc, NULL, &filterProc, NULL, NULL, NULL)) |
|---|
| 658 | n/a | return NULL; |
|---|
| 659 | n/a | err = NavChooseFolder(defaultLocation, &reply, &dialogOptions, |
|---|
| 660 | n/a | eventProc, filterProc, (void *)dict); |
|---|
| 661 | n/a | PyMem_DEL(defaultLocation); |
|---|
| 662 | n/a | if ( err ) { |
|---|
| 663 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 664 | n/a | return NULL; |
|---|
| 665 | n/a | } |
|---|
| 666 | n/a | return (PyObject *)newnavrrobject(&reply); |
|---|
| 667 | n/a | } |
|---|
| 668 | n/a | |
|---|
| 669 | n/a | static char nav_NavChooseVolume__doc__[] = |
|---|
| 670 | n/a | "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord" |
|---|
| 671 | n/a | ; |
|---|
| 672 | n/a | |
|---|
| 673 | n/a | static PyObject * |
|---|
| 674 | n/a | nav_NavChooseVolume(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 675 | n/a | { |
|---|
| 676 | n/a | PyObject *dict; |
|---|
| 677 | n/a | AEDesc *defaultLocation = NULL; |
|---|
| 678 | n/a | NavReplyRecord reply; |
|---|
| 679 | n/a | NavDialogOptions dialogOptions; |
|---|
| 680 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 681 | n/a | NavObjectFilterUPP filterProc = NULL; |
|---|
| 682 | n/a | OSErr err; |
|---|
| 683 | n/a | |
|---|
| 684 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 685 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 686 | n/a | return NULL; |
|---|
| 687 | n/a | dict = kw; |
|---|
| 688 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 689 | n/a | return NULL; |
|---|
| 690 | n/a | if (!filldialogoptions(dict, &defaultLocation, &dialogOptions, &eventProc, NULL, &filterProc, NULL, NULL, NULL)) |
|---|
| 691 | n/a | return NULL; |
|---|
| 692 | n/a | err = NavChooseVolume(defaultLocation, &reply, &dialogOptions, |
|---|
| 693 | n/a | eventProc, filterProc, (void *)dict); |
|---|
| 694 | n/a | PyMem_DEL(defaultLocation); |
|---|
| 695 | n/a | if ( err ) { |
|---|
| 696 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 697 | n/a | return NULL; |
|---|
| 698 | n/a | } |
|---|
| 699 | n/a | return (PyObject *)newnavrrobject(&reply); |
|---|
| 700 | n/a | } |
|---|
| 701 | n/a | |
|---|
| 702 | n/a | static char nav_NavChooseObject__doc__[] = |
|---|
| 703 | n/a | "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord" |
|---|
| 704 | n/a | ; |
|---|
| 705 | n/a | |
|---|
| 706 | n/a | static PyObject * |
|---|
| 707 | n/a | nav_NavChooseObject(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 708 | n/a | { |
|---|
| 709 | n/a | PyObject *dict; |
|---|
| 710 | n/a | AEDesc *defaultLocation = NULL; |
|---|
| 711 | n/a | NavReplyRecord reply; |
|---|
| 712 | n/a | NavDialogOptions dialogOptions; |
|---|
| 713 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 714 | n/a | NavObjectFilterUPP filterProc = NULL; |
|---|
| 715 | n/a | OSErr err; |
|---|
| 716 | n/a | |
|---|
| 717 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 718 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 719 | n/a | return NULL; |
|---|
| 720 | n/a | dict = kw; |
|---|
| 721 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 722 | n/a | return NULL; |
|---|
| 723 | n/a | if (!filldialogoptions(dict, &defaultLocation, &dialogOptions, &eventProc, NULL, &filterProc, NULL, NULL, NULL)) |
|---|
| 724 | n/a | return NULL; |
|---|
| 725 | n/a | err = NavChooseObject(defaultLocation, &reply, &dialogOptions, |
|---|
| 726 | n/a | eventProc, filterProc, (void *)dict); |
|---|
| 727 | n/a | PyMem_DEL(defaultLocation); |
|---|
| 728 | n/a | if ( err ) { |
|---|
| 729 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 730 | n/a | return NULL; |
|---|
| 731 | n/a | } |
|---|
| 732 | n/a | return (PyObject *)newnavrrobject(&reply); |
|---|
| 733 | n/a | } |
|---|
| 734 | n/a | |
|---|
| 735 | n/a | static char nav_NavNewFolder__doc__[] = |
|---|
| 736 | n/a | "(DialogOptions dict or kwargs+defaultLocation,eventProc) -> NavReplyRecord" |
|---|
| 737 | n/a | ; |
|---|
| 738 | n/a | |
|---|
| 739 | n/a | static PyObject * |
|---|
| 740 | n/a | nav_NavNewFolder(PyObject *self, PyObject *args, PyObject *kw) |
|---|
| 741 | n/a | { |
|---|
| 742 | n/a | PyObject *dict; |
|---|
| 743 | n/a | AEDesc *defaultLocation = NULL; |
|---|
| 744 | n/a | NavReplyRecord reply; |
|---|
| 745 | n/a | NavDialogOptions dialogOptions; |
|---|
| 746 | n/a | NavEventUPP eventProc = NULL; |
|---|
| 747 | n/a | OSErr err; |
|---|
| 748 | n/a | |
|---|
| 749 | n/a | if ( kw && PyObject_IsTrue(kw) ) { |
|---|
| 750 | n/a | if (!PyArg_ParseTuple(args, ";either keyword arguments or dictionary expected")) |
|---|
| 751 | n/a | return NULL; |
|---|
| 752 | n/a | dict = kw; |
|---|
| 753 | n/a | } else if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &dict)) |
|---|
| 754 | n/a | return NULL; |
|---|
| 755 | n/a | if (!filldialogoptions(dict, &defaultLocation, &dialogOptions, &eventProc, NULL, NULL, NULL, NULL, NULL)) |
|---|
| 756 | n/a | return NULL; |
|---|
| 757 | n/a | err = NavNewFolder(defaultLocation, &reply, &dialogOptions, eventProc, (void *)dict); |
|---|
| 758 | n/a | PyMem_DEL(defaultLocation); |
|---|
| 759 | n/a | if ( err ) { |
|---|
| 760 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 761 | n/a | return NULL; |
|---|
| 762 | n/a | } |
|---|
| 763 | n/a | return (PyObject *)newnavrrobject(&reply); |
|---|
| 764 | n/a | } |
|---|
| 765 | n/a | |
|---|
| 766 | n/a | #if 0 |
|---|
| 767 | n/a | /* XXXX I don't know what to do with the void * argument */ |
|---|
| 768 | n/a | static char nav_NavCustomControl__doc__[] = |
|---|
| 769 | n/a | "" |
|---|
| 770 | n/a | ; |
|---|
| 771 | n/a | |
|---|
| 772 | n/a | |
|---|
| 773 | n/a | static PyObject * |
|---|
| 774 | n/a | nav_NavCustomControl(PyObject *self, PyObject *args) |
|---|
| 775 | n/a | { |
|---|
| 776 | n/a | |
|---|
| 777 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 778 | n/a | return NULL; |
|---|
| 779 | n/a | Py_INCREF(Py_None); |
|---|
| 780 | n/a | return Py_None; |
|---|
| 781 | n/a | } |
|---|
| 782 | n/a | #endif |
|---|
| 783 | n/a | |
|---|
| 784 | n/a | static char nav_NavServicesCanRun__doc__[] = |
|---|
| 785 | n/a | "()->int" |
|---|
| 786 | n/a | ; |
|---|
| 787 | n/a | |
|---|
| 788 | n/a | static PyObject * |
|---|
| 789 | n/a | nav_NavServicesCanRun(PyObject *self, PyObject *args) |
|---|
| 790 | n/a | { |
|---|
| 791 | n/a | Boolean rv; |
|---|
| 792 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 793 | n/a | return NULL; |
|---|
| 794 | n/a | rv = NavServicesCanRun(); |
|---|
| 795 | n/a | return Py_BuildValue("l", (long)rv); |
|---|
| 796 | n/a | } |
|---|
| 797 | n/a | |
|---|
| 798 | n/a | static char nav_NavServicesAvailable__doc__[] = |
|---|
| 799 | n/a | "()->int" |
|---|
| 800 | n/a | ; |
|---|
| 801 | n/a | |
|---|
| 802 | n/a | static PyObject * |
|---|
| 803 | n/a | nav_NavServicesAvailable(PyObject *self, PyObject *args) |
|---|
| 804 | n/a | { |
|---|
| 805 | n/a | Boolean rv; |
|---|
| 806 | n/a | |
|---|
| 807 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 808 | n/a | return NULL; |
|---|
| 809 | n/a | rv = NavServicesAvailable(); |
|---|
| 810 | n/a | return Py_BuildValue("l", (long)rv); |
|---|
| 811 | n/a | } |
|---|
| 812 | n/a | /* XX */ |
|---|
| 813 | n/a | static char nav_NavLoad__doc__[] = |
|---|
| 814 | n/a | "()->None" |
|---|
| 815 | n/a | ; |
|---|
| 816 | n/a | |
|---|
| 817 | n/a | static PyObject * |
|---|
| 818 | n/a | nav_NavLoad(PyObject *self, PyObject *args) |
|---|
| 819 | n/a | { |
|---|
| 820 | n/a | |
|---|
| 821 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 822 | n/a | return NULL; |
|---|
| 823 | n/a | NavLoad(); |
|---|
| 824 | n/a | Py_INCREF(Py_None); |
|---|
| 825 | n/a | return Py_None; |
|---|
| 826 | n/a | } |
|---|
| 827 | n/a | |
|---|
| 828 | n/a | static char nav_NavUnload__doc__[] = |
|---|
| 829 | n/a | "()->None" |
|---|
| 830 | n/a | ; |
|---|
| 831 | n/a | |
|---|
| 832 | n/a | static PyObject * |
|---|
| 833 | n/a | nav_NavUnload(PyObject *self, PyObject *args) |
|---|
| 834 | n/a | { |
|---|
| 835 | n/a | |
|---|
| 836 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 837 | n/a | return NULL; |
|---|
| 838 | n/a | NavUnload(); |
|---|
| 839 | n/a | Py_INCREF(Py_None); |
|---|
| 840 | n/a | return Py_None; |
|---|
| 841 | n/a | } |
|---|
| 842 | n/a | |
|---|
| 843 | n/a | static char nav_NavLibraryVersion__doc__[] = |
|---|
| 844 | n/a | "()->int" |
|---|
| 845 | n/a | ; |
|---|
| 846 | n/a | |
|---|
| 847 | n/a | static PyObject * |
|---|
| 848 | n/a | nav_NavLibraryVersion(PyObject *self, PyObject *args) |
|---|
| 849 | n/a | { |
|---|
| 850 | n/a | UInt32 rv; |
|---|
| 851 | n/a | |
|---|
| 852 | n/a | if (!PyArg_ParseTuple(args, "")) |
|---|
| 853 | n/a | return NULL; |
|---|
| 854 | n/a | rv = NavLibraryVersion(); |
|---|
| 855 | n/a | return Py_BuildValue("l", (long)rv); |
|---|
| 856 | n/a | } |
|---|
| 857 | n/a | |
|---|
| 858 | n/a | static char nav_NavGetDefaultDialogOptions__doc__[] = |
|---|
| 859 | n/a | "()->dict\nPass dict or keyword args with same names to other calls." |
|---|
| 860 | n/a | ; |
|---|
| 861 | n/a | |
|---|
| 862 | n/a | static PyObject * |
|---|
| 863 | n/a | nav_NavGetDefaultDialogOptions(PyObject *self, PyObject *args) |
|---|
| 864 | n/a | { |
|---|
| 865 | n/a | NavDialogOptions dialogOptions; |
|---|
| 866 | n/a | OSErr err; |
|---|
| 867 | n/a | |
|---|
| 868 | n/a | err = NavGetDefaultDialogOptions(&dialogOptions); |
|---|
| 869 | n/a | if ( err ) { |
|---|
| 870 | n/a | PyErr_Mac(ErrorObject, err); |
|---|
| 871 | n/a | return NULL; |
|---|
| 872 | n/a | } |
|---|
| 873 | n/a | return Py_BuildValue( |
|---|
| 874 | n/a | "{s:h,s:l,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&}", |
|---|
| 875 | n/a | "version", dialogOptions.version, |
|---|
| 876 | n/a | "dialogOptionFlags", dialogOptions.dialogOptionFlags, |
|---|
| 877 | n/a | "location", PyMac_BuildPoint, dialogOptions.location, |
|---|
| 878 | n/a | "clientName", PyMac_BuildStr255, &dialogOptions.clientName, |
|---|
| 879 | n/a | "windowTitle", PyMac_BuildStr255, &dialogOptions.windowTitle, |
|---|
| 880 | n/a | "actionButtonLabel", PyMac_BuildStr255, &dialogOptions.actionButtonLabel, |
|---|
| 881 | n/a | "cancelButtonLabel", PyMac_BuildStr255, &dialogOptions.cancelButtonLabel, |
|---|
| 882 | n/a | "savedFileName", PyMac_BuildStr255, &dialogOptions.savedFileName, |
|---|
| 883 | n/a | "message", PyMac_BuildStr255, &dialogOptions.message, |
|---|
| 884 | n/a | "preferenceKey", PyMac_BuildOSType, dialogOptions.preferenceKey |
|---|
| 885 | n/a | ,"popupExtension", OptResObj_New, dialogOptions.popupExtension |
|---|
| 886 | n/a | ); |
|---|
| 887 | n/a | } |
|---|
| 888 | n/a | |
|---|
| 889 | n/a | /* List of methods defined in the module */ |
|---|
| 890 | n/a | |
|---|
| 891 | n/a | static struct PyMethodDef nav_methods[] = { |
|---|
| 892 | n/a | {"NavGetFile", (PyCFunction)nav_NavGetFile, METH_VARARGS|METH_KEYWORDS, nav_NavGetFile__doc__}, |
|---|
| 893 | n/a | {"NavPutFile", (PyCFunction)nav_NavPutFile, METH_VARARGS|METH_KEYWORDS, nav_NavPutFile__doc__}, |
|---|
| 894 | n/a | {"NavAskSaveChanges", (PyCFunction)nav_NavAskSaveChanges, METH_VARARGS|METH_KEYWORDS, nav_NavAskSaveChanges__doc__}, |
|---|
| 895 | n/a | {"NavCustomAskSaveChanges", (PyCFunction)nav_NavCustomAskSaveChanges, METH_VARARGS|METH_KEYWORDS, nav_NavCustomAskSaveChanges__doc__}, |
|---|
| 896 | n/a | {"NavAskDiscardChanges", (PyCFunction)nav_NavAskDiscardChanges, METH_VARARGS|METH_KEYWORDS, nav_NavAskDiscardChanges__doc__}, |
|---|
| 897 | n/a | {"NavChooseFile", (PyCFunction)nav_NavChooseFile, METH_VARARGS|METH_KEYWORDS, nav_NavChooseFile__doc__}, |
|---|
| 898 | n/a | {"NavChooseFolder", (PyCFunction)nav_NavChooseFolder, METH_VARARGS|METH_KEYWORDS, nav_NavChooseFolder__doc__}, |
|---|
| 899 | n/a | {"NavChooseVolume", (PyCFunction)nav_NavChooseVolume, METH_VARARGS|METH_KEYWORDS, nav_NavChooseVolume__doc__}, |
|---|
| 900 | n/a | {"NavChooseObject", (PyCFunction)nav_NavChooseObject, METH_VARARGS|METH_KEYWORDS, nav_NavChooseObject__doc__}, |
|---|
| 901 | n/a | {"NavNewFolder", (PyCFunction)nav_NavNewFolder, METH_VARARGS|METH_KEYWORDS, nav_NavNewFolder__doc__}, |
|---|
| 902 | n/a | #if 0 |
|---|
| 903 | n/a | {"NavCustomControl", (PyCFunction)nav_NavCustomControl, METH_VARARGS, nav_NavCustomControl__doc__}, |
|---|
| 904 | n/a | #endif |
|---|
| 905 | n/a | {"NavServicesCanRun", (PyCFunction)nav_NavServicesCanRun, METH_VARARGS, nav_NavServicesCanRun__doc__}, |
|---|
| 906 | n/a | {"NavServicesAvailable", (PyCFunction)nav_NavServicesAvailable, METH_VARARGS, nav_NavServicesAvailable__doc__}, |
|---|
| 907 | n/a | {"NavLoad", (PyCFunction)nav_NavLoad, METH_VARARGS, nav_NavLoad__doc__}, |
|---|
| 908 | n/a | {"NavUnload", (PyCFunction)nav_NavUnload, METH_VARARGS, nav_NavUnload__doc__}, |
|---|
| 909 | n/a | {"NavLibraryVersion", (PyCFunction)nav_NavLibraryVersion, METH_VARARGS, nav_NavLibraryVersion__doc__}, |
|---|
| 910 | n/a | {"NavGetDefaultDialogOptions", (PyCFunction)nav_NavGetDefaultDialogOptions, METH_VARARGS, nav_NavGetDefaultDialogOptions__doc__}, |
|---|
| 911 | n/a | {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ |
|---|
| 912 | n/a | }; |
|---|
| 913 | n/a | |
|---|
| 914 | n/a | |
|---|
| 915 | n/a | /* Initialization function for the module (*must* be called initNav) */ |
|---|
| 916 | n/a | |
|---|
| 917 | n/a | static char Nav_module_documentation[] = |
|---|
| 918 | n/a | "Interface to Navigation Services\n" |
|---|
| 919 | n/a | "Most calls accept a NavDialogOptions dictionary or keywords with the same names, pass {}\n" |
|---|
| 920 | n/a | "if you want the default options.\n" |
|---|
| 921 | n/a | "Use NavGetDefaultDialogOptions() to find out common option names.\n" |
|---|
| 922 | n/a | "See individual docstrings for additional keyword args/dictentries supported by each call.\n" |
|---|
| 923 | n/a | "Pass None as eventProc to get movable-modal dialogs that process updates through the standard Python mechanism." |
|---|
| 924 | n/a | ; |
|---|
| 925 | n/a | |
|---|
| 926 | n/a | |
|---|
| 927 | n/a | #endif /* !__LP64__ */ |
|---|
| 928 | n/a | |
|---|
| 929 | n/a | |
|---|
| 930 | n/a | void |
|---|
| 931 | n/a | initNav(void) |
|---|
| 932 | n/a | { |
|---|
| 933 | n/a | PyObject *m, *d; |
|---|
| 934 | n/a | |
|---|
| 935 | n/a | if (PyErr_WarnPy3k("In 3.x, the Nav module is removed.", 1)) |
|---|
| 936 | n/a | return; |
|---|
| 937 | n/a | |
|---|
| 938 | n/a | #ifdef __LP64__ |
|---|
| 939 | n/a | PyErr_SetString(PyExc_ImportError, "Navigation Services not available in 64-bit mode"); |
|---|
| 940 | n/a | return; |
|---|
| 941 | n/a | |
|---|
| 942 | n/a | #else /* !__LP64__ */ |
|---|
| 943 | n/a | |
|---|
| 944 | n/a | /* Test that we have NavServices */ |
|---|
| 945 | n/a | if ( !NavServicesAvailable() ) { |
|---|
| 946 | n/a | PyErr_SetString(PyExc_ImportError, "Navigation Services not available"); |
|---|
| 947 | n/a | return; |
|---|
| 948 | n/a | } |
|---|
| 949 | n/a | /* Create the module and add the functions */ |
|---|
| 950 | n/a | m = Py_InitModule4("Nav", nav_methods, |
|---|
| 951 | n/a | Nav_module_documentation, |
|---|
| 952 | n/a | (PyObject*)NULL,PYTHON_API_VERSION); |
|---|
| 953 | n/a | |
|---|
| 954 | n/a | /* Add some symbolic constants to the module */ |
|---|
| 955 | n/a | d = PyModule_GetDict(m); |
|---|
| 956 | n/a | ErrorObject = PyString_FromString("Nav.error"); |
|---|
| 957 | n/a | PyDict_SetItemString(d, "error", ErrorObject); |
|---|
| 958 | n/a | |
|---|
| 959 | n/a | /* XXXX Add constants here */ |
|---|
| 960 | n/a | |
|---|
| 961 | n/a | /* Set UPPs */ |
|---|
| 962 | n/a | my_eventProcUPP = NewNavEventUPP(my_eventProc); |
|---|
| 963 | n/a | my_previewProcUPP = NewNavPreviewUPP(my_previewProc); |
|---|
| 964 | n/a | my_filterProcUPP = NewNavObjectFilterUPP(my_filterProc); |
|---|
| 965 | n/a | #endif /* !__LP64__ */ |
|---|
| 966 | n/a | |
|---|
| 967 | n/a | } |
|---|
| 968 | n/a | |
|---|