Saturday, December 25, 2010

How To Tease Everyone On Christmas

This project may never become a serious thing, but it is fun. I intend to write an introductory post on the project, but for now I just want to post two code examples that should peek some interest.

# counter.py
from trapdoor.extension import Extension, Factory

class Counter(Extension):

    value = 0

    @Extension.method()
    @Extension.returns(int)
    def get(self):
        self._result = self.value

    @Extension.method()
    def incr(self):
        self.value += 1

counter = Factory(Counter)

and,

// counterdemo.js
WindowManager.createWindow();

document.write('<input id="a" />' +
'<br />'+
'<input onclick="window.t = window.t - 100;" name="faster" value="faster" type="button" />'+
'<input onclick="window.t = window.t + 100;" name="slower" value="slower" type="button" />'+
'<input id="t" />');

var t = 500;
var globalcounter = counter.create();

function update() {
    $('#t').val(typeof globalcounter.get);
    $('#a').val(globalcounter.get());
    globalcounter.incr();

    window.setTimeout(update, t);
}

window.setTimeout(update, t);

The result is a simple desktop app.

No comments:

I write here about programming, how to program better, things I think are neat and are related to programming. I might write other things at my personal website.

I am happily employed by the excellent Caktus Group, located in beautiful and friendly Carrboro, NC, where I work with Python, Django, and Javascript.

Blog Archive