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>
38 static PyObject
*ErrorObject
;
40 static NavEventUPP my_eventProcUPP
;
41 static NavPreviewUPP my_previewProcUPP
;
42 static NavObjectFilterUPP my_filterProcUPP
;
44 /* Callback functions */
46 my_eventProc(NavEventCallbackMessage callBackSelector
,
47 NavCBRecPtr callBackParms
,
48 NavCallBackUserData callbackUD
)
50 PyObject
*dict
= (PyObject
*)callbackUD
;
55 if ( (pyfunc
= PyDict_GetItemString(dict
, "eventProc")) == NULL
) {
59 if ( pyfunc
== Py_None
) {
62 rv
= PyObject_CallFunction(pyfunc
, "ls#", (long)callBackSelector
,
63 (void *)callBackParms
, sizeof(NavCBRec
));
67 PySys_WriteStderr("Nav: exception in eventProc callback\n");
73 my_previewProc(NavCBRecPtr callBackParms
,
74 NavCallBackUserData callbackUD
)
76 PyObject
*dict
= (PyObject
*)callbackUD
;
81 if (!dict
) return false;
82 if ( (pyfunc
= PyDict_GetItemString(dict
, "previewProc")) == NULL
) {
86 rv
= PyObject_CallFunction(pyfunc
, "s#", (void *)callBackParms
, sizeof(NavCBRec
));
88 c_rv
= PyObject_IsTrue(rv
);
91 PySys_WriteStderr("Nav: exception in previewProc callback\n");
98 my_filterProc(AEDesc
*theItem
, void *info
,
99 NavCallBackUserData callbackUD
,
100 NavFilterModes filterMode
)
102 PyObject
*dict
= (PyObject
*)callbackUD
;
105 Boolean c_rv
= false;
107 if (!dict
) return false;
108 if ( (pyfunc
= PyDict_GetItemString(dict
, "filterProc")) == NULL
) {
112 rv
= PyObject_CallFunction(pyfunc
, "O&s#h",
113 AEDesc_NewBorrowed
, theItem
, info
, sizeof(NavFileOrFolderInfo
), (short)filterMode
);
115 c_rv
= PyObject_IsTrue(rv
);
118 PySys_WriteStderr("Nav: exception in filterProc callback\n");
124 /* ----------------------------------------------------- */
126 filldialogoptions(PyObject
*d
,
127 AEDesc
**defaultLocationP
,
128 NavDialogOptions
*opt
,
129 NavEventUPP
*eventProcP
,
130 NavPreviewUPP
*previewProcP
,
131 NavObjectFilterUPP
*filterProcP
,
132 NavTypeListHandle
*typeListP
,
134 OSType
*fileCreatorP
)
137 PyObject
*key
, *value
;
139 AEDesc
*defaultLocation_storage
;
141 NavGetDefaultDialogOptions(opt
);
143 while ( PyDict_Next(d
, &pos
, &key
, &value
) ) {
144 if ( !key
|| !value
|| !PyString_Check(key
) ) {
145 PyErr_SetString(ErrorObject
, "DialogOption has non-string key");
148 keystr
= PyString_AsString(key
);
149 if( strcmp(keystr
, "defaultLocation") == 0 ) {
150 if ( (defaultLocation_storage
= PyMem_NEW(AEDesc
, 1)) == NULL
) {
154 if ( !PyArg_Parse(value
, "O&", AEDesc_Convert
, defaultLocation_storage
) ) {
155 PyMem_DEL(defaultLocation_storage
);
158 *defaultLocationP
= defaultLocation_storage
;
159 } else if( strcmp(keystr
, "version") == 0 ) {
160 if ( !PyArg_Parse(value
, "H", &opt
->version
) )
162 } else if( strcmp(keystr
, "dialogOptionFlags") == 0 ) {
163 if ( !PyArg_Parse(value
, "k", &opt
->dialogOptionFlags
) )
165 } else if( strcmp(keystr
, "location") == 0 ) {
166 if ( !PyArg_Parse(value
, "O&", PyMac_GetPoint
, &opt
->location
) )
168 } else if( strcmp(keystr
, "clientName") == 0 ) {
169 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->clientName
) )
171 } else if( strcmp(keystr
, "windowTitle") == 0 ) {
172 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->windowTitle
) )
174 } else if( strcmp(keystr
, "actionButtonLabel") == 0 ) {
175 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->actionButtonLabel
) )
177 } else if( strcmp(keystr
, "cancelButtonLabel") == 0 ) {
178 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->cancelButtonLabel
) )
180 } else if( strcmp(keystr
, "savedFileName") == 0 ) {
181 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->savedFileName
) )
183 } else if( strcmp(keystr
, "message") == 0 ) {
184 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->message
) )
186 } else if( strcmp(keystr
, "preferenceKey") == 0 ) {
187 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, &opt
->preferenceKey
) )
189 } else if( strcmp(keystr
, "popupExtension") == 0 ) {
190 if ( !PyArg_Parse(value
, "O&", ResObj_Convert
, &opt
->popupExtension
) )
192 } else if( eventProcP
&& strcmp(keystr
, "eventProc") == 0 ) {
193 *eventProcP
= my_eventProcUPP
;
194 } else if( previewProcP
&& strcmp(keystr
, "previewProc") == 0 ) {
195 *previewProcP
= my_previewProcUPP
;
196 } else if( filterProcP
&& strcmp(keystr
, "filterProc") == 0 ) {
197 *filterProcP
= my_filterProcUPP
;
198 } else if( typeListP
&& strcmp(keystr
, "typeList") == 0 ) {
199 if ( !PyArg_Parse(value
, "O&", ResObj_Convert
, typeListP
) )
201 } else if( fileTypeP
&& strcmp(keystr
, "fileType") == 0 ) {
202 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, fileTypeP
) )
204 } else if( fileCreatorP
&& strcmp(keystr
, "fileCreator") == 0 ) {
205 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, fileCreatorP
) )
208 PyErr_Format(ErrorObject
, "Unknown DialogOption key: %s", keystr
);
215 /* ----------------------------------------------------- */
217 /* Declarations for objects of type NavReplyRecord */
221 NavReplyRecord itself
;
224 static PyTypeObject Navrrtype
;
228 /* ---------------------------------------------------------------- */
230 static char nav_NavTranslateFile__doc__
[] =
231 "(NavTranslationOptions)->None"
235 nav_NavTranslateFile(navrrobject
*self
, PyObject
*args
)
237 NavTranslationOptions howToTranslate
;
240 if (!PyArg_ParseTuple(args
, "k", &howToTranslate
))
242 err
= NavTranslateFile(&self
->itself
, howToTranslate
);
244 PyErr_Mac(ErrorObject
, err
);
251 static char nav_NavCompleteSave__doc__
[] =
252 "(NavTranslationOptions)->None"
256 nav_NavCompleteSave(navrrobject
*self
, PyObject
*args
)
258 NavTranslationOptions howToTranslate
;
261 if (!PyArg_ParseTuple(args
, "k", &howToTranslate
))
263 err
= NavCompleteSave(&self
->itself
, howToTranslate
);
265 PyErr_Mac(ErrorObject
, err
);
273 static struct PyMethodDef navrr_methods
[] = {
274 {"NavTranslateFile", (PyCFunction
)nav_NavTranslateFile
, METH_VARARGS
, nav_NavTranslateFile__doc__
},
275 {"NavCompleteSave", (PyCFunction
)nav_NavCompleteSave
, METH_VARARGS
, nav_NavCompleteSave__doc__
},
277 {NULL
, NULL
} /* sentinel */
284 newnavrrobject(NavReplyRecord
*itself
)
288 self
= PyObject_NEW(navrrobject
, &Navrrtype
);
291 self
->itself
= *itself
;
297 navrr_dealloc(navrrobject
*self
)
299 NavDisposeReply(&self
->itself
);
304 navrr_getattr(navrrobject
*self
, char *name
)
309 if( strcmp(name
, "__members__") == 0 )
310 return Py_BuildValue(
312 "version", "validRecord", "replacing",
313 "isStationery", "translationNeeded",
316 "fileTranslation", "keyScript", "saveFileName");
318 if( strcmp(name
, "version") == 0 )
319 return Py_BuildValue("h", self
->itself
.version
);
320 if( strcmp(name
, "validRecord") == 0 )
321 return Py_BuildValue("l", (long)self
->itself
.validRecord
);
322 if( strcmp(name
, "replacing") == 0 )
323 return Py_BuildValue("l", (long)self
->itself
.replacing
);
324 if( strcmp(name
, "isStationery") == 0 )
325 return Py_BuildValue("l", (long)self
->itself
.isStationery
);
326 if( strcmp(name
, "translationNeeded") == 0 )
327 return Py_BuildValue("l", (long)self
->itself
.translationNeeded
);
328 if( strcmp(name
, "selection") == 0 ) {
332 PyObject
*rv
, *rvitem
;
335 if ((err
=AECountItems(&self
->itself
.selection
, &count
))) {
336 PyErr_Mac(ErrorObject
, err
);
339 if ( (rv
=PyList_New(count
)) == NULL
)
341 for(i
=0; i
<count
; i
++) {
342 desc
.dataHandle
= NULL
;
343 if ((err
=AEGetNthDesc(&self
->itself
.selection
, i
+1, typeFSS
, NULL
, &desc
))) {
345 PyErr_Mac(ErrorObject
, err
);
348 if ((err
=AEGetDescData(&desc
, &fss
, sizeof(FSSpec
)))) {
350 PyErr_Mac(ErrorObject
, err
);
353 rvitem
= PyMac_BuildFSSpec(&fss
);
354 PyList_SetItem(rv
, i
, rvitem
);
355 AEDisposeDesc(&desc
);
359 if( strcmp(name
, "selection_fsr") == 0 ) {
363 PyObject
*rv
, *rvitem
;
366 if ((err
=AECountItems(&self
->itself
.selection
, &count
))) {
367 PyErr_Mac(ErrorObject
, err
);
370 if ( (rv
=PyList_New(count
)) == NULL
)
372 for(i
=0; i
<count
; i
++) {
373 desc
.dataHandle
= NULL
;
374 if ((err
=AEGetNthDesc(&self
->itself
.selection
, i
+1, typeFSRef
, NULL
, &desc
))) {
376 PyErr_Mac(ErrorObject
, err
);
379 if ((err
=AEGetDescData(&desc
, &fsr
, sizeof(FSRef
)))) {
381 PyErr_Mac(ErrorObject
, err
);
384 rvitem
= PyMac_BuildFSRef(&fsr
);
385 PyList_SetItem(rv
, i
, rvitem
);
386 AEDisposeDesc(&desc
);
390 if( strcmp(name
, "fileTranslation") == 0 )
391 return ResObj_New((Handle
)self
->itself
.fileTranslation
);
392 if( strcmp(name
, "keyScript") == 0 )
393 return Py_BuildValue("h", (short)self
->itself
.keyScript
);
394 if( strcmp(name
, "saveFileName") == 0 )
395 return Py_BuildValue("O&", CFStringRefObj_New
, self
->itself
.saveFileName
);
398 return Py_FindMethod(navrr_methods
, (PyObject
*)self
, name
);
402 navrr_setattr(navrrobject
*self
, char *name
, PyObject
*v
)
404 /* Set attribute 'name' to value 'v'. v==NULL means delete */
406 /* XXXX Add your own setattr code here */
410 static char Navrrtype__doc__
[] =
411 "Record containing result of a Nav file selection call. Use dir() for member names."
414 static PyTypeObject Navrrtype
= {
415 PyObject_HEAD_INIT(&PyType_Type
)
417 "Nav.NavReplyRecord", /*tp_name*/
418 sizeof(navrrobject
), /*tp_basicsize*/
421 (destructor
)navrr_dealloc
, /*tp_dealloc*/
422 (printfunc
)0, /*tp_print*/
423 (getattrfunc
)navrr_getattr
, /*tp_getattr*/
424 (setattrfunc
)navrr_setattr
, /*tp_setattr*/
425 (cmpfunc
)0, /*tp_compare*/
426 (reprfunc
)0, /*tp_repr*/
428 0, /*tp_as_sequence*/
430 (hashfunc
)0, /*tp_hash*/
431 (ternaryfunc
)0, /*tp_call*/
432 (reprfunc
)0, /*tp_str*/
434 /* Space for future expansion */
436 Navrrtype__doc__
/* Documentation string */
439 /* End of code for NavReplyRecord objects */
441 /* ----------------------------------------------------- */
443 static char nav_NavGetFile__doc__
[] =
444 "(DialogOptions dict or kwargs+defaultLocation,eventProc,previewProc,filterProc,typeList) -> NavReplyRecord"
448 nav_NavGetFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
451 AEDesc
*defaultLocation
= NULL
;
452 NavReplyRecord reply
;
453 NavDialogOptions dialogOptions
;
454 NavEventUPP eventProc
= NULL
;
455 NavPreviewUPP previewProc
= NULL
;
456 NavObjectFilterUPP filterProc
= NULL
;
457 NavTypeListHandle typeList
= NULL
;
460 if ( kw
&& PyObject_IsTrue(kw
) ) {
461 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
464 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
466 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, &previewProc
, &filterProc
, &typeList
, NULL
, NULL
))
468 err
= NavGetFile(defaultLocation
, &reply
, &dialogOptions
,
469 eventProc
, previewProc
, filterProc
, typeList
, (void *)dict
);
470 PyMem_DEL(defaultLocation
);
472 PyErr_Mac(ErrorObject
, err
);
475 return (PyObject
*)newnavrrobject(&reply
);
478 static char nav_NavPutFile__doc__
[] =
479 "(DialogOptions dict or kwargs+defaultLocation,eventProc,fileCreator,fileType) -> NavReplyRecord"
483 nav_NavPutFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
486 AEDesc
*defaultLocation
= NULL
;
487 NavReplyRecord reply
;
488 NavDialogOptions dialogOptions
;
489 NavEventUPP eventProc
= NULL
;
494 if ( kw
&& PyObject_IsTrue(kw
) ) {
495 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
498 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
500 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, &fileType
, &fileCreator
))
502 err
= NavPutFile(defaultLocation
, &reply
, &dialogOptions
,
503 eventProc
, fileType
, fileCreator
, (void *)dict
);
504 PyMem_DEL(defaultLocation
);
506 PyErr_Mac(ErrorObject
, err
);
509 return (PyObject
*)newnavrrobject(&reply
);
512 static char nav_NavAskSaveChanges__doc__
[] =
513 "(NavAskSaveChangesAction, DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
518 nav_NavAskSaveChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
521 NavDialogOptions dialogOptions
;
522 NavAskSaveChangesAction action
;
523 NavAskSaveChangesResult reply
;
524 NavEventUPP eventProc
= NULL
;
527 if ( kw
&& PyObject_IsTrue(kw
) ) {
528 if (!PyArg_ParseTuple(args
, "k", &action
))
531 } else if (!PyArg_ParseTuple(args
, "lO!", &action
, &PyDict_Type
, &dict
))
533 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
535 err
= NavAskSaveChanges(&dialogOptions
, action
, &reply
, eventProc
, (void *)dict
);
537 PyErr_Mac(ErrorObject
, err
);
540 return Py_BuildValue("l", (long)reply
);
543 static char nav_NavCustomAskSaveChanges__doc__
[] =
544 "(DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
548 nav_NavCustomAskSaveChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
551 NavDialogOptions dialogOptions
;
552 NavAskSaveChangesResult reply
;
553 NavEventUPP eventProc
= NULL
;
556 if ( kw
&& PyObject_IsTrue(kw
) ) {
557 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
560 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
562 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
564 err
= NavCustomAskSaveChanges(&dialogOptions
, &reply
, eventProc
, (void *)dict
);
566 PyErr_Mac(ErrorObject
, err
);
569 return Py_BuildValue("l", (long)reply
);
572 static char nav_NavAskDiscardChanges__doc__
[] =
573 "(DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
577 nav_NavAskDiscardChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
580 NavDialogOptions dialogOptions
;
581 NavAskSaveChangesResult reply
;
582 NavEventUPP eventProc
= NULL
;
585 if ( kw
&& PyObject_IsTrue(kw
) ) {
586 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
589 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
591 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
593 err
= NavAskDiscardChanges(&dialogOptions
, &reply
, eventProc
, (void *)dict
);
595 PyErr_Mac(ErrorObject
, err
);
598 return Py_BuildValue("l", (long)reply
);
601 static char nav_NavChooseFile__doc__
[] =
602 "(DialogOptions dict or kwargs+defaultLocation,eventProc,previewProc,filterProc,typeList) -> NavReplyRecord"
606 nav_NavChooseFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
609 AEDesc
*defaultLocation
= NULL
;
610 NavReplyRecord reply
;
611 NavDialogOptions dialogOptions
;
612 NavEventUPP eventProc
= NULL
;
613 NavPreviewUPP previewProc
= NULL
;
614 NavObjectFilterUPP filterProc
= NULL
;
615 NavTypeListHandle typeList
= NULL
;
618 if ( kw
&& PyObject_IsTrue(kw
) ) {
619 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
622 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
624 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, &previewProc
, &filterProc
, &typeList
, NULL
, NULL
))
626 err
= NavChooseFile(defaultLocation
, &reply
, &dialogOptions
,
627 eventProc
, previewProc
, filterProc
, typeList
, (void *)dict
);
628 PyMem_DEL(defaultLocation
);
630 PyErr_Mac(ErrorObject
, err
);
633 return (PyObject
*)newnavrrobject(&reply
);
636 static char nav_NavChooseFolder__doc__
[] =
637 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
641 nav_NavChooseFolder(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
644 AEDesc
*defaultLocation
= NULL
;
645 NavReplyRecord reply
;
646 NavDialogOptions dialogOptions
;
647 NavEventUPP eventProc
= NULL
;
648 NavObjectFilterUPP filterProc
= NULL
;
651 if ( kw
&& PyObject_IsTrue(kw
) ) {
652 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
655 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
657 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
659 err
= NavChooseFolder(defaultLocation
, &reply
, &dialogOptions
,
660 eventProc
, filterProc
, (void *)dict
);
661 PyMem_DEL(defaultLocation
);
663 PyErr_Mac(ErrorObject
, err
);
666 return (PyObject
*)newnavrrobject(&reply
);
669 static char nav_NavChooseVolume__doc__
[] =
670 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
674 nav_NavChooseVolume(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
677 AEDesc
*defaultLocation
= NULL
;
678 NavReplyRecord reply
;
679 NavDialogOptions dialogOptions
;
680 NavEventUPP eventProc
= NULL
;
681 NavObjectFilterUPP filterProc
= NULL
;
684 if ( kw
&& PyObject_IsTrue(kw
) ) {
685 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
688 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
690 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
692 err
= NavChooseVolume(defaultLocation
, &reply
, &dialogOptions
,
693 eventProc
, filterProc
, (void *)dict
);
694 PyMem_DEL(defaultLocation
);
696 PyErr_Mac(ErrorObject
, err
);
699 return (PyObject
*)newnavrrobject(&reply
);
702 static char nav_NavChooseObject__doc__
[] =
703 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
707 nav_NavChooseObject(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
710 AEDesc
*defaultLocation
= NULL
;
711 NavReplyRecord reply
;
712 NavDialogOptions dialogOptions
;
713 NavEventUPP eventProc
= NULL
;
714 NavObjectFilterUPP filterProc
= NULL
;
717 if ( kw
&& PyObject_IsTrue(kw
) ) {
718 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
721 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
723 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
725 err
= NavChooseObject(defaultLocation
, &reply
, &dialogOptions
,
726 eventProc
, filterProc
, (void *)dict
);
727 PyMem_DEL(defaultLocation
);
729 PyErr_Mac(ErrorObject
, err
);
732 return (PyObject
*)newnavrrobject(&reply
);
735 static char nav_NavNewFolder__doc__
[] =
736 "(DialogOptions dict or kwargs+defaultLocation,eventProc) -> NavReplyRecord"
740 nav_NavNewFolder(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
743 AEDesc
*defaultLocation
= NULL
;
744 NavReplyRecord reply
;
745 NavDialogOptions dialogOptions
;
746 NavEventUPP eventProc
= NULL
;
749 if ( kw
&& PyObject_IsTrue(kw
) ) {
750 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
753 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
755 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
757 err
= NavNewFolder(defaultLocation
, &reply
, &dialogOptions
, eventProc
, (void *)dict
);
758 PyMem_DEL(defaultLocation
);
760 PyErr_Mac(ErrorObject
, err
);
763 return (PyObject
*)newnavrrobject(&reply
);
767 /* XXXX I don't know what to do with the void * argument */
768 static char nav_NavCustomControl__doc__
[] =
774 nav_NavCustomControl(PyObject
*self
, PyObject
*args
)
777 if (!PyArg_ParseTuple(args
, ""))
784 static char nav_NavServicesCanRun__doc__
[] =
789 nav_NavServicesCanRun(PyObject
*self
, PyObject
*args
)
792 if (!PyArg_ParseTuple(args
, ""))
794 rv
= NavServicesCanRun();
795 return Py_BuildValue("l", (long)rv
);
798 static char nav_NavServicesAvailable__doc__
[] =
803 nav_NavServicesAvailable(PyObject
*self
, PyObject
*args
)
807 if (!PyArg_ParseTuple(args
, ""))
809 rv
= NavServicesAvailable();
810 return Py_BuildValue("l", (long)rv
);
813 static char nav_NavLoad__doc__
[] =
818 nav_NavLoad(PyObject
*self
, PyObject
*args
)
821 if (!PyArg_ParseTuple(args
, ""))
828 static char nav_NavUnload__doc__
[] =
833 nav_NavUnload(PyObject
*self
, PyObject
*args
)
836 if (!PyArg_ParseTuple(args
, ""))
843 static char nav_NavLibraryVersion__doc__
[] =
848 nav_NavLibraryVersion(PyObject
*self
, PyObject
*args
)
852 if (!PyArg_ParseTuple(args
, ""))
854 rv
= NavLibraryVersion();
855 return Py_BuildValue("l", (long)rv
);
858 static char nav_NavGetDefaultDialogOptions__doc__
[] =
859 "()->dict\nPass dict or keyword args with same names to other calls."
863 nav_NavGetDefaultDialogOptions(PyObject
*self
, PyObject
*args
)
865 NavDialogOptions dialogOptions
;
868 err
= NavGetDefaultDialogOptions(&dialogOptions
);
870 PyErr_Mac(ErrorObject
, err
);
873 return Py_BuildValue(
874 "{s:h,s:l,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&,s:O&}",
875 "version", dialogOptions
.version
,
876 "dialogOptionFlags", dialogOptions
.dialogOptionFlags
,
877 "location", PyMac_BuildPoint
, dialogOptions
.location
,
878 "clientName", PyMac_BuildStr255
, &dialogOptions
.clientName
,
879 "windowTitle", PyMac_BuildStr255
, &dialogOptions
.windowTitle
,
880 "actionButtonLabel", PyMac_BuildStr255
, &dialogOptions
.actionButtonLabel
,
881 "cancelButtonLabel", PyMac_BuildStr255
, &dialogOptions
.cancelButtonLabel
,
882 "savedFileName", PyMac_BuildStr255
, &dialogOptions
.savedFileName
,
883 "message", PyMac_BuildStr255
, &dialogOptions
.message
,
884 "preferenceKey", PyMac_BuildOSType
, dialogOptions
.preferenceKey
885 ,"popupExtension", OptResObj_New
, dialogOptions
.popupExtension
889 /* List of methods defined in the module */
891 static struct PyMethodDef nav_methods
[] = {
892 {"NavGetFile", (PyCFunction
)nav_NavGetFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavGetFile__doc__
},
893 {"NavPutFile", (PyCFunction
)nav_NavPutFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavPutFile__doc__
},
894 {"NavAskSaveChanges", (PyCFunction
)nav_NavAskSaveChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavAskSaveChanges__doc__
},
895 {"NavCustomAskSaveChanges", (PyCFunction
)nav_NavCustomAskSaveChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavCustomAskSaveChanges__doc__
},
896 {"NavAskDiscardChanges", (PyCFunction
)nav_NavAskDiscardChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavAskDiscardChanges__doc__
},
897 {"NavChooseFile", (PyCFunction
)nav_NavChooseFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseFile__doc__
},
898 {"NavChooseFolder", (PyCFunction
)nav_NavChooseFolder
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseFolder__doc__
},
899 {"NavChooseVolume", (PyCFunction
)nav_NavChooseVolume
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseVolume__doc__
},
900 {"NavChooseObject", (PyCFunction
)nav_NavChooseObject
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseObject__doc__
},
901 {"NavNewFolder", (PyCFunction
)nav_NavNewFolder
, METH_VARARGS
|METH_KEYWORDS
, nav_NavNewFolder__doc__
},
903 {"NavCustomControl", (PyCFunction
)nav_NavCustomControl
, METH_VARARGS
, nav_NavCustomControl__doc__
},
905 {"NavServicesCanRun", (PyCFunction
)nav_NavServicesCanRun
, METH_VARARGS
, nav_NavServicesCanRun__doc__
},
906 {"NavServicesAvailable", (PyCFunction
)nav_NavServicesAvailable
, METH_VARARGS
, nav_NavServicesAvailable__doc__
},
907 {"NavLoad", (PyCFunction
)nav_NavLoad
, METH_VARARGS
, nav_NavLoad__doc__
},
908 {"NavUnload", (PyCFunction
)nav_NavUnload
, METH_VARARGS
, nav_NavUnload__doc__
},
909 {"NavLibraryVersion", (PyCFunction
)nav_NavLibraryVersion
, METH_VARARGS
, nav_NavLibraryVersion__doc__
},
910 {"NavGetDefaultDialogOptions", (PyCFunction
)nav_NavGetDefaultDialogOptions
, METH_VARARGS
, nav_NavGetDefaultDialogOptions__doc__
},
911 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
915 /* Initialization function for the module (*must* be called initNav) */
917 static char Nav_module_documentation
[] =
918 "Interface to Navigation Services\n"
919 "Most calls accept a NavDialogOptions dictionary or keywords with the same names, pass {}\n"
920 "if you want the default options.\n"
921 "Use NavGetDefaultDialogOptions() to find out common option names.\n"
922 "See individual docstrings for additional keyword args/dictentries supported by each call.\n"
923 "Pass None as eventProc to get movable-modal dialogs that process updates through the standard Python mechanism."
927 #endif /* !__LP64__ */
935 if (PyErr_WarnPy3k("In 3.x, Nav is removed.", 1))
939 PyErr_SetString(PyExc_ImportError
, "Navigation Services not available in 64-bit mode");
942 #else /* !__LP64__ */
944 /* Test that we have NavServices */
945 if ( !NavServicesAvailable() ) {
946 PyErr_SetString(PyExc_ImportError
, "Navigation Services not available");
949 /* Create the module and add the functions */
950 m
= Py_InitModule4("Nav", nav_methods
,
951 Nav_module_documentation
,
952 (PyObject
*)NULL
,PYTHON_API_VERSION
);
954 /* Add some symbolic constants to the module */
955 d
= PyModule_GetDict(m
);
956 ErrorObject
= PyString_FromString("Nav.error");
957 PyDict_SetItemString(d
, "error", ErrorObject
);
959 /* XXXX Add constants here */
962 my_eventProcUPP
= NewNavEventUPP(my_eventProc
);
963 my_previewProcUPP
= NewNavPreviewUPP(my_previewProc
);
964 my_filterProcUPP
= NewNavObjectFilterUPP(my_filterProc
);
965 #endif /* !__LP64__ */