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 ******************************************************************/
34 #include "pymactoolbox.h"
35 #ifdef WITHOUT_FRAMEWORKS
36 #include <Navigation.h>
38 #include <Carbon/Carbon.h>
41 static PyObject
*ErrorObject
;
43 static NavEventUPP my_eventProcUPP
;
44 static NavPreviewUPP my_previewProcUPP
;
45 static NavObjectFilterUPP my_filterProcUPP
;
47 /* Callback functions */
49 my_eventProc(NavEventCallbackMessage callBackSelector
,
50 NavCBRecPtr callBackParms
,
51 NavCallBackUserData callbackUD
)
53 PyObject
*dict
= (PyObject
*)callbackUD
;
58 if ( (pyfunc
= PyDict_GetItemString(dict
, "eventProc")) == NULL
) {
62 if ( pyfunc
== Py_None
) {
63 #if !TARGET_API_MAC_OSX
64 /* Special case: give update events to the Python event handling code */
65 if ( callBackSelector
== kNavCBEvent
&&
66 callBackParms
->eventData
.eventDataParms
.event
->what
== updateEvt
)
67 PyMac_HandleEvent(callBackParms
->eventData
.eventDataParms
.event
);
72 rv
= PyObject_CallFunction(pyfunc
, "ls#", (long)callBackSelector
,
73 (void *)callBackParms
, sizeof(NavCBRec
));
77 fprintf(stderr
, "Nav: exception in eventProc callback\n");
83 my_previewProc(NavCBRecPtr callBackParms
,
84 NavCallBackUserData callbackUD
)
86 PyObject
*dict
= (PyObject
*)callbackUD
;
91 if (!dict
) return false;
92 if ( (pyfunc
= PyDict_GetItemString(dict
, "previewProc")) == NULL
) {
96 rv
= PyObject_CallFunction(pyfunc
, "s#", (void *)callBackParms
, sizeof(NavCBRec
));
98 c_rv
= PyObject_IsTrue(rv
);
101 fprintf(stderr
, "Nav: exception in previewProc callback\n");
107 static pascal Boolean
108 my_filterProc(AEDesc
*theItem
, void *info
,
109 NavCallBackUserData callbackUD
,
110 NavFilterModes filterMode
)
112 PyObject
*dict
= (PyObject
*)callbackUD
;
115 Boolean c_rv
= false;
117 if (!dict
) return false;
118 if ( (pyfunc
= PyDict_GetItemString(dict
, "filterProc")) == NULL
) {
122 rv
= PyObject_CallFunction(pyfunc
, "O&s#h",
123 AEDesc_New
, theItem
, info
, sizeof(NavFileOrFolderInfo
), (short)filterMode
);
125 c_rv
= PyObject_IsTrue(rv
);
128 fprintf(stderr
, "Nav: exception in filterProc callback\n");
134 /* ----------------------------------------------------- */
136 filldialogoptions(PyObject
*d
,
137 AEDesc
**defaultLocationP
,
138 NavDialogOptions
*opt
,
139 NavEventUPP
*eventProcP
,
140 NavPreviewUPP
*previewProcP
,
141 NavObjectFilterUPP
*filterProcP
,
142 NavTypeListHandle
*typeListP
,
144 OSType
*fileCreatorP
)
147 PyObject
*key
, *value
;
149 AEDesc
*defaultLocation_storage
;
151 NavGetDefaultDialogOptions(opt
);
153 while ( PyDict_Next(d
, &pos
, &key
, &value
) ) {
154 if ( !key
|| !value
|| !PyString_Check(key
) ) {
155 PyErr_SetString(ErrorObject
, "DialogOption has non-string key");
158 keystr
= PyString_AsString(key
);
159 if( strcmp(keystr
, "defaultLocation") == 0 ) {
160 if ( (defaultLocation_storage
= PyMem_NEW(AEDesc
, 1)) == NULL
) {
164 if ( !PyArg_Parse(value
, "O&", AEDesc_Convert
, defaultLocation_storage
) ) {
165 PyMem_DEL(defaultLocation_storage
);
168 *defaultLocationP
= defaultLocation_storage
;
169 } else if( strcmp(keystr
, "version") == 0 ) {
170 if ( !PyArg_Parse(value
, "h", &opt
->version
) )
172 } else if( strcmp(keystr
, "dialogOptionFlags") == 0 ) {
173 if ( !PyArg_Parse(value
, "l", &opt
->dialogOptionFlags
) )
175 } else if( strcmp(keystr
, "location") == 0 ) {
176 if ( !PyArg_Parse(value
, "O&", PyMac_GetPoint
, &opt
->location
) )
178 } else if( strcmp(keystr
, "clientName") == 0 ) {
179 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->clientName
) )
181 } else if( strcmp(keystr
, "windowTitle") == 0 ) {
182 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->windowTitle
) )
184 } else if( strcmp(keystr
, "actionButtonLabel") == 0 ) {
185 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->actionButtonLabel
) )
187 } else if( strcmp(keystr
, "cancelButtonLabel") == 0 ) {
188 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->cancelButtonLabel
) )
190 } else if( strcmp(keystr
, "savedFileName") == 0 ) {
191 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->savedFileName
) )
193 } else if( strcmp(keystr
, "message") == 0 ) {
194 if ( !PyArg_Parse(value
, "O&", PyMac_GetStr255
, &opt
->message
) )
196 } else if( strcmp(keystr
, "preferenceKey") == 0 ) {
197 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, &opt
->preferenceKey
) )
199 } else if( strcmp(keystr
, "popupExtension") == 0 ) {
200 if ( !PyArg_Parse(value
, "O&", ResObj_Convert
, &opt
->popupExtension
) )
202 } else if( eventProcP
&& strcmp(keystr
, "eventProc") == 0 ) {
203 *eventProcP
= my_eventProcUPP
;
204 } else if( previewProcP
&& strcmp(keystr
, "previewProc") == 0 ) {
205 PyErr_SetString(ErrorObject
, "No callbacks implemented yet");
207 } else if( filterProcP
&& strcmp(keystr
, "filterProc") == 0 ) {
208 PyErr_SetString(ErrorObject
, "No callbacks implemented yet");
210 } else if( typeListP
&& strcmp(keystr
, "typeList") == 0 ) {
211 if ( !PyArg_Parse(value
, "O&", ResObj_Convert
, typeListP
) )
213 } else if( fileTypeP
&& strcmp(keystr
, "fileType") == 0 ) {
214 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, fileTypeP
) )
216 } else if( fileCreatorP
&& strcmp(keystr
, "fileCreator") == 0 ) {
217 if ( !PyArg_Parse(value
, "O&", PyMac_GetOSType
, fileCreatorP
) )
220 PyErr_Format(ErrorObject
, "Unknown DialogOption key: %s", keystr
);
227 /* ----------------------------------------------------- */
229 /* Declarations for objects of type NavReplyRecord */
233 NavReplyRecord itself
;
236 staticforward PyTypeObject Navrrtype
;
240 /* ---------------------------------------------------------------- */
242 static char nav_NavTranslateFile__doc__
[] =
243 "(NavTranslationOptions)->None"
247 nav_NavTranslateFile(navrrobject
*self
, PyObject
*args
)
249 NavTranslationOptions howToTranslate
;
252 if (!PyArg_ParseTuple(args
, "l", &howToTranslate
))
254 err
= NavTranslateFile(&self
->itself
, howToTranslate
);
256 PyErr_Mac(ErrorObject
, err
);
263 static char nav_NavCompleteSave__doc__
[] =
264 "(NavTranslationOptions)->None"
268 nav_NavCompleteSave(navrrobject
*self
, PyObject
*args
)
270 NavTranslationOptions howToTranslate
;
273 if (!PyArg_ParseTuple(args
, "l", &howToTranslate
))
275 err
= NavCompleteSave(&self
->itself
, howToTranslate
);
277 PyErr_Mac(ErrorObject
, err
);
285 static struct PyMethodDef navrr_methods
[] = {
286 {"NavTranslateFile", (PyCFunction
)nav_NavTranslateFile
, METH_VARARGS
, nav_NavTranslateFile__doc__
},
287 {"NavCompleteSave", (PyCFunction
)nav_NavCompleteSave
, METH_VARARGS
, nav_NavCompleteSave__doc__
},
289 {NULL
, NULL
} /* sentinel */
296 newnavrrobject(NavReplyRecord
*itself
)
300 self
= PyObject_NEW(navrrobject
, &Navrrtype
);
303 self
->itself
= *itself
;
309 navrr_dealloc(navrrobject
*self
)
311 NavDisposeReply(&self
->itself
);
316 navrr_getattr(navrrobject
*self
, char *name
)
320 if( strcmp(name
, "__members__") == 0 )
321 return Py_BuildValue("sssssss", "version", "validRecord", "replacing",
322 "isStationery", "translationNeeded", "selection", "fileTranslation");
323 if( strcmp(name
, "version") == 0 )
324 return Py_BuildValue("h", self
->itself
.version
);
325 if( strcmp(name
, "validRecord") == 0 )
326 return Py_BuildValue("l", (long)self
->itself
.validRecord
);
327 if( strcmp(name
, "replacing") == 0 )
328 return Py_BuildValue("l", (long)self
->itself
.replacing
);
329 if( strcmp(name
, "isStationery") == 0 )
330 return Py_BuildValue("l", (long)self
->itself
.isStationery
);
331 if( strcmp(name
, "translationNeeded") == 0 )
332 return Py_BuildValue("l", (long)self
->itself
.translationNeeded
);
333 if( strcmp(name
, "selection") == 0 ) {
336 PyObject
*rv
, *rvitem
;
339 if (err
=AECountItems(&self
->itself
.selection
, &count
)) {
340 PyErr_Mac(ErrorObject
, err
);
343 if ( (rv
=PyList_New(count
)) == NULL
)
345 for(i
=0; i
<count
; i
++) {
346 desc
.dataHandle
= NULL
;
347 if (err
=AEGetNthDesc(&self
->itself
.selection
, i
+1, typeFSS
, NULL
, &desc
)) {
349 PyErr_Mac(ErrorObject
, err
);
352 #if TARGET_API_MAC_CARBON
353 if (err
=AEGetDescData(&desc
, &fss
, sizeof(FSSpec
))) {
355 PyErr_Mac(ErrorObject
, err
);
359 memcpy((void *)&fss
, (void *)*desc
.dataHandle
, sizeof(FSSpec
));
361 rvitem
= PyMac_BuildFSSpec(&fss
);
362 PyList_SetItem(rv
, i
, rvitem
);
363 AEDisposeDesc(&desc
);
367 if( strcmp(name
, "fileTranslation") == 0 )
368 return ResObj_New((Handle
)self
->itself
.fileTranslation
);
371 return Py_FindMethod(navrr_methods
, (PyObject
*)self
, name
);
375 navrr_setattr(navrrobject
*self
, char *name
, PyObject
*v
)
377 /* Set attribute 'name' to value 'v'. v==NULL means delete */
379 /* XXXX Add your own setattr code here */
383 static char Navrrtype__doc__
[] =
384 "Record containing result of a Nav file selection call. Use dir() for member names."
387 static PyTypeObject Navrrtype
= {
388 PyObject_HEAD_INIT(&PyType_Type
)
390 "Nav.NavReplyRecord", /*tp_name*/
391 sizeof(navrrobject
), /*tp_basicsize*/
394 (destructor
)navrr_dealloc
, /*tp_dealloc*/
395 (printfunc
)0, /*tp_print*/
396 (getattrfunc
)navrr_getattr
, /*tp_getattr*/
397 (setattrfunc
)navrr_setattr
, /*tp_setattr*/
398 (cmpfunc
)0, /*tp_compare*/
399 (reprfunc
)0, /*tp_repr*/
401 0, /*tp_as_sequence*/
403 (hashfunc
)0, /*tp_hash*/
404 (ternaryfunc
)0, /*tp_call*/
405 (reprfunc
)0, /*tp_str*/
407 /* Space for future expansion */
409 Navrrtype__doc__
/* Documentation string */
412 /* End of code for NavReplyRecord objects */
414 /* ----------------------------------------------------- */
416 static char nav_NavGetFile__doc__
[] =
417 "(DialogOptions dict or kwargs+defaultLocation,eventProc,previewProc,filterProc,typeList) -> NavReplyRecord"
421 nav_NavGetFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
424 AEDesc
*defaultLocation
= NULL
;
425 NavReplyRecord reply
;
426 NavDialogOptions dialogOptions
;
427 NavEventUPP eventProc
= NULL
;
428 NavPreviewUPP previewProc
= NULL
;
429 NavObjectFilterUPP filterProc
= NULL
;
430 NavTypeListHandle typeList
= NULL
;
433 if ( kw
&& PyObject_IsTrue(kw
) ) {
434 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
437 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
439 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, &previewProc
, &filterProc
, &typeList
, NULL
, NULL
))
441 err
= NavGetFile(defaultLocation
, &reply
, &dialogOptions
,
442 eventProc
, previewProc
, filterProc
, typeList
, (void *)dict
);
443 PyMem_DEL(defaultLocation
);
445 PyErr_Mac(ErrorObject
, err
);
448 return (PyObject
*)newnavrrobject(&reply
);
451 static char nav_NavPutFile__doc__
[] =
452 "(DialogOptions dict or kwargs+defaultLocation,eventProc,fileCreator,fileType) -> NavReplyRecord"
456 nav_NavPutFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
459 AEDesc
*defaultLocation
= NULL
;
460 NavReplyRecord reply
;
461 NavDialogOptions dialogOptions
;
462 NavEventUPP eventProc
= NULL
;
467 if ( kw
&& PyObject_IsTrue(kw
) ) {
468 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
471 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
473 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, &fileType
, &fileCreator
))
475 err
= NavPutFile(defaultLocation
, &reply
, &dialogOptions
,
476 eventProc
, fileType
, fileCreator
, (void *)dict
);
477 PyMem_DEL(defaultLocation
);
479 PyErr_Mac(ErrorObject
, err
);
482 return (PyObject
*)newnavrrobject(&reply
);
485 static char nav_NavAskSaveChanges__doc__
[] =
486 "(NavAskSaveChangesAction, DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
491 nav_NavAskSaveChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
494 NavDialogOptions dialogOptions
;
495 NavAskSaveChangesAction action
;
496 NavAskSaveChangesResult reply
;
497 NavEventUPP eventProc
= NULL
;
500 if ( kw
&& PyObject_IsTrue(kw
) ) {
501 if (!PyArg_ParseTuple(args
, "l", &action
))
504 } else if (!PyArg_ParseTuple(args
, "lO!", &action
, &PyDict_Type
, &dict
))
506 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
508 err
= NavAskSaveChanges(&dialogOptions
, action
, &reply
, eventProc
, (void *)dict
);
510 PyErr_Mac(ErrorObject
, err
);
513 return Py_BuildValue("l", (long)reply
);
516 static char nav_NavCustomAskSaveChanges__doc__
[] =
517 "(DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
521 nav_NavCustomAskSaveChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
524 NavDialogOptions dialogOptions
;
525 NavAskSaveChangesResult reply
;
526 NavEventUPP eventProc
= NULL
;
529 if ( kw
&& PyObject_IsTrue(kw
) ) {
530 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
533 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
535 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
537 err
= NavCustomAskSaveChanges(&dialogOptions
, &reply
, eventProc
, (void *)dict
);
539 PyErr_Mac(ErrorObject
, err
);
542 return Py_BuildValue("l", (long)reply
);
545 static char nav_NavAskDiscardChanges__doc__
[] =
546 "(DialogOptions dict or kwargs+eventProc) -> NavAskSaveChangesResult"
550 nav_NavAskDiscardChanges(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
553 NavDialogOptions dialogOptions
;
554 NavAskSaveChangesResult reply
;
555 NavEventUPP eventProc
= NULL
;
558 if ( kw
&& PyObject_IsTrue(kw
) ) {
559 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
562 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
564 if (!filldialogoptions(dict
, NULL
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
566 err
= NavAskDiscardChanges(&dialogOptions
, &reply
, eventProc
, (void *)dict
);
568 PyErr_Mac(ErrorObject
, err
);
571 return Py_BuildValue("l", (long)reply
);
574 static char nav_NavChooseFile__doc__
[] =
575 "(DialogOptions dict or kwargs+defaultLocation,eventProc,previewProc,filterProc,typeList) -> NavReplyRecord"
579 nav_NavChooseFile(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
582 AEDesc
*defaultLocation
= NULL
;
583 NavReplyRecord reply
;
584 NavDialogOptions dialogOptions
;
585 NavEventUPP eventProc
= NULL
;
586 NavPreviewUPP previewProc
= NULL
;
587 NavObjectFilterUPP filterProc
= NULL
;
588 NavTypeListHandle typeList
= NULL
;
591 if ( kw
&& PyObject_IsTrue(kw
) ) {
592 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
595 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
597 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, &previewProc
, &filterProc
, &typeList
, NULL
, NULL
))
599 err
= NavChooseFile(defaultLocation
, &reply
, &dialogOptions
,
600 eventProc
, previewProc
, filterProc
, typeList
, (void *)dict
);
601 PyMem_DEL(defaultLocation
);
603 PyErr_Mac(ErrorObject
, err
);
606 return (PyObject
*)newnavrrobject(&reply
);
609 static char nav_NavChooseFolder__doc__
[] =
610 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
614 nav_NavChooseFolder(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
617 AEDesc
*defaultLocation
= NULL
;
618 NavReplyRecord reply
;
619 NavDialogOptions dialogOptions
;
620 NavEventUPP eventProc
= NULL
;
621 NavObjectFilterUPP filterProc
= NULL
;
624 if ( kw
&& PyObject_IsTrue(kw
) ) {
625 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
628 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
630 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
632 err
= NavChooseFolder(defaultLocation
, &reply
, &dialogOptions
,
633 eventProc
, filterProc
, (void *)dict
);
634 PyMem_DEL(defaultLocation
);
636 PyErr_Mac(ErrorObject
, err
);
639 return (PyObject
*)newnavrrobject(&reply
);
642 static char nav_NavChooseVolume__doc__
[] =
643 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
647 nav_NavChooseVolume(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
650 AEDesc
*defaultLocation
= NULL
;
651 NavReplyRecord reply
;
652 NavDialogOptions dialogOptions
;
653 NavEventUPP eventProc
= NULL
;
654 NavObjectFilterUPP filterProc
= NULL
;
657 if ( kw
&& PyObject_IsTrue(kw
) ) {
658 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
661 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
663 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
665 err
= NavChooseVolume(defaultLocation
, &reply
, &dialogOptions
,
666 eventProc
, filterProc
, (void *)dict
);
667 PyMem_DEL(defaultLocation
);
669 PyErr_Mac(ErrorObject
, err
);
672 return (PyObject
*)newnavrrobject(&reply
);
675 static char nav_NavChooseObject__doc__
[] =
676 "(DialogOptions dict or kwargs+defaultLocation,eventProc,filterProc) -> NavReplyRecord"
680 nav_NavChooseObject(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
683 AEDesc
*defaultLocation
= NULL
;
684 NavReplyRecord reply
;
685 NavDialogOptions dialogOptions
;
686 NavEventUPP eventProc
= NULL
;
687 NavObjectFilterUPP filterProc
= NULL
;
690 if ( kw
&& PyObject_IsTrue(kw
) ) {
691 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
694 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
696 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, &filterProc
, NULL
, NULL
, NULL
))
698 err
= NavChooseObject(defaultLocation
, &reply
, &dialogOptions
,
699 eventProc
, filterProc
, (void *)dict
);
700 PyMem_DEL(defaultLocation
);
702 PyErr_Mac(ErrorObject
, err
);
705 return (PyObject
*)newnavrrobject(&reply
);
708 static char nav_NavNewFolder__doc__
[] =
709 "(DialogOptions dict or kwargs+defaultLocation,eventProc) -> NavReplyRecord"
713 nav_NavNewFolder(PyObject
*self
, PyObject
*args
, PyObject
*kw
)
716 AEDesc
*defaultLocation
= NULL
;
717 NavReplyRecord reply
;
718 NavDialogOptions dialogOptions
;
719 NavEventUPP eventProc
= NULL
;
722 if ( kw
&& PyObject_IsTrue(kw
) ) {
723 if (!PyArg_ParseTuple(args
, ";either keyword arguments or dictionary expected"))
726 } else if (!PyArg_ParseTuple(args
, "O!", &PyDict_Type
, &dict
))
728 if (!filldialogoptions(dict
, &defaultLocation
, &dialogOptions
, &eventProc
, NULL
, NULL
, NULL
, NULL
, NULL
))
730 err
= NavNewFolder(defaultLocation
, &reply
, &dialogOptions
, eventProc
, (void *)dict
);
731 PyMem_DEL(defaultLocation
);
733 PyErr_Mac(ErrorObject
, err
);
736 return (PyObject
*)newnavrrobject(&reply
);
740 /* XXXX I don't know what to do with the void * argument */
741 static char nav_NavCustomControl__doc__
[] =
747 nav_NavCustomControl(PyObject
*self
, PyObject
*args
)
750 if (!PyArg_ParseTuple(args
, ""))
757 static char nav_NavServicesCanRun__doc__
[] =
762 nav_NavServicesCanRun(PyObject
*self
, PyObject
*args
)
765 if (!PyArg_ParseTuple(args
, ""))
767 rv
= NavServicesCanRun();
768 return Py_BuildValue("l", (long)rv
);
771 static char nav_NavServicesAvailable__doc__
[] =
776 nav_NavServicesAvailable(PyObject
*self
, PyObject
*args
)
780 if (!PyArg_ParseTuple(args
, ""))
782 rv
= NavServicesAvailable();
783 return Py_BuildValue("l", (long)rv
);
786 static char nav_NavLoad__doc__
[] =
791 nav_NavLoad(PyObject
*self
, PyObject
*args
)
794 if (!PyArg_ParseTuple(args
, ""))
801 static char nav_NavUnload__doc__
[] =
806 nav_NavUnload(PyObject
*self
, PyObject
*args
)
809 if (!PyArg_ParseTuple(args
, ""))
816 static char nav_NavLibraryVersion__doc__
[] =
821 nav_NavLibraryVersion(PyObject
*self
, PyObject
*args
)
825 if (!PyArg_ParseTuple(args
, ""))
827 rv
= NavLibraryVersion();
828 return Py_BuildValue("l", (long)rv
);
831 static char nav_NavGetDefaultDialogOptions__doc__
[] =
832 "()->dict\nPass dict or keyword args with same names to other calls."
836 nav_NavGetDefaultDialogOptions(PyObject
*self
, PyObject
*args
)
838 NavDialogOptions dialogOptions
;
841 err
= NavGetDefaultDialogOptions(&dialogOptions
);
843 PyErr_Mac(ErrorObject
, err
);
846 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&}",
847 "version", dialogOptions
.version
,
848 "dialogOptionFlags", dialogOptions
.dialogOptionFlags
,
849 "location", PyMac_BuildPoint
, dialogOptions
.location
,
850 "clientName", PyMac_BuildStr255
, &dialogOptions
.clientName
,
851 "windowTitle", PyMac_BuildStr255
, &dialogOptions
.windowTitle
,
852 "actionButtonLabel", PyMac_BuildStr255
, &dialogOptions
.actionButtonLabel
,
853 "cancelButtonLabel", PyMac_BuildStr255
, &dialogOptions
.cancelButtonLabel
,
854 "savedFileName", PyMac_BuildStr255
, &dialogOptions
.savedFileName
,
855 "message", PyMac_BuildStr255
, &dialogOptions
.message
,
856 "preferenceKey", PyMac_BuildOSType
, dialogOptions
.preferenceKey
,
857 "popupExtension", OptResObj_New
, dialogOptions
.popupExtension
);
860 /* List of methods defined in the module */
862 static struct PyMethodDef nav_methods
[] = {
863 {"NavGetFile", (PyCFunction
)nav_NavGetFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavGetFile__doc__
},
864 {"NavPutFile", (PyCFunction
)nav_NavPutFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavPutFile__doc__
},
865 {"NavAskSaveChanges", (PyCFunction
)nav_NavAskSaveChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavAskSaveChanges__doc__
},
866 {"NavCustomAskSaveChanges", (PyCFunction
)nav_NavCustomAskSaveChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavCustomAskSaveChanges__doc__
},
867 {"NavAskDiscardChanges", (PyCFunction
)nav_NavAskDiscardChanges
, METH_VARARGS
|METH_KEYWORDS
, nav_NavAskDiscardChanges__doc__
},
868 {"NavChooseFile", (PyCFunction
)nav_NavChooseFile
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseFile__doc__
},
869 {"NavChooseFolder", (PyCFunction
)nav_NavChooseFolder
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseFolder__doc__
},
870 {"NavChooseVolume", (PyCFunction
)nav_NavChooseVolume
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseVolume__doc__
},
871 {"NavChooseObject", (PyCFunction
)nav_NavChooseObject
, METH_VARARGS
|METH_KEYWORDS
, nav_NavChooseObject__doc__
},
872 {"NavNewFolder", (PyCFunction
)nav_NavNewFolder
, METH_VARARGS
|METH_KEYWORDS
, nav_NavNewFolder__doc__
},
874 {"NavCustomControl", (PyCFunction
)nav_NavCustomControl
, METH_VARARGS
, nav_NavCustomControl__doc__
},
876 {"NavServicesCanRun", (PyCFunction
)nav_NavServicesCanRun
, METH_VARARGS
, nav_NavServicesCanRun__doc__
},
877 {"NavServicesAvailable", (PyCFunction
)nav_NavServicesAvailable
, METH_VARARGS
, nav_NavServicesAvailable__doc__
},
878 {"NavLoad", (PyCFunction
)nav_NavLoad
, METH_VARARGS
, nav_NavLoad__doc__
},
879 {"NavUnload", (PyCFunction
)nav_NavUnload
, METH_VARARGS
, nav_NavUnload__doc__
},
880 {"NavLibraryVersion", (PyCFunction
)nav_NavLibraryVersion
, METH_VARARGS
, nav_NavLibraryVersion__doc__
},
881 {"NavGetDefaultDialogOptions", (PyCFunction
)nav_NavGetDefaultDialogOptions
, METH_VARARGS
, nav_NavGetDefaultDialogOptions__doc__
},
882 {NULL
, (PyCFunction
)NULL
, 0, NULL
} /* sentinel */
886 /* Initialization function for the module (*must* be called initNav) */
888 static char Nav_module_documentation
[] =
889 "Interface to Navigation Services\n"
890 "Most calls accept a NavDialogOptions dictionary or keywords with the same names, pass {}\n"
891 "if you want the default options.\n"
892 "Use NavGetDefaultDialogOptions() to find out common option names.\n"
893 "See individual docstrings for additional keyword args/dictentries supported by each call.\n"
894 "Pass None as eventProc to get movable-modal dialogs that process updates through the standard Python mechanism."
902 /* Test that we have NavServices */
903 if ( !NavServicesAvailable() ) {
904 PyErr_SetString(PyExc_ImportError
, "Navigation Services not available");
907 /* Create the module and add the functions */
908 m
= Py_InitModule4("Nav", nav_methods
,
909 Nav_module_documentation
,
910 (PyObject
*)NULL
,PYTHON_API_VERSION
);
912 /* Add some symbolic constants to the module */
913 d
= PyModule_GetDict(m
);
914 ErrorObject
= PyString_FromString("Nav.error");
915 PyDict_SetItemString(d
, "error", ErrorObject
);
917 /* XXXX Add constants here */
920 my_eventProcUPP
= NewNavEventUPP(my_eventProc
);
921 my_previewProcUPP
= NewNavPreviewUPP(my_previewProc
);
922 my_filterProcUPP
= NewNavObjectFilterUPP(my_filterProc
);