Package library :: Package pyjamas :: Package feed :: Module Feed
[hide private]
[frames] | no frames]

Source Code for Module library.pyjamas.feed.Feed

 1  from pyjamas.Timer import Timer 
 2  from __pyjamas__ import doc, JS 
 3  from pyjamas import DOM 
 4   
 5  frameId = 0 
 6   
7 -class Feed:
8
9 - def __init__(self, url, callback):
10 global frameId 11 frame = DOM.createElement("iframe") 12 frameid = "__pygwt_feedFrame%d" % frameId 13 frameId += 1 14 DOM.setAttribute(frame, "id", frameid) 15 DOM.setAttribute(frame, "src", url) 16 #DOM.setStyleAttribute(frame, 'width', '0') 17 #DOM.setStyleAttribute(frame, 'height', '0') 18 #DOM.setStyleAttribute(frame, 'border', '0') 19 #DOM.setStyleAttribute(frame, 'position', 'absolute') 20 self.frameId = frameId 21 self.frame = frame 22 self.timer = Timer(notify=self) 23 doc().parent.body.appendChild(frame) 24 self.callback = callback 25 self.timer.scheduleRepeating(100)
26
27 - def getFrameTxt(self):
28 return str(self.frame.contentWindow.document.body.innerHTML)
29
30 - def onTimer(self, *args):
31 txt = self.getFrameTxt() 32 if txt == '': 33 return 34 self.callback(self, txt) 35 self.timer.cancel()
36