2/10/2003

For people who are curious

For people who are curious about the bleeding edge of Woven development, I have been working on LivePage a bit more recently. LivePage allows asynchronous events both from the browser, and to the browser after the page has already been loaded. The current implementation in CVS requires Flash, but it is also technically possible to get this to work with an IFrame connection that the server never closes as the Output Conduit. I whipped up a little example so you can get a feel for where I am going with this, and give me feedback if you desire.



If you want to try this, save it as an rpy and view it with twisted.web using a tap created like this: (Latest CVS is probably required)



mktap web --path=/path/to/web/resources --flashconduit 4321



Make sure you put a slash after the .rpy, so the relative urls spit out by the webConduitGlue resolve correctly. For example, http://localhost:8080/simpleLivePageExample.rpy/




from twisted.web.woven import model, page, input, widgets


class ANumber(model.AttributeModel):
def __init__(self):
model.AttributeModel.__init__(self)
self.value = 0


class AWidget(widgets.Widget):
def setUp(self, request, node, data):
self.add(widgets.Text(data))


class HandleInput(input.Anything):
def initialize(self):
self.view.addEventHandler("onclick", self.clicked)

def clicked(self, request, widget):
print "CLICKED!"
self.model.setData(self.model.getData() + 1)
self.model.notify({'request': request})


resource = page.LivePage(ANumber())

resource.setSubviewFactory('aView', AWidget)
resource.setSubcontrollerFactory('aController', HandleInput)

resource.template = """<html>
<body>
<div model="value" view="aView">
stuff
</div>

<img src="http://www.google.com/images/logo.gif" model="value" view="Widget" controller="aController" />

<div view="webConduitGlue" />
</body>
</html>"""


No comments: