Created
October 16, 2009 02:01
-
-
Save showyou/211475 to your computer and use it in GitHub Desktop.
wx+twisted http
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wx | |
from twisted.internet import wxreactor | |
wxreactor.install() | |
from twisted.internet import reactor | |
from twisted.web import client | |
ID_EXIT = 101 | |
class MyFrame(wx.Frame): | |
TIMER_ID = 1 | |
def __init__(self, parent, ID, title): | |
wx.Frame.__init__(self, parent, ID, title, | |
wx.DefaultPosition, wx.Size(300,200)) | |
menu = wx.Menu() | |
menu.Append(ID_EXIT, "E&xit", "Terminate the program") | |
menuBar = wx.MenuBar() | |
menuBar.Append(menu, "&File"); | |
self.x = wx.StaticText(self, -1, '-') | |
self.SetMenuBar(menuBar) | |
wx.EVT_MENU(self, ID_EXIT,self.DoExit) | |
self.timer = self.startTimer(self.TIMER_ID,self.OnUpdate,20000) | |
self.CreateStatusBar() | |
print "loading MyFrame" | |
self.setStatusBar("start") | |
def DoExit(self, event): | |
self.Close(True) | |
reactor.stop() | |
def OnUpdate(self,event): | |
d = client.getPage('http://twitter.com/statuses/public_timeline.json') | |
d.addCallback(self.changeTxt) | |
self.setStatusBar("start: getPage") | |
def changeTxt(self, data): | |
self.x.SetLabel(data) | |
self.setStatusBar("end: getPage") | |
def setStatusBar(self,str): | |
sb = wx.GetApp().GetTopWindow().GetStatusBar() | |
sb.SetStatusText(str) | |
print "setStatusBar %s" %str | |
def startTimer(self, timerID, func, span): | |
timer = wx.Timer(self,timerID) | |
wx.EVT_TIMER(self,timerID,func) | |
timer.Start(span) | |
return timer | |
class MyApp(wx.App): | |
def __init__(self): | |
wx.App.__init__(self, False) | |
self.frame = MyFrame(None, -1, "Hello, world") | |
self.frame.Show(True) | |
self.SetTopWindow(self.frame) | |
def main(): | |
app = MyApp() | |
reactor.registerWxApp(app) | |
reactor.run() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment