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