1 /***********************************************************
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
33 #include "pymactoolbox.h"
34 #include <Carbon/Carbon.h>
36 static PyObject
*ErrorObject
;
38 static NavEventUPP my_eventProcUPP
;
39 static NavPreviewUPP my_previewProcUPP
;
40 static NavObjectFilterUPP my_filterProcUPP
;
42 /* Callback functions */
44 my_eventProc(NavEventCallbackMessage callBackSelector
,
45 NavCBRecPtr callBackParms
,
46 NavCallBackUserData callbackUD
)
48 PyObject
*dict
= (PyObject
*)callbackUD
;
53 if ( (pyfunc
= PyDict_GetItemString(dict
, "eventProc")) == NULL
) {
57 if ( pyfunc
== Py_None
) {
60 rv
= PyObject_CallFunction(pyfunc
, "ls#", (long)callBackSelector
,
61 (void *)callBackParms
, sizeof(NavCBRec
));
65 PySys_WriteStderr("Nav: exception in eventProc callback\n");
71 my_previewProc(NavCBRecPtr callBackParms
,
72 NavCallBackUserData callbackUD
)
74 PyObject
*dict
= (PyObject
*)callbackUD
;
79 if (!dict
) return false;
80 if ( (pyfunc
= PyDict_GetItemString(dict
, "previewProc")) == NULL
) {
84 rv
= PyObject_CallFunction(pyfunc
, "s#", (void *)callBackParms
, sizeof(NavCBRec
));
86 c_rv
= PyObject_IsTrue(rv
);
89 PySys_WriteStderr("Nav: exception in previewProc callback\n");
96 my_filterProc(AEDesc
*theItem
, void *info
,
97 NavCallBackUserData callbackUD
,
98 NavFilterModes filterMode
)
100 PyObject
*dict
= (PyObject
*)callbackUD
;
103 Boolean c_rv
= false;
105 if (!dict
) return false;
106 if ( (pyfunc
= PyDict_GetItemString(dict
, "filterProc")) == NULL
) {
110 rv
= PyObject_CallFunction(pyfunc
, "O&s#h",
111 AEDesc_NewBorrowed
, theItem
, info
, sizeof(NavFileOrFolderInfo
), (short)filterMode
);
113 c_rv
= PyObject_IsTrue(rv
);
116 PySys_WriteStderr("Nav: exception in filterProc callback\n");
122 /* ----------------------------------------------------- */
124 filldialogoptions(PyObject
*d
,
125 AEDesc
**defaultLocationP
,
126 NavDialogOptions
*opt
,
127 NavEventUPP
*eventProcP
,
128 NavPreviewUPP
*previewProcP
,
129 NavObjectFilterUPP
*filterProcP
,
130 NavTypeListHandle
*typeListP
,
132 OSType
*fileCreatorP
)
135 PyObject
*key
, *value
;
137 AEDesc
*defaultLocation_storage
;
139 NavGetDefaultDialogOptions(opt
);
141 while ( PyDict_Next(d
, &pos
, &key
, &value
) ) {
142 if ( !key
|| !value
|| !PyString_Check(key
) ) {
143 PyErr_SetString(ErrorObject
, "DialogOption has non-string key");
146 keystr
= PyString_AsString(key
);
147 if( strcmp(keystr
, "defaultLocation") == 0 ) {
148 if ( (defaultLocation_storage
= PyMem_NEW(AEDesc
, 1)) == NULL
) {
152 if ( !PyArg_Parse(value
, "O&", AEDesc_Convert
, defaultLocation_storage
) ) {
153 PyMem_DEL(defaultLocation_storage
);
156 *defaultLocationP
= defaultLocation_storage
;
157 } else if( strcmp(keystr
, "version") == 0 ) {
158 if ( !PyArg_Parse(value
, "H", &opt
->version
) )
160 } else if( strcmp(keystr
, "dialogOptionFlags") == 0 ) {
161 if ( !PyArg_Parse(value
, "k", &opt
->dialogOptionFlags
) )
163 } else if( strcmp(keystr
, "location") == 0 ) {
164 if ( !PyArg_Parse(value
, "O&", PyMac_GetPoint
, &opt
->location
) )
166 } else if( strcmp(keystr
, "clientName") == 0 ) {
167 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->clientName
) )
169 } else if( strcmp(keystr
, "windowTitle") == 0 ) {
170 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->windowTitle
) )
172 } else if( strcmp(keystr
, "actionButtonLabel") == 0 ) {
173 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->actionButtonLabel
) )
175 } else if( strcmp(keystr
, "cancelButtonLabel") == 0 ) {
176 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->cancelButtonLabel
) )
178 } else if( strcmp(keystr
, "savedFileName") == 0 ) {
179 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->savedFileName
) )
181 } else if( strcmp(keystr
, "message") == 0 ) {
182 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->message
) )
184 } else if( strcmp(keystr
, "preferenceKey") == 0 ) {
185 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, &opt
->preferenceKey
) )
187 } else if( strcmp(keystr
, "popupExtension") == 0 ) {
188 if ( !PyArg_Parse(value
, "O&", ResObj_Convert
, &opt
->popupExtension
) )
190 } else if( eventProcP
&& strcmp(keystr
, "eventProc") == 0 ) {
191 *eventProcP
= my_eventProcUPP
;
192 } else if( previewProcP
&& strcmp(keystr
, "previewProc") == 0 ) {
193 *previewProcP
= my_previewProcUPP
;
194 } else if( filterProcP
&& strcmp(keystr
, "filterProc") == 0 ) {
195 *filterProcP
= my_filterProcUPP
;
196 } else if( typeListP
&& strcmp(keystr
, "typeList") == 0 ) {
197 if ( !PyArg_Parse(value
, "O&", ResObj_Convert
, typeListP
) )
199 } else if( fileTypeP
&& strcmp(keystr
, "fileType") == 0 ) {
200 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, fileTypeP
) )
202 } else if( fileCreatorP
&& strcmp(keystr
, "fileCreator") == 0 ) {
203 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, fileCreatorP
) )
206 PyErr_Format(ErrorObject
, "Unknown DialogOption key: %s", keystr
);
213 /* ----------------------------------------------------- */
215 /* Declarations for objects of type NavReplyRecord */
219 NavReplyRecord itself
;
222 static PyTypeObject Navrrtype
;
226 /* ---------------------------------------------------------------- */
228 static char nav_NavTranslateFile__doc__
[] =
229 "(NavTranslationOptions)->None"
233 nav_NavTranslateFile(navrrobject
*self
, PyObject
*args
)
235 NavTranslationOptions howToTranslate
;
238 if (!PyArg_ParseTuple(args
, "k", &howToTranslate
))
240 err
= NavTranslateFile(&self
->itself
, howToTranslate
);
242 PyErr_Mac(ErrorObject
, err
);
249 static char nav_NavCompleteSave__doc__
[] =
250 "(NavTranslationOptions)->None"
254 nav_NavCompleteSave(navrrobject
*self
, PyObject
*args
)
256 NavTranslationOptions howToTranslate
;
259 if (!PyArg_ParseTuple(args
, "k", &howToTranslate
))
261 err
= NavCompleteSave(&self
->itself
, howToTranslate
);
263 PyErr_Mac(ErrorObject
, err
);
271 static struct PyMethodDef navrr_methods
[] = {
272 {"NavTranslateFile", (PyCFunction
)nav_NavTranslateFile
, METH_VARARGS
, nav_NavTranslateFile__doc__
},
273 {"NavCompleteSave", (PyCFunction
)nav_NavCompleteSave
, METH_VARARGS
, nav_NavCompleteSave__doc__
},
275 {NULL
, NULL
} /* sentinel */
282 newnavrrobject(NavReplyRecord
*itself
)
286 self
= PyObject_NEW(navrrobject
, &Navrrtype
);
289 self
->itself
= *itself
;
295 navrr_dealloc(navrrobject
*self
)
297 NavDisposeReply(&self
->itself
);
302 navrr_getattr(navrrobject
*self
, char *name
)
307 if( strcmp(name
, "__members__") == 0 )
308 return Py_BuildValue("ssssssssss", "version", "validRecord", "replacing",
309 "isStationery", "translationNeeded", "selection", "selection_fsr",
310 "fileTranslation", "keyScript", "saveFileName");
311 if( strcmp(name
, "version") == 0 )
312 return Py_BuildValue("h", self
->itself
.version
);
313 if( strcmp(name
, "validRecord") == 0 )
314 return Py_BuildValue("l", (long)self
->itself
.validRecord
);
315 if( strcmp(name
, "replacing") == 0 )
316 return Py_BuildValue("l", (long)self
->itself
.replacing
);
317 if( strcmp(name
, "isStationery") == 0 )
318 return Py_BuildValue("l", (long)self
->itself
.isStationery
);
319 if( strcmp(name
, "translationNeeded") == 0 )
320 return Py_BuildValue("l", (long)self
->itself
.translationNeeded
);
321 if( strcmp(name
, "selection") == 0 ) {
324 PyObject
*rv
, *rvitem
;
327 if ((err
=AECountItems(&self
->itself
.selection
, &count
))) {
328 PyErr_Mac(ErrorObject
, err
);
331 if ( (rv
=PyList_New(count
)) == NULL
)
333 for(i
=0; i
<count
; i
++) {
334 desc
.dataHandle
= NULL
;
335 if ((err
=AEGetNthDesc(&self
->itself
.selection
, i
+1, typeFSS
, NULL
, &desc
))) {
337 PyErr_Mac(ErrorObject
, err
);
340 if ((err
=AEGetDescData(&desc
, &fss
, sizeof(FSSpec
)))) {
342 PyErr_Mac(ErrorObject
, err
);
345 rvitem
= PyMac_BuildFSSpec(&fss
);
346 PyList_SetItem(rv
, i
, rvitem
);
347 AEDisposeDesc(&desc
);
351 if( strcmp(name
, "selection_fsr") == 0 ) {
354 PyObject
*rv
, *rvitem
;
357 if ((err
=AECountItems(&self
->itself
.selection
, &count
))) {
358 PyErr_Mac(ErrorObject
, err
);
361 if ( (rv
=PyList_New(count
)) == NULL
)
363 for(i
=0; i
<count
; i
++) {
364 desc
.dataHandle
= NULL
;
365 if ((err
=AEGetNthDesc(&self
->itself
.selection
, i
+1, typeFSRef
, NULL
, &desc
))) {
367 PyErr_Mac(ErrorObject
, err
);
370 if ((err
=AEGetDescData(&desc
, &fsr
, sizeof(FSRef
)))) {
372 PyErr_Mac(ErrorObject
, err
);
375 rvitem
= PyMac_BuildFSRef(&fsr
);
376 PyList_SetItem(rv
, i
, rvitem
);
377 AEDisposeDesc(&desc
);
381 if( strcmp(name
, "fileTranslation") == 0 )
382 return ResObj_New((Handle
)self
->itself
.fileTranslation
);
383 if( strcmp(name
, "keyScript") == 0 )
384 return Py_BuildValue("h", (short)self
->itself
.keyScript
);
385 if( strcmp(name
, "saveFileName") == 0 )
386 return Py_BuildValue("O&", CFStringRefObj_New
, self
->itself
.saveFileName
);
389 return Py_FindMethod(navrr_methods
, (PyObject
*)self
, name
);
393 navrr_setattr(navrrobject
*self
, char *name
, PyObject
*v
)
395 /* Set attribute 'name' to value 'v'. v==NULL means delete */
397 /* XXXX Add your own setattr code here */
401 static char Navrrtype__doc__
[] =
402 "Record containing result of a Nav file selection call. Use dir() for member names."
405 static PyTypeObject Navrrtype
= {
406 PyObject_HEAD_INIT(&PyType_Type
)
408 "Nav.NavReplyRecord", /*tp_name*/
409 sizeof(navrrobject
), /*tp_basicsize*/
412 (destructor
)navrr_dealloc
, /*tp_dealloc*/
413 (printfunc
)0, /*tp_print*/
414 (getattrfunc
)navrr_getattr
, /*tp_getattr*/
415 (setattrfunc
)navrr_setattr
, /*tp_setattr*/
416 (cmpfunc
)0, /*tp_compare*/
417 (reprfunc
)0, /*tp_repr*/
419 0, /*tp_as_sequence*/
421 (hashfunc
)0, /*tp_hash*/
422 (ternaryfunc
)0, /*tp_call*/
423 (reprfunc
)0, /*tp_str*/
425 /* Space for future expansion */
427 Navrrtype__doc__
/* Documentation string */
430 /* End of code for NavReplyRecord objects */
432 /* ----------------------------------------------------- */
434 static char nav_NavGetFile__doc__
[] =
435 "(DialogOptions dict or kwargs+defaultLocation,eventProc,previewProc,filterProc,typeList) -> NavReplyRecord"
439 nav_NavGetFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
442 AEDesc
*defaultLocation
= NULL
;
443 NavReplyRecord reply
;
444 NavDialogOptions dialogOptions
;
445 NavEventUPP eventProc
= NULL
;
446 NavPreviewUPP previewProc
= NULL
;
447 NavObjectFilterUPP filterProc
= NULL
;
448 NavTypeListHandle typeList
= NULL
;
451 if ( kw
&& PyObject_IsTrue(kw
) ) {
452 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
455 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
457 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, &previewProc
, &filterProc
, &typeList
, NULL
, NULL
))
459 err
= NavGetFile(defaultLocation
, &reply
, &dialogOptions
,
460 eventProc
, previewProc
, filterProc
, typeList
, (void *)dict
);
461 PyMem_DEL(defaultLocation
);
463 PyErr_Mac(ErrorObject
, err
);
466 return (PyObject
*)newnavrrobject(&reply
);
469 static char nav_NavPutFile__doc__
[] =
470 "(DialogOptions dict or kwargs+defaultLocation,eventProc,fileCreator,fileType) -> NavReplyRecord"
474 nav_NavPutFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
477 AEDesc
*defaultLocation
= NULL
;
478 NavReplyRecord reply
;
479 NavDialogOptions dialogOptions
;
480 NavEventUPP eventProc
= NULL
;
485 if ( kw
&& PyObject_IsTrue(kw
) ) {
486 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
489 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
491 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, &fileType
, &fileCreator
))
493 err
= NavPutFile(defaultLocation
, &reply
, &dialogOptions
,
494 eventProc
, fileType
, fileCreator
, (void *)dict
);
495 PyMem_DEL(defaultLocation
);
497 PyErr_Mac(ErrorObject
, err
);
500 return (PyObject
*)newnavrrobject(&reply
);
503 static char nav_NavAskSaveChanges__doc__
[] =
504 "(NavAskSaveChangesAction, DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
509 nav_NavAskSaveChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
512 NavDialogOptions dialogOptions
;
513 NavAskSaveChangesAction action
;
514 NavAskSaveChangesResult reply
;
515 NavEventUPP eventProc
= NULL
;
518 if ( kw
&& PyObject_IsTrue(kw
) ) {
519 if (!PyArg_ParseTuple(args
, "k", &action
))
522 } else if (!PyArg_ParseTuple(args
, "lO!", &action
, &PyDict_Type
, &dict
))
524 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
526 err
= NavAskSaveChanges(&dialogOptions
, action
, &reply
, eventProc
, (void *)dict
);
528 PyErr_Mac(ErrorObject
, err
);
531 return Py_BuildValue("l", (long)reply
);
534 static char nav_NavCustomAskSaveChanges__doc__
[] =
535 "(DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
539 nav_NavCustomAskSaveChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
542 NavDialogOptions dialogOptions
;
543 NavAskSaveChangesResult reply
;
544 NavEventUPP eventProc
= NULL
;
547 if ( kw
&& PyObject_IsTrue(kw
) ) {
548 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
551 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
553 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
555 err
= NavCustomAskSaveChanges(&dialogOptions
, &reply
, eventProc
, (void *)dict
);
557 PyErr_Mac(ErrorObject
, err
);
560 return Py_BuildValue("l", (long)reply
);
563 static char nav_NavAskDiscardChanges__doc__
[] =
564 "(DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
568 nav_NavAskDiscardChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
571 NavDialogOptions dialogOptions
;
572 NavAskSaveChangesResult reply
;
573 NavEventUPP eventProc
= NULL
;
576 if ( kw
&& PyObject_IsTrue(kw
) ) {
577 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
580 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
582 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
584 err
= NavAskDiscardChanges(&dialogOptions
, &reply
, eventProc
, (void *)dict
);
586 PyErr_Mac(ErrorObject
, err
);
589 return Py_BuildValue("l", (long)reply
);
592 static char nav_NavChooseFile__doc__
[] =
593 "(DialogOptions dict or kwargs+defaultLocation,eventProc,previewProc,filterProc,typeList) -> NavReplyRecord"
597 nav_NavChooseFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
600 AEDesc
*defaultLocation
= NULL
;
601 NavReplyRecord reply
;
602 NavDialogOptions dialogOptions
;
603 NavEventUPP eventProc
= NULL
;
604 NavPreviewUPP previewProc
= NULL
;
605 NavObjectFilterUPP filterProc
= NULL
;
606 NavTypeListHandle typeList
= NULL
;
609 if ( kw
&& PyObject_IsTrue(kw
) ) {
610 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
613 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
615 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, &previewProc
, &filterProc
, &typeList
, NULL
, NULL
))
617 err
= NavChooseFile(defaultLocation
, &reply
, &dialogOptions
,
618 eventProc
, previewProc
, filterProc
, typeList
, (void *)dict
);
619 PyMem_DEL(defaultLocation
);
621 PyErr_Mac(ErrorObject
, err
);
624 return (PyObject
*)newnavrrobject(&reply
);
627 static char nav_NavChooseFolder__doc__
[] =
628 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
632 nav_NavChooseFolder(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
635 AEDesc
*defaultLocation
= NULL
;
636 NavReplyRecord reply
;
637 NavDialogOptions dialogOptions
;
638 NavEventUPP eventProc
= NULL
;
639 NavObjectFilterUPP filterProc
= NULL
;
642 if ( kw
&& PyObject_IsTrue(kw
) ) {
643 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
646 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
648 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
650 err
= NavChooseFolder(defaultLocation
, &reply
, &dialogOptions
,
651 eventProc
, filterProc
, (void *)dict
);
652 PyMem_DEL(defaultLocation
);
654 PyErr_Mac(ErrorObject
, err
);
657 return (PyObject
*)newnavrrobject(&reply
);
660 static char nav_NavChooseVolume__doc__
[] =
661 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
665 nav_NavChooseVolume(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
668 AEDesc
*defaultLocation
= NULL
;
669 NavReplyRecord reply
;
670 NavDialogOptions dialogOptions
;
671 NavEventUPP eventProc
= NULL
;
672 NavObjectFilterUPP filterProc
= NULL
;
675 if ( kw
&& PyObject_IsTrue(kw
) ) {
676 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
679 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
681 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
683 err
= NavChooseVolume(defaultLocation
, &reply
, &dialogOptions
,
684 eventProc
, filterProc
, (void *)dict
);
685 PyMem_DEL(defaultLocation
);
687 PyErr_Mac(ErrorObject
, err
);
690 return (PyObject
*)newnavrrobject(&reply
);
693 static char nav_NavChooseObject__doc__
[] =
694 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
698 nav_NavChooseObject(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
701 AEDesc
*defaultLocation
= NULL
;
702 NavReplyRecord reply
;
703 NavDialogOptions dialogOptions
;
704 NavEventUPP eventProc
= NULL
;
705 NavObjectFilterUPP filterProc
= NULL
;
708 if ( kw
&& PyObject_IsTrue(kw
) ) {
709 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
712 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
714 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
716 err
= NavChooseObject(defaultLocation
, &reply
, &dialogOptions
,
717 eventProc
, filterProc
, (void *)dict
);
718 PyMem_DEL(defaultLocation
);
720 PyErr_Mac(ErrorObject
, err
);
723 return (PyObject
*)newnavrrobject(&reply
);
726 static char nav_NavNewFolder__doc__
[] =
727 "(DialogOptions dict or kwargs+defaultLocation,eventProc) -> NavReplyRecord"
731 nav_NavNewFolder(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
734 AEDesc
*defaultLocation
= NULL
;
735 NavReplyRecord reply
;
736 NavDialogOptions dialogOptions
;
737 NavEventUPP eventProc
= NULL
;
740 if ( kw
&& PyObject_IsTrue(kw
) ) {
741 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
744 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
746 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
748 err
= NavNewFolder(defaultLocation
, &reply
, &dialogOptions
, eventProc
, (void *)dict
);
749 PyMem_DEL(defaultLocation
);
751 PyErr_Mac(ErrorObject
, err
);
754 return (PyObject
*)newnavrrobject(&reply
);
758 /* XXXX I don't know what to do with the void * argument */
759 static char nav_NavCustomControl__doc__
[] =
765 nav_NavCustomControl(PyObject
*self
, PyObject
*args
)
768 if (!PyArg_ParseTuple(args
, ""))
775 static char nav_NavServicesCanRun__doc__
[] =
780 nav_NavServicesCanRun(PyObject
*self
, PyObject
*args
)
783 if (!PyArg_ParseTuple(args
, ""))
785 rv
= NavServicesCanRun();
786 return Py_BuildValue("l", (long)rv
);
789 static char nav_NavServicesAvailable__doc__
[] =
794 nav_NavServicesAvailable(PyObject
*self
, PyObject
*args
)
798 if (!PyArg_ParseTuple(args
, ""))
800 rv
= NavServicesAvailable();
801 return Py_BuildValue("l", (long)rv
);
804 static char nav_NavLoad__doc__
[] =
809 nav_NavLoad(PyObject
*self
, PyObject
*args
)
812 if (!PyArg_ParseTuple(args
, ""))
819 static char nav_NavUnload__doc__
[] =
824 nav_NavUnload(PyObject
*self
, PyObject
*args
)
827 if (!PyArg_ParseTuple(args
, ""))
834 static char nav_NavLibraryVersion__doc__
[] =
839 nav_NavLibraryVersion(PyObject
*self
, PyObject
*args
)
843 if (!PyArg_ParseTuple(args
, ""))
845 rv
= NavLibraryVersion();
846 return Py_BuildValue("l", (long)rv
);
849 static char nav_NavGetDefaultDialogOptions__doc__
[] =
850 "()->dict\nPass dict or keyword args with same names to other calls."
854 nav_NavGetDefaultDialogOptions(PyObject
*self
, PyObject
*args
)
856 NavDialogOptions dialogOptions
;
859 err
= NavGetDefaultDialogOptions(&dialogOptions
);
861 PyErr_Mac(ErrorObject
, err
);
864 return Py_BuildValue("{s:h,s:l,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&}",
865 "version", dialogOptions
.version
,
866 "dialogOptionFlags", dialogOptions
.dialogOptionFlags
,
867 "location", PyMac_BuildPoint
, dialogOptions
.location
,
868 "clientName", PyMac_BuildStr255
, &dialogOptions
.clientName
,
869 "windowTitle", PyMac_BuildStr255
, &dialogOptions
.windowTitle
,
870 "actionButtonLabel", PyMac_BuildStr255
, &dialogOptions
.actionButtonLabel
,
871 "cancelButtonLabel", PyMac_BuildStr255
, &dialogOptions
.cancelButtonLabel
,
872 "savedFileName", PyMac_BuildStr255
, &dialogOptions
.savedFileName
,
873 "message", PyMac_BuildStr255
, &dialogOptions
.message
,
874 "preferenceKey", PyMac_BuildOSType
, dialogOptions
.preferenceKey
,
875 "popupExtension", OptResObj_New
, dialogOptions
.popupExtension
);
878 /* List of methods defined in the module */
880 static struct PyMethodDef nav_methods
[] = {
881 {"NavGetFile", (PyCFunction
)nav_NavGetFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavGetFile__doc__
},
882 {"NavPutFile", (PyCFunction
)nav_NavPutFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavPutFile__doc__
},
883 {"NavAskSaveChanges", (PyCFunction
)nav_NavAskSaveChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavAskSaveChanges__doc__
},
884 {"NavCustomAskSaveChanges", (PyCFunction
)nav_NavCustomAskSaveChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavCustomAskSaveChanges__doc__
},
885 {"NavAskDiscardChanges", (PyCFunction
)nav_NavAskDiscardChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavAskDiscardChanges__doc__
},
886 {"NavChooseFile", (PyCFunction
)nav_NavChooseFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseFile__doc__
},
887 {"NavChooseFolder", (PyCFunction
)nav_NavChooseFolder
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseFolder__doc__
},
888 {"NavChooseVolume", (PyCFunction
)nav_NavChooseVolume
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseVolume__doc__
},
889 {"NavChooseObject", (PyCFunction
)nav_NavChooseObject
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseObject__doc__
},
890 {"NavNewFolder", (PyCFunction
)nav_NavNewFolder
, METH_VARARGS
|METH_KEYWORDS
, nav_NavNewFolder__doc__
},
892 {"NavCustomControl", (PyCFunction
)nav_NavCustomControl
, METH_VARARGS
, nav_NavCustomControl__doc__
},
894 {"NavServicesCanRun", (PyCFunction
)nav_NavServicesCanRun
, METH_VARARGS
, nav_NavServicesCanRun__doc__
},
895 {"NavServicesAvailable", (PyCFunction
)nav_NavServicesAvailable
, METH_VARARGS
, nav_NavServicesAvailable__doc__
},
896 {"NavLoad", (PyCFunction
)nav_NavLoad
, METH_VARARGS
, nav_NavLoad__doc__
},
897 {"NavUnload", (PyCFunction
)nav_NavUnload
, METH_VARARGS
, nav_NavUnload__doc__
},
898 {"NavLibraryVersion", (PyCFunction
)nav_NavLibraryVersion
, METH_VARARGS
, nav_NavLibraryVersion__doc__
},
899 {"NavGetDefaultDialogOptions", (PyCFunction
)nav_NavGetDefaultDialogOptions
, METH_VARARGS
, nav_NavGetDefaultDialogOptions__doc__
},
900 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
904 /* Initialization function for the module (*must* be called initNav) */
906 static char Nav_module_documentation
[] =
907 "Interface to Navigation Services\n"
908 "Most calls accept a NavDialogOptions dictionary or keywords with the same names, pass {}\n"
909 "if you want the default options.\n"
910 "Use NavGetDefaultDialogOptions() to find out common option names.\n"
911 "See individual docstrings for additional keyword args/dictentries supported by each call.\n"
912 "Pass None as eventProc to get movable-modal dialogs that process updates through the standard Python mechanism."
920 /* Test that we have NavServices */
921 if ( !NavServicesAvailable() ) {
922 PyErr_SetString(PyExc_ImportError
, "Navigation Services not available");
925 /* Create the module and add the functions */
926 m
= Py_InitModule4("Nav", nav_methods
,
927 Nav_module_documentation
,
928 (PyObject
*)NULL
,PYTHON_API_VERSION
);
930 /* Add some symbolic constants to the module */
931 d
= PyModule_GetDict(m
);
932 ErrorObject
= PyString_FromString("Nav.error");
933 PyDict_SetItemString(d
, "error", ErrorObject
);
935 /* XXXX Add constants here */
938 my_eventProcUPP
= NewNavEventUPP(my_eventProc
);
939 my_previewProcUPP
= NewNavPreviewUPP(my_previewProc
);
940 my_filterProcUPP
= NewNavObjectFilterUPP(my_filterProc
);