1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from __pyjamas__ import JS
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
36 JS("""
37 //console['log']("translateGmapsObject " + fieldNameXXX+"("+pyToJs+")")
38
39 if (! (@{{fieldName}} in @{{fields}}))
40 {
41 //console['log']("nothing")
42 return @{{obj}};
43 }
44 else{
45 @{{action}} = @{{fields}}[@{{fieldName}}]
46 //console['log']("action=" + action)
47
48 if (@{{action}} == 'd')
49 {
50 //console['log']("is dict")
51 // this newobj can be used in js and also in python,
52 // like this "newobj['field']"
53 var newobj = {}
54 for (var i in @{{obj}})
55 // vai ficar disponivel como uma propriedade, no python!
56 newobj[i] = $m['translateGmapsObject'](@{{obj}}[i], i, @{{fields}}, @{{pyToJs}});
57 return newobj
58
59 }
60 else if (@{{action}} == 'l')
61 {
62 if (@{{pyToJs}}) {
63 var newobj = $m['listToJs'](@{{obj}})
64 //console['log']("is list py->js")
65 for (var i in newobj){
66 newobj[i]=$m['translateGmapsObject'](
67 newobj[i], @{{fieldName}} + "[]", @{{fields}},@{{pyToJs}} ) ;
68 }
69 return newobj
70 }else{
71 //console['log']("is list js->py")
72 var newobj = @{{list}}([])
73 for (var i in @{{obj}})
74 newobj['append']($m['translateGmapsObject'](
75 @{{obj}}[i], @{{fieldName}} + "[]", @{{fields}},@{{pyToJs}} ));
76 return newobj
77 }
78 }
79 else
80 {
81 //console['log']("is special")
82 return @{{action}}(@{{obj}})
83 }
84 }
85 """)
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
102 obj = JS("{}")
103 try:
104 for key in dict:
105 value = dict[key]
106 JS("@{{obj}}[@{{key}}] = @{{value}}")
107 except:
108 pass
109
110 return obj
111
112
113
115 obj = JS("[]")
116 for i in list:
117 obj.push(i)
118 return obj
119
120
121
122
123
124
125
126
136
137
139 self = JS("this")
140 print "DUMP"
141 for eventName in self.__listeners:
142 print " " + eventName
143 for list in self.__listeners[eventName]:
144 print " " + str(list)
145
146
148 self = JS("this")
149
150 thelist = JS("""
151 $wnd['google']['maps']['event']['addListener'](this, @{{eventName}}, function(event) {
152 @{{callback}}(event);
153 })
154 """)
155
156
157
158
159 if eventName in self.__listeners:
160 self.__listeners[eventName].append(thelist)
161 else:
162 self.__listeners[eventName] = [thelist]
163
164 return thelist
165
166
168 self = JS("this")
169
170 for eventName in self.__listeners:
171 if list in self.__listeners[eventName]:
172 JS("""$wnd['google']['maps']['event']['removeListener'](@{{list}});""")
173 self.__listeners[eventName].remove(list)
174 return
175
176
177
178
180 self = JS("this")
181
182 JS("""$wnd['google']['maps']['event']['clearListeners'](this, @{{eventName}})""")
183 if eventName in self.__listeners:
184 del self.__listeners[eventName]
185
186
188 self = JS("this")
189
190 JS("""$wnd['google']['maps']['event']['clearInstanceListeners'](this)""")
191 self.__listeners = {}
192