本文整理汇总了Python中nevow.livepage.js函数的典型用法代码示例。如果您正苦于以下问题:Python js函数的具体用法?Python js怎么用?Python js使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了js函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tor_update
def tor_update(self, percent, tag, summary):
if self.ctx is None:
print "I have no Web client yet, but got a Tor update:", percent, tag, summary
return
client = livepage.IClientHandle(self.ctx)
point = int(300 * (float(percent) / 100.0))
self.client.send(livepage.js("""document.getElementById('progress_done').style.width = "%dpx";""" % point))
if percent == 100:
## done, turn message box green too
self.client.send(livepage.js("""document.getElementById("status").style.backgroundColor="#aaffaa";"""))
if self.continuous_update:
## add a text node for each update, creating a continuous list
self.client.send(
livepage.js(
"""var newNode = document.createElement('div');
newNode.appendChild(document.createTextNode("%d%% -- %s"));
document.getElementById('status').appendChild(newNode);"""
% (percent, summary)
)
)
else:
self.client.send(livepage.set("status", "%d%% — %s" % (percent, summary)))
示例2: __getitem__
def __getitem__(self, key):
if key == 'init':
def _init(value):
return livepage.js("livetags[%r] = %s;"%(self.name,value))
return _init
if key == 'delete':
return livepage.js("delComponent(%r);"%self.name)
return livepage.js("livetags[%r].%s"%(self.name, key))
示例3: checkException
def checkException(self):
def continueTests(ctx, status):
if status == 'passed':
self.passed()
else:
self.failed()
continuer = self.handle.transient(continueTests)
return livepage.anonymous(
[livepage.js("if (testFrameNode.contentDocument.title != 'Exception') {\n\t"),
continuer('passed'),
livepage.js("\n} else {\n\t"),
continuer('failed'),
livepage.js("\n}")])
示例4: recieveFieldData
def recieveFieldData(self, client, fieldId, value, total, onDone=None):
"""
Called by client to give us a value from a certain field
"""
total = int(total)
self.fieldsReceived.add(fieldId)
obj, name = self.fieldId2obj(fieldId)
# Decode the value
decoded = ''
toSearch = value
def getMatch():
if toSearch and toSearch[0] == '%':
match1 = self.reUni.search(toSearch)
match2 = self.reChr.search(toSearch)
if match1 and match2:
if match1.start() < match2.start():
return match1
else:
return match2
else:
return match1 or match2
else:
return self.reRaw.search(toSearch)
match = getMatch()
while match:
num = match.groups()[-1]
if len(num) > 1:
decoded += unichr(int(num, 16))
else:
decoded += num
toSearch = toSearch[match.end():]
match = getMatch()
# Check the field type
if fieldId in self.booleanFieldNames:
setattr(obj, name, decoded[0].lower() == 't')
elif fieldId in self.imgFieldNames:
if not decoded.startswith("resources"):
setattr(obj, name, toUnicode(decoded))
else:
# Must be a string
setattr(obj, name, toUnicode(decoded))
client.sendScript(js(
'document.getElementById("%s").style.color = "black"' % fieldId))
if len(self.fieldsReceived) == total:
self.fieldsReceived = set()
client.sendScript(js.alert(
(u"%s" % _('Settings saved')).encode('utf8')))
if onDone:
client.sendScript(js(onDone))
示例5: test_js
def test_js(self):
foo = livepage.js("foo")
self.livepage.call("alert", foo("1"))
self.assertEquals(self.livepage.sent, "alert(foo('1'));")
self.livepage.sendScript(foo(1))
self.assertEquals(self.livepage.sent, "foo(1)")
window = livepage.js("window")
self.livepage.sendScript(window.open("http://google.com"))
self.assertEquals(self.livepage.sent, "window.open('http://google.com')")
array = livepage.js("array")
self.livepage.sendScript(array[5])
self.assertEquals(self.livepage.sent, "array[5]")
self.livepage.sendScript(livepage.js[1, 2, 3])
self.assertEquals(self.livepage.sent, "[1,2,3]")
示例6: test_normal
def test_normal(self):
"""No quoting at all happens when we are in a JavascriptContext
which is not in a single quoted string or a double quoted string.
"""
ctx = makeCtx()
self.assertEquals(flat.flatten("foo", ctx), "'foo'")
self.assertEquals(flat.flatten(livepage.js("1 < 2 & 3"), ctx), "1 < 2 & 3")
示例7: inlineJSSerializer
def inlineJSSerializer(original, ctx):
from nevow import livepage
from nevow.tags import script, xml
theJS = livepage.js(original.children)
new = livepage.JavascriptContext(ctx, invisible[theJS])
return serialize(script(type="text/javascript")[
xml('\n//<![CDATA[\n'),
serialize(theJS, new),
xml('\n//]]>\n')], ctx)
示例8: test_callWithJS
def test_callWithJS(self):
self.livepage.call("add", 1, 2)
self.assertEquals(self.livepage.sent, "add(1,2)")
self.livepage.call("amIEvil", True)
self.assertEquals(self.livepage.sent, "amIEvil(true)")
self.livepage.call("add", 1.4, 2.4)
self.assertEquals(self.livepage.sent, "add(1.4,2.4)")
self.livepage.call('alert', livepage.js('document.title'))
self.assertEquals(self.livepage.sent, 'alert(document.title)')
self.livepage.call('alert', livepage.document.title)
self.assertEquals(self.livepage.sent, 'alert(document.title)')
示例9: action_post
def action_post(self, action, target, parameter, callWhenDone=None):
if callWhenDone is None:
callWhenDone = "function (){}"
def observePosting(client, location, destination):
if location.endswith(destination):
self.passed()
else:
self.failed()
return [
"var targetForm = ", contentDocument[target], ";",
"var postTarget = ", js.targetForm.action, ";",
[(js.targetForm[key].value, ' = "', value, '";')
for (key, value) in parameter.items()],
"addLoadObserver(function () {",
livepage.handler(
observePosting,
contentDocument.location,
js.postTarget),
"});",
js.sendSubmitEvent(js.targetForm, js(callWhenDone))]
示例10: handle_workloadClass
def handle_workloadClass(self, ctx, wlc):
if wlc in self.workloadClasses:
self.workloadClasses.remove(wlc)
action = "remove"
else:
self.workloadClasses.append(wlc)
action = "add"
rawClasses = set(self.workloadClasses)
yield livepage.js('document.getElementById("wlc_%s").classList.%s("active")' % (wlc, action)), livepage.eol
self.wltTable.prefilteredData = [wlc
for wlc
in self.wltTable.rawData
if wlc['rawClasses'] & rawClasses]
self.wltTable.filteredData = self.wltTable.prefilteredData
self.wltTable.setPage(0)
yield self.wltTable.update(ctx)
示例11: onCommand
from twisted.python import util
from nevow import rend, loaders, inevow, livepage
getValue = livepage.js('getValue')
changeLabel = livepage.js('changeLabel')
def onCommand(client, text):
client.sendScript(changeLabel(text))
class XulApp(livepage.LivePage):
addSlash = True
docFactory = loaders.xmlfile(util.sibpath(__file__, 'xul_example.xul'))
def locateChild(self, ctx, segments):
inevow.IRequest(ctx).setHeader("Content-Type", "application/vnd.mozilla.xul+xml; charset=UTF-8")
return rend.Page.locateChild(self, ctx, segments)
def render_btn(self, ctx, data):
return ctx.tag(oncommand=livepage.server.handle('onCommand', getValue('some-text')))
def handle_onCommand(self, ctx, text):
return changeLabel(text)
def createResource():
return XulApp()
示例12: _passHandle
def _passHandle(self, ctx, name):
"""Ties up a handler for the promote, demote,
up and down buttons. (Called by below funcs)"""
attr = getattr(self.outlinePane, 'handle%s' % name)
return ctx.tag(oncommand=handler(attr, js('currentOutlineId()')))
示例13: render_delNode
def render_delNode(self, ctx, data):
"""Fills in the oncommand handler for the
delete child button and short cut key"""
return ctx.tag(oncommand=handler(self.outlinePane.handleDelNode,
js("confirmDelete()"),
js('currentOutlineId()')))
示例14: render_addChild
def render_addChild(self, ctx, data):
"""Fills in the oncommand handler for the
add child button and short cut key"""
return ctx.tag(oncommand=handler(self.outlinePane.handleAddChild,
js('currentOutlineId()')))
示例15: _init
def _init(value):
return livepage.js("livetags[%r] = %s;"%(self.name,value))