Some suggestions for the Pyjamas Book #280

Open
pyjsorg opened this Issue Apr 27, 2012 · 0 comments

Projects

None yet

1 participant

@pyjsorg
Contributor
pyjsorg commented Apr 27, 2012

Hello,

I'm working through the Pyjamas Book (http://pyjs.org/book/output/Bookreader.html) and there was one of its section that didn't work for me. I had tried to run the Slideshow example (in the "Simple use of HTTPRequest" section of http://pyjs.org/book/output/Bookreader.html#Rest%20of%20the%20World) with the http server of the Python Standard Library.

Eventually I was able to make it work and I want to submit to you the changes I've made. But some of these changes may not fit what you wanted to achieve so it's up to you to accept them. In particular I didn't understand why you wanted to use a HTTP POST request instead of a HTTP GET one to retrieve the test_slide.txt file

So first of all the Slideshow.py file :
> from pyjamas.ui.HTML import HTML
> from pyjamas.ui.RootPanel import RootPanel
> from pyjamas.HTTPRequest import HTTPRequest
>
> class SlideLoader:
> def init(self, panel):
> self.panel = panel
>
> def onCompletion(self, text):
> self.panel.setSlide(text)
>
> def onError(self, text, code):
> self.panel.onError(text, code)
>
> def onTimeout(self, text):
> self.panel.onTimeout(text)
>
> class Slideshow:
>
> def onModuleLoad(self):
> self.slide = HTML()
> RootPanel().add(self.slide)
>
> #HTTPRequest().asyncPost("test_slide.txt", "", SlideLoader(self))
> HTTPRequest().asyncGet("test_slide.txt", SlideLoader(self))
>
> def setSlide(self, content):
> #content = content.upper()
> self.slide.setHTML("<pre>%s</pre>" % content)
>
> def onError(self, text, code):
> self.slide.setHTML(text + "<br />" + code)
>
> if name == 'main':
> app = Slideshow()
> app.onModuleLoad()

Then here's a python file that start a HTTP server. You just have to execute it in the directory of the Slideshow.html file (or one of its parent).

The python 2.6 version of this file :
> import BaseHTTPServer
> import SimpleHTTPServer
>
> server_address = ('', 8000)
> handler_class = SimpleHTTPServer.SimpleHTTPRequestHandler
> httpd = BaseHTTPServer.HTTPServer(server_address, handler_class)
> httpd.serve_forever()
>

The python 3.x version of this file :
> import http.server
>
> server_address = ('', 8000)
> handler_class = http.server.SimpleHTTPRequestHandler
> httpd = http.server.HTTPServer(server_address, handler_class)
> httpd.serve_forever()
>

I hope this helps.

Keep up the good work !

Evens Fortuné

Original issue: http://code.google.com/p/pyjamas/issues/detail?id=439 (July 01, 2010 02:30:14)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment