-
Notifications
You must be signed in to change notification settings - Fork 9
/
gphoto2.pyx
1192 lines (949 loc) · 42.5 KB
/
gphoto2.pyx
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
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# gphoto2.pyx - libgphoto2 Python bindings using pyrex
# Copyright (C) 2003-2004 David PHAM-VAN -- [email protected]
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#------------------------------------------------------------------------------
cdef extern from "Python.h":
object PyString_FromStringAndSize(char *, int)
#------------------------------------------------------------------------------
cdef extern from "stdlib.h":
void free(void *)
#------------------------------------------------------------------------------
cdef extern from "time.h":
ctypedef struct time_t:
int a
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-port-version.h":
ctypedef enum GPVersionVerbosity:
GP_VERSION_SHORT
GP_VERSION_VERBOSE
char **gp_port_library_version(GPVersionVerbosity verbose)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-version.h":
char **gp_library_version(GPVersionVerbosity verbose)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-context.h":
ctypedef struct GPContext
GPContext *gp_context_new ()
void gp_context_ref (GPContext *context)
void gp_context_unref (GPContext *context)
ctypedef enum GPContextFeedback:
GP_CONTEXT_FEEDBACK_OK
GP_CONTEXT_FEEDBACK_CANCEL
ctypedef void (* GPContextIdleFunc) (GPContext *context, void *data)
ctypedef void (* GPContextErrorFunc) (GPContext *context, char *format, args, void *data)
ctypedef void (* GPContextStatusFunc) (GPContext *context, char *format, args, void *data)
ctypedef void (* GPContextMessageFunc) (GPContext *context, char *format, args, void *data)
ctypedef GPContextFeedback (* GPContextQuestionFunc) (GPContext *context, char *format, args, void *data)
ctypedef GPContextFeedback (* GPContextCancelFunc) (GPContext *context, void *data)
ctypedef unsigned int (* GPContextProgressStartFunc) (GPContext *context, float target, char *format, args, void *data)
ctypedef void (* GPContextProgressUpdateFunc) (GPContext *context, unsigned int id, float current, void *data)
ctypedef void (* GPContextProgressStopFunc) (GPContext *context, unsigned int id, void *data)
void gp_context_set_idle_func (GPContext *context, GPContextIdleFunc func, void *data)
void gp_context_set_progress_funcs (GPContext *context, GPContextProgressStartFunc start_func, GPContextProgressUpdateFunc update_func,
GPContextProgressStopFunc stop_func, void *data)
void gp_context_set_error_func (GPContext *context, GPContextErrorFunc func, void *data)
void gp_context_set_status_func (GPContext *context, GPContextStatusFunc func, void *data)
void gp_context_set_question_func (GPContext *context, GPContextQuestionFunc func, void *data)
void gp_context_set_cancel_func (GPContext *context, GPContextCancelFunc func, void *data)
void gp_context_set_message_func (GPContext *context, GPContextMessageFunc func, void *data)
void gp_context_idle (GPContext *context)
void gp_context_error (GPContext *context, char *format, ...)
void gp_context_status (GPContext *context, char *format, ...)
void gp_context_message (GPContext *context, char *format, ...)
GPContextFeedback gp_context_question (GPContext *context, char *format, ...)
GPContextFeedback gp_context_cancel (GPContext *context)
unsigned int gp_context_progress_start (GPContext *context, float target, char *format, ...)
void gp_context_progress_update (GPContext *context, unsigned int id, float current)
void gp_context_progress_stop (GPContext *context, unsigned int id)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-port-info-list.h":
ctypedef enum GPPortType:
GP_PORT_NONE
GP_PORT_SERIAL
GP_PORT_USB
ctypedef struct _GPPortInfo:
char foo
ctypedef _GPPortInfo *GPPortInfo
ctypedef struct GPPortInfoList
int gp_port_info_list_new (GPPortInfoList **list)
int gp_port_info_list_free (GPPortInfoList *list)
int gp_port_info_list_append (GPPortInfoList *list, GPPortInfo info)
int gp_port_info_list_load (GPPortInfoList *list)
int gp_port_info_list_count (GPPortInfoList *list)
int gp_port_info_list_lookup_path (GPPortInfoList *list, char *path)
int gp_port_info_list_lookup_name (GPPortInfoList *list, char *name)
int gp_port_info_list_get_info (GPPortInfoList *list, int n, GPPortInfo *info)
int gp_port_info_get_name (GPPortInfo info, char **name)
int gp_port_info_set_name (GPPortInfo info, char *name)
int gp_port_info_get_path (GPPortInfo info, char **path)
int gp_port_info_set_path (GPPortInfo info, char *path)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-port.h":
ctypedef enum GPPortSerialParity:
GP_PORT_SERIAL_PARITY_OFF
GP_PORT_SERIAL_PARITY_EVEN
GP_PORT_SERIAL_PARITY_ODD
ctypedef enum defines_port:
GP_PORT_MAX_BUF_LEN
ctypedef struct GPPortSettingsSerial:
char port[128]
int speed
int bits
GPPortSerialParity parity
int stopbits
ctypedef struct GPPortSettingsUSB:
int inep, outep, intep
int config
int interface
int altsetting
char port[64]
ctypedef union GPPortSettings:
GPPortSettingsSerial serial
GPPortSettingsUSB usb
enum:
GP_PORT_USB_ENDPOINT_IN
GP_PORT_USB_ENDPOINT_OUT
GP_PORT_USB_ENDPOINT_INT
ctypedef struct GPPortPrivateLibrary
ctypedef struct GPPortPrivateCore
ctypedef struct GPPort:
GPPortType type
GPPortSettings settings
GPPortSettings settings_pending
int timeout
GPPortPrivateLibrary *pl
GPPortPrivateCore *pc
int gp_port_new (GPPort **port)
int gp_port_free (GPPort *port)
int gp_port_set_info (GPPort *port, GPPortInfo info)
int gp_port_get_info (GPPort *port, GPPortInfo *info)
int gp_port_open (GPPort *port)
int gp_port_close (GPPort *port)
int gp_port_write (GPPort *port, char *data, int size)
int gp_port_read (GPPort *port, char *data, int size)
int gp_port_check_int (GPPort *port, char *data, int size)
int gp_port_check_int_fast (GPPort *port, char *data, int size)
int gp_port_get_timeout (GPPort *port, int *timeout)
int gp_port_set_timeout (GPPort *port, int timeout)
int gp_port_set_settings (GPPort *port, GPPortSettings settings)
int gp_port_get_settings (GPPort *port, GPPortSettings *settings)
ctypedef enum GPPin:
GP_PIN_RTS
GP_PIN_DTR
GP_PIN_CTS
GP_PIN_DSR
GP_PIN_CD
GP_PIN_RING
ctypedef enum GPLevel:
GP_LEVEL_LOW
GP_LEVEL_HIGH
int gp_port_get_pin (GPPort *port, GPPin pin, GPLevel *level)
int gp_port_set_pin (GPPort *port, GPPin pin, GPLevel level)
int gp_port_send_break (GPPort *port, int duration)
int gp_port_flush (GPPort *port, int direction)
int gp_port_usb_find_device (GPPort *port, int idvendor, int idproduct)
int gp_port_usb_find_device_by_class (GPPort *port, int mainclass, int subclass, int protocol)
int gp_port_usb_clear_halt (GPPort *port, int ep)
int gp_port_usb_msg_write (GPPort *port, int request, int value, int index, char *bytes, int size)
int gp_port_usb_msg_read (GPPort *port, int request, int value, int index, char *bytes, int size)
int gp_port_set_error (GPPort *port, char *format, ...)
char *gp_port_get_error (GPPort *port)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-port-log.h":
ctypedef enum GPLogLevel:
GP_LOG_ERROR
GP_LOG_VERBOSE
GP_LOG_DEBUG
GP_LOG_DATA
ctypedef void *GPLogFunc (GPLogLevel level, char *domain, char *format, args, void *data)
int gp_log_add_func (GPLogLevel level, GPLogFunc func, void *data)
int gp_log_remove_func (int id)
void gp_log (GPLogLevel level, char *domain, char *format, ...)
void gp_logv (GPLogLevel level, char *domain, char *format, args)
void gp_log_data (char *domain, char *data, unsigned int size)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-port-result.h":
ctypedef enum port_result:
GP_OK
GP_ERROR
GP_ERROR_BAD_PARAMETERS
GP_ERROR_NO_MEMORY
GP_ERROR_LIBRARY
GP_ERROR_UNKNOWN_PORT
GP_ERROR_NOT_SUPPORTED
GP_ERROR_IO
GP_ERROR_TIMEOUT
GP_ERROR_IO_SUPPORTED_SERIAL
GP_ERROR_IO_SUPPORTED_USB
GP_ERROR_IO_INIT
GP_ERROR_IO_READ
GP_ERROR_IO_WRITE
GP_ERROR_IO_UPDATE
GP_ERROR_IO_SERIAL_SPEED
GP_ERROR_IO_USB_CLEAR_HALT
GP_ERROR_IO_USB_FIND
GP_ERROR_IO_USB_CLAIM
GP_ERROR_IO_LOCK
char *gp_port_result_as_string (int result)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-port-result.h":
ctypedef enum gphoto2_result:
GP_ERROR_CORRUPTED_DATA
GP_ERROR_FILE_EXISTS
GP_ERROR_MODEL_NOT_FOUND
GP_ERROR_DIRECTORY_NOT_FOUND
GP_ERROR_FILE_NOT_FOUND
GP_ERROR_DIRECTORY_EXISTS
GP_ERROR_CAMERA_BUSY
GP_ERROR_PATH_NOT_ABSOLUTE
GP_ERROR_CANCEL
char *gp_result_as_string(int result)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-widget.h":
ctypedef struct CameraWidget
ctypedef enum CameraWidgetType:
GP_WIDGET_WINDOW
GP_WIDGET_SECTION
GP_WIDGET_TEXT
GP_WIDGET_RANGE
GP_WIDGET_TOGGLE
GP_WIDGET_RADIO
GP_WIDGET_MENU
GP_WIDGET_BUTTON
GP_WIDGET_DATE
ctypedef int (* CameraWidgetCallback) (Camera, CameraWidget, GPContext)
int gp_widget_new (CameraWidgetType _type, char *label, CameraWidget **widget)
int gp_widget_free (CameraWidget *widget)
int gp_widget_ref (CameraWidget *widget)
int gp_widget_unref (CameraWidget *widget)
int gp_widget_append (CameraWidget *widget, CameraWidget *child)
int gp_widget_prepend (CameraWidget *widget, CameraWidget *child)
int gp_widget_count_children (CameraWidget *widget)
int gp_widget_get_child (CameraWidget *widget, int child_number,
CameraWidget **child)
int gp_widget_get_child_by_label (CameraWidget *widget, char *label,
CameraWidget **child)
int gp_widget_get_child_by_id (CameraWidget *widget, int id, CameraWidget **child)
int gp_widget_get_child_by_name (CameraWidget *widget, char *name, CameraWidget **child)
int gp_widget_get_root (CameraWidget *widget, CameraWidget **root)
int gp_widget_get_parent (CameraWidget *widget, CameraWidget **parent)
int gp_widget_set_value (CameraWidget *widget, void *value)
int gp_widget_get_value (CameraWidget *widget, void *value)
int gp_widget_set_name (CameraWidget *widget, char *name)
int gp_widget_get_name (CameraWidget *widget, char **name)
int gp_widget_set_info (CameraWidget *widget, char *info)
int gp_widget_get_info (CameraWidget *widget, char **info)
int gp_widget_get_id (CameraWidget *widget, int *id)
int gp_widget_get_type (CameraWidget *widget, CameraWidgetType *type)
int gp_widget_get_label (CameraWidget *widget, char **label)
int gp_widget_set_range (CameraWidget *range, float low, float high, float increment)
int gp_widget_get_range (CameraWidget *range, float *min, float *max, float *increment)
int gp_widget_add_choice (CameraWidget *widget, char *choice)
int gp_widget_count_choices (CameraWidget *widget)
int gp_widget_get_choice (CameraWidget *widget, int choice_number, char **choice)
int gp_widget_changed (CameraWidget *widget)
int gp_widget_set_changed (CameraWidget *widget, int changed)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-file.h":
ctypedef enum defines_file:
GP_MIME_WAV
GP_MIME_RAW
GP_MIME_PNG
GP_MIME_PGM
GP_MIME_PPM
GP_MIME_PNM
GP_MIME_JPEG
GP_MIME_TIFF
GP_MIME_BMP
GP_MIME_QUICKTIME
GP_MIME_AVI
GP_MIME_CRW
GP_MIME_UNKNOWN
GP_MIME_EXIF
ctypedef enum CameraFileType:
GP_FILE_TYPE_PREVIEW
GP_FILE_TYPE_NORMAL
GP_FILE_TYPE_RAW
GP_FILE_TYPE_AUDIO
GP_FILE_TYPE_EXIF
ctypedef struct CameraFile
int gp_file_new (CameraFile **file)
int gp_file_ref (CameraFile *file)
int gp_file_unref (CameraFile *file)
int gp_file_free (CameraFile *file)
int gp_file_open (CameraFile *file, char *filename)
int gp_file_save (CameraFile *file, char *filename)
int gp_file_clean (CameraFile *file)
int gp_file_copy (CameraFile *destination, CameraFile *source)
int gp_file_set_name (CameraFile *file, char *name)
int gp_file_get_name (CameraFile *file, char **name)
int gp_file_set_mime_type (CameraFile *file, char *mime_type)
int gp_file_get_mime_type (CameraFile *file, char **mime_type)
int gp_file_set_type (CameraFile *file, CameraFileType type)
int gp_file_get_type (CameraFile *file, CameraFileType *type)
int gp_file_set_mtime (CameraFile *file, mtime)
int gp_file_get_mtime (CameraFile *file, mtime)
int gp_file_detect_mime_type (CameraFile *file)
int gp_file_adjust_name_for_mime_type (CameraFile *file)
int gp_file_append (CameraFile*, char *data, unsigned long int size)
int gp_file_set_data_and_size (CameraFile*, char *data, unsigned long int size)
int gp_file_get_data_and_size (CameraFile*, char **data, unsigned long int *size)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-list.h":
ctypedef enum defines_list:
MAX_ENTRIES
cdef struct s_entry:
char name[128]
char value[128]
ctypedef struct CameraList:
int count
s_entry entry[1024]
int ref_count
int gp_list_new (CameraList **list)
int gp_list_ref (CameraList *list)
int gp_list_unref (CameraList *list)
int gp_list_free (CameraList *list)
int gp_list_count (CameraList *list)
int gp_list_append (CameraList *list, char *name, char *value)
int gp_list_reset (CameraList *list)
int gp_list_sort (CameraList *list)
int gp_list_get_name (CameraList *list, int index, char **name)
int gp_list_get_value (CameraList *list, int index, char **value)
int gp_list_set_name (CameraList *list, int index, char *name)
int gp_list_set_value (CameraList *list, int index, char *value)
int gp_list_populate (CameraList *list, char *format, int count)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-filesys.h":
ctypedef enum CameraFileInfoFields:
GP_FILE_INFO_NONE
GP_FILE_INFO_TYPE
GP_FILE_INFO_NAME
GP_FILE_INFO_SIZE
GP_FILE_INFO_WIDTH
GP_FILE_INFO_HEIGHT
GP_FILE_INFO_PERMISSIONS
GP_FILE_INFO_STATUS
GP_FILE_INFO_MTIME
GP_FILE_INFO_ALL
ctypedef enum CameraFilePermissions:
GP_FILE_PERM_NONE
GP_FILE_PERM_READ
GP_FILE_PERM_DELETE
GP_FILE_PERM_ALL
ctypedef enum CameraFileStatus:
GP_FILE_STATUS_NOT_DOWNLOADED
GP_FILE_STATUS_DOWNLOADED
ctypedef struct CameraFileInfoFile:
CameraFileInfoFields fields
CameraFileStatus status
unsigned long size
char type[64]
unsigned int width, height
char name[64]
CameraFilePermissions permissions
time_t mtime
ctypedef struct CameraFileInfoPreview:
CameraFileInfoFields fields
CameraFileStatus status
unsigned long size
char type[64]
unsigned int width, height
ctypedef struct CameraFileInfoAudio:
CameraFileInfoFields fields
CameraFileStatus status
unsigned long size
char type[64]
ctypedef struct CameraFileInfo:
CameraFileInfoPreview preview
CameraFileInfoFile file
CameraFileInfoAudio audio
ctypedef struct CameraFilesystem
int gp_filesystem_new (CameraFilesystem **fs)
int gp_filesystem_free (CameraFilesystem *fs)
int gp_filesystem_append (CameraFilesystem *fs, char *folder, char *filename, GPContext *context)
int gp_filesystem_set_info_noop (CameraFilesystem *fs, char *folder, CameraFileInfo info, GPContext *context)
int gp_filesystem_set_file_noop (CameraFilesystem *fs, char *folder, CameraFile *file, GPContext *context)
int gp_filesystem_delete_file_noop (CameraFilesystem *fs, char *folder, char *filename, GPContext *context)
int gp_filesystem_reset (CameraFilesystem *fs)
int gp_filesystem_count (CameraFilesystem *fs, char *folder, GPContext *context)
int gp_filesystem_name (CameraFilesystem *fs, char *folder, int filenumber, char **filename, GPContext *context)
int gp_filesystem_get_folder (CameraFilesystem *fs, char *filename, char **folder, GPContext *context)
int gp_filesystem_number (CameraFilesystem *fs, char *folder, char *filename, GPContext *context)
ctypedef int (*CameraFilesystemListFunc) (CameraFilesystem *fs, char *folder, CameraList *list, void *data, GPContext *context)
int gp_filesystem_set_list_funcs (CameraFilesystem *fs, CameraFilesystemListFunc file_list_func, CameraFilesystemListFunc folder_list_func, void *data)
int gp_filesystem_list_files (CameraFilesystem *fs, char *folder, CameraList *list, GPContext *context)
int gp_filesystem_list_folders (CameraFilesystem *fs, char *folder, CameraList *list, GPContext *context)
ctypedef int (*CameraFilesystemSetInfoFunc) (CameraFilesystem *fs, char *folder, char *filename, CameraFileInfo info, void *data, GPContext *context)
ctypedef int (*CameraFilesystemGetInfoFunc) (CameraFilesystem *fs, char *folder, char *filename, CameraFileInfo *info, void *data, GPContext *context)
int gp_filesystem_set_info_funcs (CameraFilesystem *fs, CameraFilesystemGetInfoFunc get_info_func,
CameraFilesystemSetInfoFunc set_info_func,
void *data)
int gp_filesystem_get_info (CameraFilesystem *fs, char *folder,
char *filename, CameraFileInfo *info,
GPContext *context)
int gp_filesystem_set_info (CameraFilesystem *fs, char *folder,
char *filename, CameraFileInfo info,
GPContext *context)
ctypedef int (*CameraFilesystemGetFileFunc) (CameraFilesystem *fs,
char *folder,
char *filename,
CameraFileType type,
CameraFile *file, void *data,
GPContext *context)
ctypedef int (*CameraFilesystemDeleteFileFunc) (CameraFilesystem *fs,
char *folder,
char *filename,
void *data, GPContext *context)
int gp_filesystem_set_file_funcs (CameraFilesystem *fs,
CameraFilesystemGetFileFunc get_file_func,
CameraFilesystemDeleteFileFunc del_file_func,
void *data)
int gp_filesystem_get_file (CameraFilesystem *fs, char *folder,
char *filename, CameraFileType type,
CameraFile *file, GPContext *context)
int gp_filesystem_delete_file (CameraFilesystem *fs, char *folder,
char *filename, GPContext *context)
ctypedef int (*CameraFilesystemPutFileFunc) (CameraFilesystem *fs,
char *folder,
CameraFile *file, void *data,
GPContext *context)
ctypedef int (*CameraFilesystemDeleteAllFunc) (CameraFilesystem *fs,
char *folder, void *data,
GPContext *context)
ctypedef int (*CameraFilesystemDirFunc) (CameraFilesystem *fs,
char *folder,
char *name, void *data,
GPContext *context)
int gp_filesystem_set_folder_funcs (CameraFilesystem *fs,
CameraFilesystemPutFileFunc put_file_func,
CameraFilesystemDeleteAllFunc delete_all_func,
CameraFilesystemDirFunc make_dir_func,
CameraFilesystemDirFunc remove_dir_func,
void *data)
int gp_filesystem_put_file (CameraFilesystem *fs, char *folder,
CameraFile *file, GPContext *context)
int gp_filesystem_delete_all (CameraFilesystem *fs, char *folder,
GPContext *context)
int gp_filesystem_make_dir (CameraFilesystem *fs, char *folder,
char *name, GPContext *context)
int gp_filesystem_remove_dir (CameraFilesystem *fs, char *folder,
char *name, GPContext *context)
int gp_filesystem_dump (CameraFilesystem *fs)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-abilities-list.h":
ctypedef enum CameraDriverStatus:
GP_DRIVER_STATUS_PRODUCTION
GP_DRIVER_STATUS_TESTING
GP_DRIVER_STATUS_EXPERIMENTAL
GP_DRIVER_STATUS_DEPRECATED
ctypedef enum CameraOperation:
GP_OPERATION_NONE
GP_OPERATION_CAPTURE_IMAGE
GP_OPERATION_CAPTURE_VIDEO
GP_OPERATION_CAPTURE_AUDIO
GP_OPERATION_CAPTURE_PREVIEW
GP_OPERATION_CONFIG
ctypedef enum CameraFileOperation:
GP_FILE_OPERATION_NONE
GP_FILE_OPERATION_DELETE
GP_FILE_OPERATION_PREVIEW
GP_FILE_OPERATION_RAW
GP_FILE_OPERATION_AUDIO
GP_FILE_OPERATION_EXIF
ctypedef enum CameraFolderOperation:
GP_FOLDER_OPERATION_NONE
GP_FOLDER_OPERATION_DELETE_ALL
GP_FOLDER_OPERATION_PUT_FILE
GP_FOLDER_OPERATION_MAKE_DIR
GP_FOLDER_OPERATION_REMOVE_DIR
ctypedef struct CameraAbilities:
char model [128]
CameraDriverStatus status
GPPortType port
int speed [64]
CameraOperation operations
CameraFileOperation file_operations
CameraFolderOperation folder_operations
int usb_vendor, usb_product
int usb_class, usb_subclass, usb_protocol
char library [1024]
char id [1024]
int reserved1
int reserved2
int reserved3
int reserved4
int reserved5
int reserved6
int reserved7
int reserved8
ctypedef struct CameraAbilitiesList
int gp_abilities_list_new (CameraAbilitiesList **list)
int gp_abilities_list_free (CameraAbilitiesList *list)
int gp_abilities_list_load (CameraAbilitiesList *list, GPContext *context)
int gp_abilities_list_reset (CameraAbilitiesList *list)
int gp_abilities_list_detect (CameraAbilitiesList *list, GPPortInfoList *info_list, CameraList *l, GPContext *context)
int gp_abilities_list_append (CameraAbilitiesList *list, CameraAbilities abilities)
int gp_abilities_list_count (CameraAbilitiesList *list)
int gp_abilities_list_lookup_model (CameraAbilitiesList *list, char *model)
int gp_abilities_list_get_abilities (CameraAbilitiesList *list, int index, CameraAbilities *abilities)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-camera.h":
#include <gphoto2/gphoto2-context.h>
ctypedef struct Camera
#include <gphoto2/gphoto2-port.h>
#include <gphoto2/gphoto2-port-info-list.h>
#include <gphoto2/gphoto2-widget.h>
#include <gphoto2/gphoto2-list.h>
#include <gphoto2/gphoto2-file.h>
#include <gphoto2/gphoto2-filesys.h>
#include <gphoto2/gphoto2-abilities-list.h>
#include <gphoto2/gphoto2-result.h>
#include <gphoto2/gphoto2-context.h>
ctypedef struct CameraText:
char text [32 * 1024]
ctypedef struct CameraFilePath:
char name [128]
char folder [1024]
ctypedef enum CameraCaptureType:
GP_CAPTURE_IMAGE
GP_CAPTURE_MOVIE
GP_CAPTURE_SOUND
ctypedef enum CameraEventType:
GP_EVENT_UNKNOWN # unknown and unhandled event
GP_EVENT_TIMEOUT # timeout, no arguments
GP_EVENT_FILE_ADDED # CameraFilePath = file in camfs
GP_EVENT_FOLDER_ADDED # CameraFilePath = folder in camfs
ctypedef int (*CameraExitFunc) (Camera *camera, GPContext *context)
ctypedef int (*CameraGetConfigFunc) (Camera *camera, CameraWidget **widget, GPContext *context)
ctypedef int (*CameraSetConfigFunc) (Camera *camera, CameraWidget *widget, GPContext *context)
ctypedef int (*CameraCaptureFunc) (Camera *camera, CameraCaptureType type, CameraFilePath *path, GPContext *context)
ctypedef int (*CameraCapturePreviewFunc) (Camera *camera, CameraFile *file, GPContext *context)
ctypedef int (*CameraSummaryFunc) (Camera *camera, CameraText *text,
GPContext *context)
ctypedef int (*CameraManualFunc) (Camera *camera, CameraText *text,
GPContext *context)
ctypedef int (*CameraAboutFunc) (Camera *camera, CameraText *text,
GPContext *context)
ctypedef int (*CameraPrePostFunc) (Camera *camera, GPContext *context)
ctypedef struct CameraFunctions:
CameraPrePostFunc pre_func
CameraPrePostFunc post_func
CameraExitFunc exit
CameraGetConfigFunc get_config
CameraSetConfigFunc set_config
CameraCaptureFunc capture
CameraCapturePreviewFunc capture_preview
CameraSummaryFunc summary
CameraManualFunc manual
CameraAboutFunc about
void *reserved1
void *reserved2
void *reserved3
void *reserved4
void *reserved5
void *reserved6
void *reserved7
void *reserved8
ctypedef GPPort CameraPort
ctypedef GPPortInfo CameraPortInfo
ctypedef struct CameraPrivateLibrary
ctypedef struct CameraPrivateCore
cdef struct _Camera:
GPPort *port
CameraFilesystem *fs
CameraFunctions *functions
CameraPrivateLibrary *pl
CameraPrivateCore *pc
int gp_camera_new (Camera **camera)
int gp_camera_set_abilities (Camera *camera, CameraAbilities abilities)
int gp_camera_get_abilities (Camera *camera, CameraAbilities *abilities)
int gp_camera_set_port_info (Camera *camera, GPPortInfo info)
int gp_camera_get_port_info (Camera *camera, GPPortInfo *info)
int gp_camera_set_port_speed (Camera *camera, int speed)
int gp_camera_get_port_speed (Camera *camera)
int gp_camera_init (Camera *camera, GPContext *context)
int gp_camera_exit (Camera *camera, GPContext *context)
int gp_camera_ref (Camera *camera)
int gp_camera_unref (Camera *camera)
int gp_camera_free (Camera *camera)
int gp_camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
int gp_camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
int gp_camera_get_summary (Camera *camera, CameraText *summary, GPContext *context)
int gp_camera_get_manual (Camera *camera, CameraText *manual, GPContext *context)
int gp_camera_get_about (Camera *camera, CameraText *about, GPContext *context)
int gp_camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path, GPContext *context)
int gp_camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
int gp_camera_wait_for_event (Camera *camera, int timeout, CameraEventType *eventtype, void **eventdata, GPContext *context)
int gp_camera_folder_list_files (Camera *camera, char *folder, CameraList *list, GPContext *context)
int gp_camera_folder_list_folders (Camera *camera, char *folder, CameraList *list, GPContext *context)
int gp_camera_folder_delete_all (Camera *camera, char *folder, GPContext *context)
int gp_camera_folder_put_file (Camera *camera, char *folder, char *name, CameraFileType type, CameraFile *file, GPContext *context)
int gp_camera_folder_make_dir (Camera *camera, char *folder, char *name, GPContext *context)
int gp_camera_folder_remove_dir (Camera *camera, char *folder, char *name, GPContext *context)
int gp_camera_file_get_info (Camera *camera, char *folder, char *file, CameraFileInfo *info, GPContext *context)
int gp_camera_file_set_info (Camera *camera, char *folder, char *file, CameraFileInfo info, GPContext *context)
int gp_camera_file_get (Camera *camera, char *folder, char *file, CameraFileType type, CameraFile *camera_file, GPContext *context)
int gp_camera_file_delete (Camera *camera, char *folder, char *file, GPContext *context)
ctypedef int (* CameraTimeoutFunc) (Camera *camera, GPContext *context)
ctypedef unsigned int (* CameraTimeoutStartFunc) (Camera *camera, unsigned int timeout, CameraTimeoutFunc func, void *data)
ctypedef void (* CameraTimeoutStopFunc) (Camera *camera, unsigned int id, void *data)
void gp_camera_set_timeout_funcs (Camera *camera, CameraTimeoutStartFunc start_func, CameraTimeoutStopFunc stop_func, void *data)
int gp_camera_start_timeout (Camera *camera, unsigned int timeout, CameraTimeoutFunc func)
void gp_camera_stop_timeout (Camera *camera, unsigned int id)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-library.h":
ctypedef int (* CameraLibraryIdFunc) (CameraText *id)
ctypedef int (* CameraLibraryAbilitiesFunc) (CameraAbilitiesList *list)
ctypedef int (* CameraLibraryInitFunc) (Camera *camera, GPContext *context)
int camera_id (CameraText *id)
int camera_abilities (CameraAbilitiesList *list)
int camera_init (Camera *camera, GPContext *context)
#------------------------------------------------------------------------------
cdef extern from "gphoto2/gphoto2-setting.h":
int gp_setting_set (char *id, char *key, char *value)
int gp_setting_get (char *id, char *key, char *value)
#------------------------------------------------------------------------------
def library_version(verbose):
cdef char **arrText
cdef int i
retval = []
if verbose==False:
arrText=gp_library_version(GP_VERSION_SHORT)
else:
arrText=gp_library_version(GP_VERSION_VERBOSE)
i = 0
while arrText[i] != NULL:
retval.append(arrText[i])
i=i+1
return retval
cdef check(result):
if result!=0:
txt=gp_result_as_string(result)
raise Exception('Error ('+str(result)+') : '+txt)
cdef check_unref(int result,CameraFile *file):
if result!=0:
gp_file_unref(file)
txt=gp_result_as_string(result)
raise Exception('Error ('+str(result)+') : '+txt)
cdef class portInfo:
cdef GPPortInfo info
def __repr__(self):
cdef char* path
cdef char* name
gp_port_info_get_path (self.info,&path)
gp_port_info_get_name (self.info,&name)
if len(path):
return "%s: %s" % (name, path)
else:
return name
cdef class ports:
cdef GPPortInfoList *portInfoList
# FIXME: Check proper use of __cinit__ (was __new__ originally)
def __cinit__(self):
check(gp_port_info_list_new(&self.portInfoList))
def __dealloc__(self):
check(gp_port_info_list_free(self.portInfoList))
def load(self):
check(gp_port_info_list_load(self.portInfoList))
def count(self):
return gp_port_info_list_count(self.portInfoList)
def __getitem__(self, num):
cdef portInfo info
info=portInfo()
check(gp_port_info_list_get_info(self.portInfoList, num, &info.info))
return info
cdef class cameraList:
cdef CameraList *liste
def __cinit__(self):
check(gp_list_new(&self.liste))
def __dealloc__(self):
check(gp_list_free(self.liste))
def count(self):
return gp_list_count(self.liste)
def __getitem__(self, index):
cdef char *name
cdef char *value
check(gp_list_get_name(self.liste, index, &name))
check(gp_list_get_value(self.liste, index, &value))
return (name, value)
cdef class cameraWidget:
cdef CameraWidget *widget
def __cinit__(self):
self.widget = NULL;
def __dealloc__(self):
if self.widget != NULL:
check(gp_widget_unref(self.widget))
def __repr__(self):
if self.widget == NULL:
return "<null>"
return "%s:%s:%s:%s" % (self.label, self.name, self.info, str(self.value))
def new(self, wtype, char *name):
if self.widget != NULL:
check(gp_widget_unref(self.widget))
check(gp_widget_new(wtype, name, &self.widget))
check(gp_widget_ref(self.widget))
def count(self):
self._check()
return gp_widget_count_children(self.widget)
def get_child_by_name(self, char *name):
cdef cameraWidget widget
self._check()
widget = cameraWidget()
check(gp_widget_get_child_by_name(self.widget, name, &widget.widget))
check(gp_widget_ref(widget.widget))
return widget
def get_child_by_label(self, char *label):
cdef cameraWidget widget
self._check()
widget = cameraWidget()
check(gp_widget_get_child_by_label(self.widget, label, &widget.widget))
check(gp_widget_ref(widget.widget))
return widget
def _check(self):
if not self.widget:
raise Exception('Uninitialized cameraWidget')
def __len__(self):
return self.count()
def __getitem__(self, num):
cdef cameraWidget widget
widget = cameraWidget()
check(gp_widget_get_child(self.widget, num, &widget.widget))
check(gp_widget_ref(widget.widget))
return widget
property value:
def __get__(self):
cdef CameraWidgetType wtype
cdef char *type_string
cdef float type_float
cdef int type_int
if self.widget == NULL:
return None
check(gp_widget_get_type(self.widget, &wtype))
if wtype == GP_WIDGET_MENU or \
wtype == GP_WIDGET_RADIO or \
wtype == GP_WIDGET_TEXT:
check(gp_widget_get_value(self.widget, &type_string))
return type_string
if wtype == GP_WIDGET_RANGE:
check(gp_widget_get_value(self.widget, &type_float))
return type_float
if wtype == GP_WIDGET_TOGGLE or wtype == GP_WIDGET_DATE:
check(gp_widget_get_value(self.widget, &type_int))
return type_int
return None
def __set__(self, value):
cdef CameraWidgetType wtype
cdef char *type_string
cdef float type_float
cdef int type_int
if self.widget == NULL:
return
check(gp_widget_get_type(self.widget, &wtype))
if wtype == GP_WIDGET_MENU or \
wtype == GP_WIDGET_RADIO or \
wtype == GP_WIDGET_TEXT:
strval = str(value)
type_string = strval
check(gp_widget_set_value(self.widget, type_string))
if wtype == GP_WIDGET_RANGE:
type_float = float(value)
check(gp_widget_set_value(self.widget, &type_float))
if wtype == GP_WIDGET_TOGGLE or wtype == GP_WIDGET_DATE:
type_int = int(value)
check(gp_widget_set_value(self.widget, &type_int))
property label:
def __get__(self):
cdef char *label
if self.widget == NULL:
return None
check(gp_widget_get_label(self.widget, &label))
return label
property name:
def __get__(self):
cdef char *name
if self.widget == NULL:
return None
check(gp_widget_get_name(self.widget, &name))
return name
property info:
def __get__(self):
cdef char *info
if self.widget == NULL:
return None
check(gp_widget_get_info(self.widget, &info))
return info
property changed:
def __get__(self):
self._check()
return gp_widget_changed(self.widget)
property parent:
def __get__(self):
self._check()
cdef cameraWidget widget
check(gp_widget_get_parent(self.widget, &widget.widget))
if widget.widget == NULL:
return None