i had refused using nodeid ("termid") and It has been worked in later nevow
version (0.9.27)!
I tried to get widget in 2 ways
1)
var node = $("termid");
var widget = Nevow.Athena.Widget.get(node);
2)
var widget = Nevow.Athena.Widget.fromAthenaID("termid");
both of a case give exception (cannot find node by id)
I've added a method keypress2 into AaccWeb.Users (aacc_web.js)
and string mystr = u"""<textarea cols="10" rows="5" onkeypress="return
Nevow.Athena.Widget.get(this).keypress2(event);">""" + sym +
u"""</textarea>""" into aacc_web.py
aacc_web.py
< mystr = u"""<textarea id="termid" cols="10" rows="5" onkeypress="return
keypress(event)">""" + sym + u"""</textarea>"""
> #mystr = u"""<textarea id="termid" cols="10" rows="5" onkeypress="return
keypress(event)">""" + sym + u"""</textarea>"""
> mystr = u"""<textarea cols="10" rows="5" onkeypress="return
Nevow.Athena.Widget.get(this).keypress2(event);">""" + sym +
u"""</textarea>"""
aacc_web.js
// import Nevow.Athena
function keypress(event)
{
var key = event.charCode ? event.charCode : event.keyCode;
//var node = $("termid");
//var widget = Nevow.Athena.Widget.get(node);
var widget = Nevow.Athena.Widget.fromAthenaID("termid");
if (widget) {
alert("widget get ok");
widget.callRemote("aacc_keypress", event.charCode, event.keyCode,
event.metaKey, event.altKey, event.ctrlKey, event.shiftKey);
}
else {
alert("widget get error");
}
}
AaccWeb.Users = Nevow.Athena.Widget.subclass("AaccWeb.Users");
AaccWeb.Users.methods(
> function keypress2(self, event)
> {
> var key = event.charCode ? event.charCode : event.keyCode;
> self.callRemote("aacc_keypress", event.charCode, event.keyCode,
event.metaKey, event.altKey, event.ctrlKey, event.shiftKey);
> },
function start(self, node, event) {
self.callRemote("aacc_start");
return false;
},
function showConference(self, toWhat) {
var client_data = Nevow.Athena.NodeByAttribute(self.node, "class",
"Users");
client_data.innerHTML = toWhat;
}
);
ps:
however, why in old versions (0.9.0) it worked without these changes and in
new (0.9.27) is not
2007/12/9, Михаил Михайлов <[EMAIL PROTECTED]>:
>
> Jean-Paul
> thanks for the operative answer
> but my file aacc_web.py contains a line u "AaccWeb.Users" instead of u "
> AaccWeb.Users"
> the space is not present,
> space have appeared because of copying the text from my electronic
> translator
> (differently it did not work and in version 9.0 but it works)
> If You will give Your mail I can send files
> problem probably another
>
>
> 2007/12/9, Jean-Paul Calderone < [EMAIL PROTECTED]>:
> >
> > On Sun, 9 Dec 2007 00:43:31 +0300, Михаил Михайлов <[EMAIL PROTECTED]>
> > wrote:
> > >Hi
> > >
> > >my example consists 2 files: aacc_web.py and aacc_web.js
> > >
> > >python aacc_web.py
> > >will start on port 8080
> > >
> > >generated html contains textarea and in case of input
> > >prints the entered symbol on the console and in textarea
> > >It works ONLY in version 9.0 and does NOT (!) work in last versions
> > >
> > >Explain what's wrong
> > >
> >
> > You're using a feature of MochiKit, $(). Athena pages used to include
> > MochiKit by default, but they don't anymore. This may be the problem.
> >
> > Your JavaScript file includes "//import Nevow.Athena" which will be
> > ignored. This should be "// import Nevow.Athena". This probably isn't
> > the cause of the problem, but it's still wrong.
> >
> > Your Python class "Users" has a jsClass of u" AaccWeb.Users". This
> > causes
> > a KeyError because there is no such class. Instead it should be
> > u"AaccWeb.Users".
> >
> > After changing these three things, I see events being reported on the
> > server.
> >
> > Jean-Paul
> >
> > _______________________________________________
> > Twisted-web mailing list
> > [email protected]
> > http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
> >
>
>
aacc_web.js
Description: JavaScript source
# -*- coding: utf-8 -*-
""" aacc_web
"""
from twisted.application import service, internet
from twisted.internet import reactor, protocol, defer, task, ssl
from twisted.protocols import basic
from twisted.python import log, logfile, util
from twisted.cred import portal, checkers, credentials
from twisted.web import static
from nevow import appserver
from nevow import tags, guard
from nevow import rend, loaders, inevow, athena
from nevow import url
from nevow.inevow import IRequest
import os, logging, pprint, time, sys
class Users(athena.LiveFragment):
jsClass=u"AaccWeb.Users"
docFactory = loaders.xmlstr("""
<div xmlns:nevow="http://nevow.com/ns/nevow/0.1"
xmlns:athena="http://divmod.org/ns/athena/0.7"
nevow:render="liveFragment" class="Users">
</div>
""")
running = False
def __init__(self, **kwargs):
print 'start Users AJAX session'
def aacc_start(self):
if self.running:
return
reactor.callLater(1, self.updateConference, True)
self.running = True
athena.expose(aacc_start)
def aacc_keypress(self, charcode=None, keycode=None, metakey=None, altkey=None, ctrlkey=None, shiftkey=None):
print 'charcode: %s keycode: %s metakey: %s altkey: %s ctrlkey: %s shiftkey: %s' % (charcode, keycode, metakey, altkey, ctrlkey, shiftkey)
self.updateConference(True, unichr(charcode))
athena.expose(aacc_keypress)
def updateConference(self, force=False, sym=''):
""" updateConference """
#print 'updateConference'
def onUpdateConferenceOk(result):
self.callUpdateConference = reactor.callLater(1, self.updateConference)
def onUpdateConferenceErr(err):
self.running = False
if not force:
self.callUpdateConference = reactor.callLater(1, self.updateConference)
return
#mystr = u"""<textarea id="termid" cols="10" rows="5" onkeypress="return keypress(event)">""" + sym + u"""</textarea>"""
mystr = u"""<textarea cols="10" rows="5" onkeypress="return Nevow.Athena.Widget.get(this).keypress2(event);">""" + sym + u"""</textarea>"""
#self.callRemote('setFocus')
df = self.callRemote('showConference', mystr)
df.addCallbacks(onUpdateConferenceOk, onUpdateConferenceErr)
class ConferencePage(athena.LivePage):
docFactory = loaders.xmlstr("""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:nevow="http://nevow.com/ns/nevow/0.1">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<nevow:invisible nevow:render="liveglue"/>
<script type="text/javascript" src="aacc_web.js">
</script>
</head>
<body>
<div nevow:render="conference">
</div>
</body>
</html>
""")
def __init__(self, *a, **kw):
super(ConferencePage, self).__init__(*a, **kw)
self.jsModules.mapping[u'AaccWeb'] = util.sibpath(__file__, 'aacc_web.js')
addSlash = True
def render_liveglue(self, ctx, data):
req = ctx.locate(IRequest)
args = dict([(k,v[0]) for (k,v) in req.args.items()])
self.args = args
return athena.LivePage.render_liveglue(self, ctx, data)
def render_conference(self, ctx, data):
args = dict([(k,v) for (k,v) in self.args.items()])
c = Users(**args)
c.page = self
reactor.callLater(0, c.aacc_start)
return ctx.tag[c]
class RootPage(rend.Page):
""" """
addSlash = True
docFactory = loaders.xmlstr("""
<html xmlns:nevow="http://nevow.com/ns/nevow/0.1">
<body>
</body>
</html>
""")
def renderHTTP(self, ctx):
print 'render of root page'
req = ctx.locate(IRequest)
my_url = url.here.child('conference')
return my_url
def child_conference(self, ctx):
return ConferencePage()
class aacc_web:
""" """
def __init__(self, **kwargs):
""" """
resource = RootPage()
site = appserver.NevowSite(resource)
reactor.listenTCP(8080, site)
if __name__ == "__main__":
aacc_web = aacc_web()
reactor.run()
_______________________________________________ Twisted-web mailing list [email protected] http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
