Florent Guillaume wrote:
Myself I absolutely love the approach taken by CrackAjax

It's funny you mention that. I was intrigued by that too, but I can only characterize his implementation as a toy. :(

I've been working on something similar but have tried to be a bit more "professional" about it (unit tests, trying to be a good designer, etc.). Like CrackAjax it only does translation of Python syntax to JavaScript, but it does a good job and I really like the ability to define client-side methods on the view. Here's an example from my prototype (the canvas tag only works in Safari, Konquerer, and Firefox 1.5):

from anguine.view import AnguineView
from anguine.decorator import clientside
from zope.app.publisher.browser import BrowserView

class TestView1(BrowserView, AnguineView):

    def getContext():
        canvas = document.getElementById('test_canvas')
        return canvas.getContext('2d')

    def draw():
        ctx = getContext()
        for i in range(6):
            ctx.fillStyle = 'rgb('+(51*i)+','+(255-51*i)+',255)'
            for i in range(6):

    def clearCanvas():
        ctx = getContext()
        ctx.clearRect(0, 0, 150, 150)

Here's the ZPT:

<html metal:use-macro="context/@@standard_macros/view">
      tal:content="structure view/_anguine__js_code"/>
  <body metal:fill-slot="body" tal:omit-tag="">
    <canvas id="test_canvas" width="150" height="150"
        style="border: 1px solid black;"></canvas>
    <button onclick="draw()">Draw</button>
    <button onclick="clearCanvas()">Clear</button>

I consider this a mad scientist experiment, so I don't expect it to be officially included anywhere or even get any work from me once the novelty wears off. You are warned; I don't want angry villagers with pitchforks and torches coming to my castle. :)
Benji York
Senior Software Engineer
Zope Corporation
Zope3-dev mailing list
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com

Reply via email to