DivmodNevow/Athena/Files: myelement.tac

File myelement.tac, 1.4 kB (added by dialtone, 2 years ago)

update the definition of the LiveElement? to use a t.input() instead of t.button.

Line 
1 from zope.interface import implements
2 from twisted.internet import reactor
3
4 from nevow import athena, loaders, tags as T, inevow
5
6 class MyElement(athena.LiveElement):
7     jsClass = u'MyModule.MyWidget'
8
9     docFactory = loaders.stan(T.div(render=T.directive('liveElement'))[
10         T.input(type="submit", value="Push me", onclick='Nevow.Athena.Widget.get(this).clicked()')])
11
12     def __init__(self, *a, **kw):
13         super(MyElement, self).__init__(*a, **kw)
14         reactor.callLater(5, self.myEvent)
15
16     def myEvent(self):
17         print 'My Event Firing'
18         self.callRemote('echo', 12345)
19
20     def echo(self, argument):
21         print 'Echoing', argument
22         return argument
23     athena.expose(echo)
24
25 from nevow import appserver, rend
26
27 class MyPage(athena.LivePage):
28     addSlash = True
29     docFactory = loaders.stan(T.html[
30         T.head(render=T.directive('liveglue')),
31         T.body(render=T.directive('myElement'))])
32
33     def render_myElement(self, ctx, data):
34         f = MyElement()
35         f.setFragmentParent(self)
36         return ctx.tag[f]
37
38 class FakeRoot(object):
39     implements(inevow.IResource)
40    
41     def locateChild(self, ctx, segments):
42         return MyPage(), segments
43
44 site = appserver.NevowSite(FakeRoot())
45
46 from twisted.application import service, internet
47
48 application = service.Application("Athena Demo")
49 webService = internet.TCPServer(8080, site)
50 webService.setServiceParent(application)
jethro@divmod.org