| 1 |
from twisted.internet import reactor |
|---|
| 2 |
|
|---|
| 3 |
from nevow import athena, loaders, tags as T |
|---|
| 4 |
|
|---|
| 5 |
class MyFragment(athena.LiveFragment): |
|---|
| 6 |
jsClass = u'MyModule.MyWidget' |
|---|
| 7 |
|
|---|
| 8 |
docFactory = loaders.stan(T.div(render=T.directive('liveFragment'))[ |
|---|
| 9 |
T.button(onclick='Nevow.Athena.Widget.get(this).clicked()')]) |
|---|
| 10 |
|
|---|
| 11 |
def __init__(self, *a, **kw): |
|---|
| 12 |
super(MyFragment, self).__init__(*a, **kw) |
|---|
| 13 |
reactor.callLater(5, self.myEvent) |
|---|
| 14 |
|
|---|
| 15 |
def myEvent(self): |
|---|
| 16 |
print 'My Event Firing' |
|---|
| 17 |
self.callRemote('echo', 12345) |
|---|
| 18 |
|
|---|
| 19 |
def echo(self, argument): |
|---|
| 20 |
print 'Echoing', argument |
|---|
| 21 |
return argument |
|---|
| 22 |
athena.expose(echo) |
|---|
| 23 |
|
|---|
| 24 |
from nevow import appserver, rend |
|---|
| 25 |
|
|---|
| 26 |
class MyPage(athena.LivePage): |
|---|
| 27 |
docFactory = loaders.stan(T.html[ |
|---|
| 28 |
T.head(render=T.directive('liveglue')), |
|---|
| 29 |
T.body(render=T.directive('myFragment'))]) |
|---|
| 30 |
|
|---|
| 31 |
def render_myFragment(self, ctx, data): |
|---|
| 32 |
f = MyFragment() |
|---|
| 33 |
f.setFragmentParent(self) |
|---|
| 34 |
return ctx.tag[f] |
|---|
| 35 |
|
|---|
| 36 |
class Root(rend.Page): |
|---|
| 37 |
def child_(self, ctx): |
|---|
| 38 |
return MyPage() |
|---|
| 39 |
|
|---|
| 40 |
site = appserver.NevowSite(Root()) |
|---|
| 41 |
|
|---|
| 42 |
from twisted.application import service, internet |
|---|
| 43 |
|
|---|
| 44 |
application = service.Application("Athena Demo") |
|---|
| 45 |
webService = internet.TCPServer(8080, site) |
|---|
| 46 |
webService.setServiceParent(application) |
|---|