[Twisted-Python] timeout using LivePage

Sean Gillies sgillies at frii.com
Mon Aug 25 14:30:30 MDT 2003


Hi,

Am very new to Twisted but am quickly finding that I like
it.  All my questions and comments involve Twisted 1.0.6
in combo with Python 2.3 on OS X.

I've run into a problem while making a rough .rpy prototype of
a mapping application (ala MapQuest) using the U of Minnesota
MapServer's Python interface.

I will need to have server-side handlers for javascript events
to allow map zooming, panning, &c and so have been experimenting
with LivePage.  I intend that the code should render a map image,
and upon clicking the image, we zoom into the map (changing model
data), and redraw the map image.  Unfortunately, browsers are
unable to load the

mapserv.rpy/?woven_hookupOutputConduitToThisFrame=1

URL that is generated by my instance of LivePage, and so the map
is never redrawn as it should.  The model data does get changed
successfully, and when I manually reload the page, I do see
the zoomed map image as I expect.

What is this 'woven_hookupOutputConduitToThisFrame' all about?
Do I need to set up another method to handle this URL?

I know that it's not recommended to put so much logic in the .rpy
file, but as I said, a quick and dirty prototype is what I'm after.
Am attaching the source of mapserv.rpy here:

--------------------------------------------------------------------
import os
import time
from twisted.web.woven import page, widgets, controller, model
from mapscript import *

base_mapfile = 'navtech_std.map'

# Get map object from the session data if we can
class MapModel(model.MethodModel):
     def wmfactory_mapobj(self, request):
         session_obj = request.getSession()
         try:
             session_mapobj = session_obj.mapobj
         except AttributeError:
             session_mapobj = mapObj(base_mapfile)
             session_obj.mapobj = session_mapobj
         return session_mapobj

# Widget for creating a temp map image and a tag linking to it
class MapImage(widgets.Widget):
     def setUp(self, request, node, data):
         mapobj = data
         node.tagName = "img"
         imgobj = mapobj.draw()
         tmp_file = '%s_%d_%d.%s' \
                  % (mapobj.name, time.time(), os.getpid(),
                     imgobj.format.extension )
         imgobj.save(os.path.join('/tmp', tmp_file))
         map_url = os.path.join('/tmp', tmp_file)
         node.setAttribute('src', map_url)
         node.setAttribute('height', str(mapobj.height))
         node.setAttribute('width', str(mapobj.width))
         node.setAttribute('border', '1')

# Widget for displaying the current scale of the map
class MapScale(widgets.Widget):
     def setUp(self, request, node, data):
         text = 'Scale: 1:%d' % (data.scale)
         newNode = request.d.createTextNode(text)
         node.appendChild(newNode)

# Template, using the web conduit glue
template = """<html>
   <body>
     <img model="mapobj" view="map_image" controller="map_ctrl"/>
     <p model="mapobj" view="map_scale" />
     <div view="webConduitGlue" />
   </body>
</html>
"""

# Zoom into the map in the event of a javascript onclick
class MyEventHandler(controller.Controller):
     def handle(self, request):
         self.view.addEventHandler("onclick", self.onClick)

     def onClick(self, request, widget):
         # Get session map object (layers and spatial extents)
         session_obj = request.getSession()
         try:
             session_mapobj = session_obj.mapobj
         except AttributeError:
             session_mapobj = mapObj(base_mapfile)
             session_obj.mapobj = session_mapob

         # zoom in on the map
         w = session_mapobj.width
         h = session_mapobj.height
         pt = pointObj()
         pt.x, pt.y = w/2, h/2
         session_mapobj.zoomPoint(2, pt, w, h, session_mapobj.extent, 
None)
         print session_mapobj.extent.minx, session_mapobj.extent.maxx
         print self, "Zoomed!!!"

         # There is a better way to redraw the map, certainly
         request.redirect('http://localhost:8084/mapserv.rpy/')
         request.finish()

# Page class
class MyPage(page.LivePage):
     def wcfactory_map_ctrl(self, request, node, model):
         return MyEventHandler(model)

# Resource
resource = MyPage(MapModel(), template=template)
resource.setSubviewFactory("map_image", MapImage)
resource.setSubviewFactory("map_scale", MapScale)
-----------------------------------------------------------------------

looking forward to any insights into LivePage and also looking forward
to getting enough experience with Twisted that I can begin to contribute
to the list discussions.

cheers,
Sean

--
Sean Gillies
sgillies at frii dot com
http://www.frii.com/~sgillies





More information about the Twisted-Python mailing list