forked from frizinak/gphoto2go
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ex_camera_widget.go
114 lines (97 loc) · 2.46 KB
/
ex_camera_widget.go
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
package gphoto2
import "time"
type WalkWidgetsFunc func(depth int, parent, widget *CameraWidget) error
func (w *CameraWidget) Walk(fn WalkWidgetsFunc, autodispose bool) error {
if pw, err := w.Parent(); err != nil {
return err
} else {
if autodispose {
//defer pw.Close()
}
if err := w.walk(0, fn, pw, func() (*CameraWidget, error) {
return w, nil
}, autodispose); err != nil {
return err
} else {
return nil
}
}
}
func (w *CameraWidget) walk(depth int, walkFn WalkWidgetsFunc, pw *CameraWidget, getFn func() (*CameraWidget, error), autodispose bool) error {
w, err := getFn()
if err != nil {
panic(err)
}
if err := walkFn(depth, pw, w); err != nil {
return err
}
if count, err := w.ChildrenCount(); err != nil {
panic(err)
} else {
for n := 0; n < count; n++ {
if err := w.walk(depth+1, walkFn, w, func() (*CameraWidget, error) {
return w.Child(n)
}, autodispose); err != nil {
return err
}
}
}
return nil
}
func (w *CameraWidget) Value() (interface{}, error) {
_, wvt, err := w.Type()
if err != nil {
return nil, err
}
switch wvt {
case WidgetValueString:
return w.ValueString()
case WidgetValueInt:
return w.ValueInt()
case WidgetValueFloat:
return w.ValueFloat()
case WidgetValueDate:
return w.ValueDate()
case WidgetValueWeird:
return nil, nil
case WidgetValueInvalid:
return nil, nil
default:
return nil, nil
}
}
func (w *CameraWidget) SetValue(val interface{}) error {
panic("not implemented")
_, wvt, err := w.Type()
if err != nil {
return err
}
setString := func() error {
return w.SetValueString("")
}
setInt := func() error {
return w.SetValueInt(0)
}
setFloat := func() error {
return w.SetValueFloat(0)
}
setDate := func() error {
return w.SetValueDate(time.Time{})
}
switch wvt {
case WidgetValueString:
return setString()
case WidgetValueInt:
return setInt()
case WidgetValueFloat:
return setFloat()
case WidgetValueDate:
return setDate()
case WidgetValueWeird:
return nil
case WidgetValueInvalid:
return nil
default:
return nil
}
}