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.
Comments