def onreadystatechange(): if xhtoj.readyState == 4: jsnode = 0 if xhtoj.status == 200: txt = xhtoj.responseText jsnode = None if idname: jsnode = DOM.getElementById(idname) if jsnode is None: jsnode = DOM.createElement('script') #tst = DOM.createElement('html') #tst.innerHTML = str activate_javascript(txt) if not on_load_fn is None: wnd().alert(on_load_fn) # eval(on_load_fn) test_fn() return 1 else: jsnode = DOM.getElementById(idname) if not jsnode is None: jsnode.innerHTML = xhtoj.status
def fireEvent(self, *args): movieName = args[0] eventName = args[1] arguments = [] for i in range(2, len(args)): if args[i] != None: arguments.append(args[i]) wnd().players[args[0]].fireEvent(movieName, eventName, arguments)
def _dispatchEvent(sender, evt, useCap): if evt is None: evt = wnd().event else: try: sender = get_main_frame().gobject_wrap(sender) # webkit HACK! evt = get_main_frame().gobject_wrap(evt) # webkit HACK! except: pass listener = None curElem = sender #print "_dispatchEvent", sender, evt, evt.type cap = getCaptureElement() listener = get_listener(cap) if cap and (listener is not None): #print "capture _dispatchEvent", cap, listener dispatchEvent(evt, cap, listener) evt.stopPropagation() return while curElem and (get_listener(curElem) is None): #print "no parent listener", curElem, getParent(curElem) curElem = getParent(curElem) if curElem and getNodeType(curElem) != 1: curElem = None listener = get_listener(curElem) if listener is not None: dispatchEvent(evt, curElem, listener)
def browser_event_cb(view, event, from_window): global sCaptureElem #print "sCaptureElem", sCaptureElem if event is None: event = wnd().event else: try: event = get_main_frame().gobject_wrap(event) # webkit HACK! except: pass #print "browser_event_cb", event et = eventGetType(event) #print "browser_event_cb", event, et if et == "resize": onResize() return if et == 'mouseout': #print "mouse out", event _dispatchCapturedMouseoutEvent(event) if (et == 'keyup' or et == 'keydown' or et == 'keypress' or et == 'change'): return _dispatchCapturedEvent(event) else: return _dispatchCapturedMouseEvent(event)
def flashArgumentsToXML(self, arguments, num): """ @return: result of flashs build in function __flash__argumentsToXML """ arguments = self.toJS(arguments) return wnd().__flash__argumentsToXML(arguments, num);
def onFileSaveAs(self): data = self.timeProxy.exportData() data_uri = 'data:text/plain;base64,%s' % base64.encodestring(data) wnd = wnd().open('','_blank','scrollbars=yes,width=300,height=300') wnd.document.open("text/html") wnd.document.write("""<a href="%s">Right click here</a> if your browser supports data uri<br />Otherwise, you'll have to copy and paste this output to a text file<br />\n""" % data_uri) wnd.document.write("<pre>") wnd.document.write(data) wnd.document.write("</pre>") wnd.document.close()
def bind_pyjs_change(self): # Here we bind the change event to the self.change pyjs method # Since we are binding a global function to the self.change method, we want # that global function to be unique (or at least to have the myid suffix) global_unique_change = "change_%s" % (self.myid) setattr(wnd(),global_unique_change,self.change) # Now bind the change event to the wnd().global_unique_change function, which is actually self.change myjs = 'parent.jQuery("#%s").bind("change", function() { parent.%s() });' % (self.myid, global_unique_change) log.info("Now calling JS: %s", myjs) JS(""" eval(@{{myjs}}) """)
def onFileSaveAs(self): data = self.timeProxy.exportData() data_uri = 'data:text/plain;base64,%s' % base64.encodestring(data) w = wnd().open('','_blank','scrollbars=yes,width=300,height=300') w.document.open("text/html") w.document.write("""<a href="%s">Right click here</a> if your browser supports data uri<br />Otherwise, you'll have to copy and paste this output to a text file<br />\n""" % data_uri) w.document.write("<pre>") w.document.write(data) w.document.write("</pre>") w.document.close()
def init(): print "init", get_main_frame(), pyjd.is_desktop if get_main_frame() is None: if pyjd.is_desktop: pyjd.add_setup_callback(init) # pyjd.add_pre_run_callback(_first_notify) return global historyToken historyToken = '' hash = wnd().location.hash if hash and len(hash) > 0: historyToken = hash[1:]
def load_script(url, onload, async): wnd().status = ('Loading ' + url) def onload_fn(): wnd.status = ('Loaded ' + url) if not onload is None: eval(onload) return True e = DOM.createElement("script") e.src = url e.type = "text/javascript" e.language = "javascript" e.defer = async
def load_script(url, onload, async): wnd().status = ('Loading ' + url) def onload_fn(): wnd().status = ('Loaded ' + url) if not onload is None: eval(onload) return True e = DOM.createElement("script") e.src = url e.type="text/javascript" e.language = "javascript" e.defer = async
def _dispatchCapturedMouseoutEvent(evt): cap = getCaptureElement() if cap: #print "cap", dir(evt), cap if not eventGetToElement(evt): #print "synthesise", cap #When the mouse leaves the window during capture, release capture #and synthesize an 'onlosecapture' event. setCapture(None) listener = get_listener(cap) if listener: # this should be interesting... lcEvent = doc().createEvent('UIEvent') lcEvent.initUIEvent('losecapture', False, False, wnd(), 0) dispatchEvent(lcEvent, cap, listener)
def _dispatchCapturedMouseoutEvent(evt): cap = getCaptureElement() #print "cap", evt, cap if cap is None: return #print "cap", evt, cap if eventGetToElement(evt): return #print "synthesise", cap #When the mouse leaves the window during capture, release capture #and synthesize an 'onlosecapture' event. setCapture(None) listener = get_listener(cap) if listener is None: return # this should be interesting... #print "lose capture synthesised" lcEvent = doc().createEvent('UIEvent') lcEvent.initUIEvent('losecapture', False, False, wnd(), 0) dispatchEvent(lcEvent, cap, listener)
def setInstanceGlobal(movieName, instance): wnd().SWFUpload.addInstance(movieName, instance)
def confirm(msg): return wnd().confirm(msg)
def buttonClick(element): evt = doc().createEvent('MouseEvents') evt.initMouseEvent("click", True, True, wnd(), 1, 0, 0, 0, 0, False, False, False, False, 0, element) element.dispatchEvent(evt)
# # load(url) # # @param url URL to load # @param onreadystatechange function to be used for onreadystatechange # @param on_load_fn function to be called on succes, with parameters event, request # @param async request mode # @returns async == False: request object, async == True: None # def load(url, onreadystatechange=None, on_load_fn=None, async=False): setCompilerOptions("noDebug") wnd().status = ('Loading ' + url) req = createHttpRequest() if onreadystatechange is None: def onreadystatechange(evnt): if req.readyState == 4 and (req.status == 200 or req.status == 0): str = req.responseText wnd().status = ('Loaded ' + url) if not on_load_fn is None: on_load_fn(evnt, req) # next line is in JS() for IE6 JS("req.onreadystatechange = onreadystatechange;") req.open("GET", url, async) try:
def prompt(msg, defaultReply=""): return wnd().prompt(msg, defaultReply)
def getLocation(): global location if not location: location = Location.Location(wnd().location) return location
class SWFUploadInstances: def addInstance(self, movieName, instance): setattr(self, movieName, instance) class SWFUploadEventCatcher: def __init__(self): self.instances = SWFUploadInstances() def addInstance(self, movieName, instance): self.instances.addInstance(movieName, instance) # Global variable called by Flash External Interface wnd().SWFUpload = SWFUploadEventCatcher() def setInstanceGlobal(movieName, instance): wnd().SWFUpload.addInstance(movieName, instance) # Counter for Flash-movies global movieCount movieCount = 0 def getMovieCount(): return movieCount class SWFUpload(FlashPanel): """ Embedding and api handling of SWFUpload
def getClientWidth(): try: return wnd().innerWidth except: return doc().body.clientWidth
def setLocation(url): w = wnd() w.location = url
def getClientHeight(): try: return wnd().innerHeight except: return doc().body.clientHeight
def scroll(x, y): wnd().scroll(x, y)
def scrollBy(x, y): wnd().scrollBy(x, y)
def prompt(msg, defaultReply=""): return wnd().prompt(msg, defaultReply, "", 0)
def setInstanceGlobal(movieName, instance): wnd().players[movieName] = instance
def prompt(msg, defaultReply=""): """ Prompt the user to enter some text. We return the entered text, or None if the user cancelled. """ return wnd().prompt(msg, defaultReply);
def performanceNowInit(): performanceNowPolyfill() return wnd()
def onreadystatechange(evnt): if req.readyState == 4 and (req.status == 200 or req.status == 0): str = req.responseText wnd().status = ('Loaded ' + url) if not on_load_fn is None: on_load_fn(evnt, req)
def forward(): wnd().history.forward()
def onMouseMove(self, sender, x, y): event = DOM.eventGetCurrentEvent() self.mouseEvent = event button = DOM.eventGetButton(event) if not button == Event.BUTTON_LEFT: return ## The following commented code lets the native dnd happen in IE. sucks. ## But it may enable dragging our widgets out of IE into other apps. # else: # try: # self.dragWidget.getElement().dragDrop() # return # except: # pass # Adjust x and y to absolute coordinates. x, y = eventCoordinates(event) if self.dragging == DRAGGING_NO_MOVEMENT_YET: self.origMouseX = x self.origMouseY = y self.currentDragOperation = 'none' fromElement = self.dragWidget.getElement() # Is the widget itself draggable? try: draggable = fromElement.draggable except: draggable = False # if not, find the draggable element at (x, y) in the widget if not draggable: fromElement = findDraggable(sender.getElement(), self.origMouseX, self.origMouseY) # Nothing draggable found. return. if fromElement is None: self.dragging = NOT_DRAGGING return # Get the location for the dragging widget #self.absParent = None #self.absParent = self.dragWidget.getParent() #self.absLeft = DOM.getStyleAttribute(fromElement, 'left') #print self.absLeft #self.absTop = DOM.getStyleAttribute(fromElement, 'top') #print self.absTop #self.origTop = DOM.getAbsoluteTop(fromElement) + parent.getAbsoluteTop() #self.origLeft = DOM.getAbsoluteLeft(fromElement) + parent.getAbsoluteLeft() self.origTop = DOM.getAbsoluteTop(fromElement) self.origLeft = DOM.getAbsoluteLeft(fromElement) #self.glassTop = DOM.getAbsoluteTop(fromElement.offsetParent) #self.glassLeft = DOM.getAbsoluteTop(fromElement.offsetParent) position_absolute = DOM.getStyleAttribute(fromElement, 'position') == 'absolute' if position_absolute: self.dragLeftOffset = ( self.origMouseX - DOM.getAbsoluteLeft(fromElement.offsetParent)) self.dragTopOffset = ( self.origMouseY - DOM.getAbsoluteTop(fromElement.offsetParent)) else: self.dragLeftOffset = self.origMouseX - self.origLeft self.dragTopOffset = self.origMouseY - self.origTop # self.setDragImage(fromElement, # self.origMouseX - self.origLeft, # self.origMouseY - self.origTop) self.dragDataStore.elements = [fromElement] dragStartEvent = self.fireDNDEvent('dragstart', None, self.dragWidget) if not isCanceled(dragStartEvent): self.initFeedbackImage() RootPanel().add(self.draggingImage) self.setDragImageLocation(x, y) self.dragging = ACTIVELY_DRAGGING GlassWidget.show(self) elif self.dragging == ACTIVELY_DRAGGING: try: doc().selection.empty() except: wnd().getSelection().removeAllRanges() self.setDragImageLocation(x, y) # If we are still working on the previous iteration, or if we have # done this recently, we'll wait for the next event. if self.dragBusy or time.time() - self.drag_time < 0.25: return self.doDrag(event, x, y) self.drag_time = time.time()
Global variables called by Flash External Interface """ class PlayerEventCatcher: def fireEvent(self, *args): movieName = args[0] eventName = args[1] arguments = [] for i in range(2, len(args)): if args[i] != None: arguments.append(args[i]) wnd().players[args[0]].fireEvent(movieName, eventName, arguments) def setInstanceGlobal(movieName, instance): wnd().players[movieName] = instance wnd().players = {} wnd().flowplayer = PlayerEventCatcher() # Counter for Flash-movies global movieCount movieCount = 0 def getMovieCount(): return movieCount class Player(FlashPanel): """ Embedding and api handling of Flowplayer """
def getWindow(): return wnd()
class PlayerEventCatcher: def fireEvent(self, *args): movieName = args[0] eventName = args[1] arguments = [] for i in range(2, len(args)): if args[i] != None: arguments.append(args[i]) wnd().players[args[0]].fireEvent(movieName, eventName, arguments) def setInstanceGlobal(movieName, instance): wnd().players[movieName] = instance wnd().players = {} wnd().flowplayer = PlayerEventCatcher() # Counter for Flash-movies global movieCount movieCount = 0 def getMovieCount(): return movieCount class Player(FlashPanel): """ Embedding and api handling of Flowplayer """
def back(): wnd().history.back()
def onload_fn(): wnd().status = ('Loaded ' + url) if not onload is None: eval(onload) return True
pass return None # # load(url) # # @param url URL to load # @param onreadystatechange function to be used for onreadystatechange # @param on_load_fn function to be called on succes, with parameters event, request # @param async request mode # @returns async == False: request object, async == True: None # def load(url, onreadystatechange=None, on_load_fn=None, async=False): setCompilerOptions("noDebug") wnd().status = ('Loading ' + url) req = createHttpRequest() if onreadystatechange is None: def onreadystatechange(evnt): if req.readyState==4 and (req.status == 200 or req.status == 0): str = req.responseText wnd().status = ('Loaded ' + url) if not on_load_fn is None: on_load_fn(evnt, req) # next line is in JS() for IE6 JS("@{{req}}['onreadystatechange'] = @{{onreadystatechange}};") req.open("GET", url , async) try: req.send(None)
def onreadystatechange(evnt): if req.readyState==4 and (req.status == 200 or req.status == 0): str = req.responseText wnd().status = ('Loaded ' + url) if not on_load_fn is None: on_load_fn(evnt, req)
def requestAnimationFrameInit(): requestAnimationFramePolyfill() return wnd()