1 """
2 Flash embedding Panel
3
4 @license: Apache License Version 2.0
5 @copyright: 2009 Tobias Weber
6 @author: Tobias Weber
7 @contact: tobi-weber@gmx.de
8 """
9
10 from pyjamas import DOM
11 from pyjamas.ui.Panel import Panel
12 from pyjamas import log
13 from __pyjamas__ import wnd
14 import sys
15 if sys.platform in ['mozilla', 'ie6', 'opera', 'oldmoz', 'safari']:
16 from __javascript__ import Array, Object, eval
17
20
22
24 element = DOM.createDiv()
25 self.setElement(element)
26 Panel.__init__(self, **kwargs)
27
28 self.object_id = 'FlashObject'
29 """ id of the object-tag. Default: FlashObject """
30 self.object_class = None
31 """ The class-name of the object-tag. Default: None"""
32 self.object_width = None
33 """ The width-parameter of the object-tag. Default: None"""
34 self.object_height = None
35 """ The height-parameter of the object-tag. Default: None"""
36 self.flash_url = None
37 """ The Flash-Movie url. Default: None"""
38 self.wmode = None
39 """ The flashmovie wmode parameter. Default: None"""
40 self.quality = 'high'
41 """ The flashmovie quality parameter. Default: high"""
42 self.menu = None
43 """ The flashmovie wmode parameter. Default: None"""
44 self.allowScriptAccess = 'always'
45 """ The flashmovie allowscriptaccess parameter. Default: always"""
46 self.allowFullscreen = 'false'
47 """ The flashmovie allowfullscreen parameter. Default: False"""
48 self.bgColor = '#FFFFFF'
49 """ The flashmovie bgcolor parameter. Default: #FFFFFF (white)"""
50 self.flashvars = ''
51 self.browser = browser()
52
53
56
58 """
59 @return: id of the object-tag
60 """
61 return self.object_id
62
64 """
65 @param object_id: The id of the object-tag
66 """
67 self.object_id = object_id
68
70 """
71 @return: class-name of the object-tag
72 """
73 return self.object_class
74
76 """
77 @param object_class: The class-name of the object-tag
78 """
79 self.object_class = object_class
80
82 """
83 @return: width parameter of the object-tag
84 """
85 return self.object_width
86
88 """
89 @param object_class: The width parameter of the object-tag
90 """
91 self.object_width = str(width)
92
94 """
95 @return: height parameter of the object-tag
96 """
97 return self.object_height
98
100 """
101 @param object_class: The height parameter of the object-tag
102 """
103 self.object_height = str(height)
104
106 """
107 @return: url of the flashmovie
108 """
109 return self.flash_url
110
112 """
113 @param flash_url: The url of the flash_movie
114 """
115 self.flash_url = flash_url
116
118 """
119 @return: flash parameter wmode
120 """
121 return self.wmode
122
124 """
125 @param wmode: The flash parameter wmode
126 """
127 self.wmode = wmode
128
130 """
131 @return: flash parameter quality
132 """
133 return self.quality
134
136 """
137 @param quality: The flash parameter quality
138 """
139 self.quality = quality
140
142 """
143 @return: flash parameter menu
144 """
145 if self.menu == 'true':
146 return True
147 else:
148 return False
149
151 """
152 @param menu: The flash parameter menu
153 """
154 if menu:
155 self.menu = 'true'
156 else:
157 self.menu = 'false'
158
160 """
161 @return: flash parameter allowfullscreen
162 """
163 if self.allowFullscreen == 'true':
164 return True
165 else:
166 return False
167
169 """
170 @param allowFullscreen: The flash parameter allowfullscreen
171 """
172 if allowFullscreen:
173 self.allowFullscreen = 'true'
174 else:
175 self.allowFullscreen = 'false'
176
178 """
179 @return: flash parameter bgcolor
180 """
181 return self.bgColor
182
184 """
185 @param bgcolor: The flash parameter bgcolor
186 """
187 self.bgColor = bgcolor
188
190 """
191 @return: flash parameter flashvars
192 """
193 return self.flashvars
194
196 """
197 @param flashvars: The flash parameter flashvars
198 """
199 self.flashvars = flashvars
200
202 object = 'id="'+self.object_id+'"'
203 if self.object_width:
204 object += ' width="'+self.object_width+'"'
205 if self.object_height:
206 object += ' height="'+self.object_height+'"'
207 if self.object_class:
208 object += ' class="'+self.object_class+'"'
209 if self.browser == 'ie':
210 object += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
211 else:
212 object += ' type="application/x-shockwave-flash"'
213 object += ' data="'+self.flash_url+'"'
214 html = ['<object %s>' % object]
215 if self.flash_url:
216 html.append('<param name="movie" value="'+self.flash_url+'" />')
217 if self.quality:
218 html.append('<param name="quality" value="'+self.quality+'" />')
219 if self.allowScriptAccess != None:
220 html.append('<param name="allowscriptaccess" value="'+self.allowScriptAccess+'" />')
221 if self.allowFullscreen != None:
222 html.append('<param name="allowfullscreen" value="'+self.allowFullscreen+'" />')
223 if self.bgColor:
224 html.append('<param name="bgcolor" value="'+self.bgColor+'"/>')
225 if self.wmode != None:
226 html.append('<param name="wmode" value="'+self.wmode+'" />')
227 if self.menu != None:
228 html.append('<param name="menu" value="'+self.menu+'" />')
229 html.append('<param name="flashvars" value="'+self.getFlashVars()+'" />')
230
231 html.append("""
232 <div class="noflash">
233 <h3>You have no flash plugin installed</h3>
234 <p>Click here to download latest version</p>
235 <p>Download latest version from <a href='http://www.adobe.com/go/getflashplayer'>here</a></p>
236 </div>
237 """)
238 html.append('</object>')
239
240 flashvars = ''.join(html)
241 return flashvars
242
249
250 - def callFlash(self, functionName, arguments=[]):
251 """
252 @param functionName: Methodname of ExternalInterface
253 @param arguments: List with arguments of ExternalInterfaces method
254
255 @return: return value of ExternalInterfaces method
256 """
257 raise NotImplemented("calling of javascript and conversion of javascript parameters is required")
258
259 - def toJS(self, list_or_dict):
260 """
261 @param list_or_dict: A List or a Dictonary
262
263 Converting recrusive Dictonarys and Lists to Javascript Types.
264
265 @return: javascript array or object
266 """
267 raise NotImplemented("conversion of javascript parameters is required")
268
270 """
271 @return: result of flashs build in function __flash__argumentsToXML
272 """
273 arguments = self.toJS(arguments)
274 return wnd().__flash__argumentsToXML(arguments, num);
275