Package library :: Package pyjamas :: Package ui :: Module FlashPanel
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.ui.FlashPanel

  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 wnd 
 13  import pyjd 
 14  if not pyjd.is_desktop: 
 15      from __javascript__ import Array, Object, eval 
 16   
 17  #from pyjamas import logging 
 18  #log = logging.getAppendLogger(__name__, logging.DEBUG, logging.PLAIN_FORMAT) 
 19   
20 -def browser():
21 return 'w3c'
22
23 -class FlashPanel(Panel):
24
25 - def __init__(self, **kwargs):
26 element = DOM.createDiv() 27 self.setElement(element) 28 29 self.object_id = 'FlashObject' 30 """ id of the object-tag. Default: FlashObject """ 31 self.object_class = None 32 """ The class-name of the object-tag. Default: None""" 33 self.object_width = None 34 """ The width-parameter of the object-tag. Default: None""" 35 self.object_height = None 36 """ The height-parameter of the object-tag. Default: None""" 37 self.flash_url = None 38 """ The Flash-Movie url. Default: None""" 39 self.wmode = None #'window' 40 """ The flashmovie wmode parameter. Default: None""" 41 self.quality = 'high' 42 """ The flashmovie quality parameter. Default: high""" 43 self.menu = None # 'false' 44 """ The flashmovie wmode parameter. Default: None""" 45 self.allowScriptAccess = 'always' 46 """ The flashmovie allowscriptaccess parameter. Default: always""" 47 self.allowFullscreen = 'false' 48 """ The flashmovie allowfullscreen parameter. Default: False""" 49 self.bgColor = '#FFFFFF' 50 """ The flashmovie bgcolor parameter. Default: #FFFFFF (white)""" 51 self.flashvars = '' 52 self.browser = browser() 53 #log.debug('FlashPanel loaded on %s' % self.browser) 54 55 Panel.__init__(self, **kwargs)
56
57 - def onLoad(self):
58 DOM.setInnerHTML(self.element, self.__getFlashHTML())
59
60 - def getObjectID(self):
61 """ 62 @return: id of the object-tag 63 """ 64 return self.object_id
65
66 - def setObjectID(self, object_id):
67 """ 68 @param object_id: The id of the object-tag 69 """ 70 self.object_id = object_id
71
72 - def getObjectClass(self):
73 """ 74 @return: class-name of the object-tag 75 """ 76 return self.object_class
77
78 - def setObjectClass(self, object_class):
79 """ 80 @param object_class: The class-name of the object-tag 81 """ 82 self.object_class = object_class
83
84 - def getObjectWidth(self):
85 """ 86 @return: width parameter of the object-tag 87 """ 88 return self.object_width
89
90 - def setObjectWidth(self, width):
91 """ 92 @param width: The width parameter of the object-tag 93 """ 94 self.object_width = str(width)
95
96 - def getObjectHeight(self):
97 """ 98 @return: height parameter of the object-tag 99 """ 100 return self.object_height
101
102 - def setObjectHeight(self, height):
103 """ 104 @param height: The height parameter of the object-tag 105 """ 106 self.object_height = str(height)
107
108 - def getFlashUrl(self):
109 """ 110 @return: url of the flashmovie 111 """ 112 return self.flash_url
113
114 - def setFlashUrl(self, flash_url):
115 """ 116 @param flash_url: The url of the flash_movie 117 """ 118 self.flash_url = flash_url
119
120 - def getWmode(self):
121 """ 122 @return: flash parameter wmode 123 """ 124 return self.wmode
125
126 - def setWmode(self, wmode):
127 """ 128 @param wmode: The flash parameter wmode 129 """ 130 self.wmode = wmode
131
132 - def getQuality(self):
133 """ 134 @return: flash parameter quality 135 """ 136 return self.quality
137
138 - def setQuality(self, quality):
139 """ 140 @param quality: The flash parameter quality 141 """ 142 self.quality = quality
143
144 - def getMenu(self):
145 """ 146 @return: flash parameter menu 147 """ 148 if self.menu == 'true': 149 return True 150 else: 151 return False
152
153 - def setMenu(self, menu):
154 """ 155 @param menu: The flash parameter menu 156 """ 157 if menu: 158 self.menu = 'true' 159 else: 160 self.menu = 'false'
161
162 - def getAllowFullscreen(self):
163 """ 164 @return: flash parameter allowfullscreen 165 """ 166 if self.allowFullscreen == 'true': 167 return True 168 else: 169 return False
170
171 - def setAllowFullscreen(self, allowFullscreen):
172 """ 173 @param allowFullscreen: The flash parameter allowfullscreen 174 """ 175 if allowFullscreen: 176 self.allowFullscreen = 'true' 177 else: 178 self.allowFullscreen = 'false'
179
180 - def getBGColor(self):
181 """ 182 @return: flash parameter bgcolor 183 """ 184 return self.bgColor
185
186 - def setBGColor(self, bgcolor):
187 """ 188 @param bgcolor: The flash parameter bgcolor 189 """ 190 self.bgColor = bgcolor
191
192 - def getFlashVars(self):
193 """ 194 @return: flash parameter flashvars 195 """ 196 return self.flashvars
197
198 - def setFlashVars(self, flashvars):
199 """ 200 @param flashvars: The flash parameter flashvars 201 """ 202 self.flashvars = flashvars
203
204 - def __getFlashHTML(self):
205 obj = 'id="'+self.object_id+'"' 206 if self.object_width: 207 obj += ' width="'+self.object_width+'"' 208 if self.object_height: 209 obj += ' height="'+self.object_height+'"' 210 if self.object_class: 211 obj += ' class="'+self.object_class+'"' 212 if self.browser == 'ie': 213 obj += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' 214 else: 215 obj += ' type="application/x-shockwave-flash"' 216 obj += ' data="'+self.flash_url+'"' 217 html = ['<object %s>' % obj] 218 if self.flash_url: 219 html.append('<param name="movie" value="'+self.flash_url+'" />') 220 if self.quality: 221 html.append('<param name="quality" value="'+self.quality+'" />') 222 if self.allowScriptAccess != None: 223 html.append('<param name="allowscriptaccess" value="'+self.allowScriptAccess+'" />') 224 if self.allowFullscreen != None: 225 html.append('<param name="allowfullscreen" value="'+self.allowFullscreen+'" />') 226 if self.bgColor: 227 html.append('<param name="bgcolor" value="'+self.bgColor+'"/>') 228 if self.wmode != None: 229 html.append('<param name="wmode" value="'+self.wmode+'" />') 230 if self.menu != None: 231 html.append('<param name="menu" value="'+self.menu+'" />') 232 html.append('<param name="flashvars" value="'+self.getFlashVars()+'" />') 233 # If Flash is not installed 234 html.append(""" 235 <div class="noflash"> 236 <h3>You have no flash plugin installed</h3> 237 <p>Click here to download latest version</p> 238 <p>Download latest version from <a href='http://www.adobe.com/go/getflashplayer'>here</a></p> 239 </div> 240 """) 241 html.append('</object>') 242 243 flashvars = ''.join(html) 244 return flashvars
245
246 - def getMovieElement(self):
247 """ 248 @return: element DOM-Object of the object-tag 249 """ 250 element = DOM.getElementById(self.object_id) 251 return element
252
253 - def callFlash(self, functionName, arguments=[]):
254 """ 255 @param functionName: Methodname of ExternalInterface 256 @param arguments: List with arguments of ExternalInterfaces method 257 258 @return: return value of ExternalInterfaces method 259 """ 260 raise NotImplemented("calling of javascript and conversion of javascript parameters is required")
261
262 - def toJS(self, list_or_dict):
263 """ 264 @param list_or_dict: A List or a Dictonary 265 266 Converting recrusive Dictonarys and Lists to Javascript Types. 267 268 @return: javascript array or object 269 """ 270 raise NotImplemented("conversion of javascript parameters is required")
271
272 - def flashArgumentsToXML(self, arguments, num):
273 """ 274 @return: result of flashs build in function __flash__argumentsToXML 275 """ 276 arguments = self.toJS(arguments) 277 return wnd().__flash__argumentsToXML(arguments, num);
278