0

我正在尝试使用睡衣(http://pyjs.org/)。我的输入文件名为 hi.py,如下所示:

from pyjamas import Window
from pyjamas.ui import RootPanel, Button
from pyjamas.ui import HTML

def greet(sender):
    Window.alert("Hello!")

b = Button("Click me", greet)
RootPanel().add(b)

我运行以下命令:

python ~/pyjs-pyjs-07f54ad/bin/pyjsbuild hi.py
Building : hi
PYJSPATH : [
    /Users/michaelnatkin/HelloPyjs
    /Users/michaelnatkin/pyjs-pyjs-07f54ad/library
    /Users/michaelnatkin/pyjs-pyjs-07f54ad/addons
]
Built to : /Users/michaelnatkin/HelloPyjs/output

这似乎运行没有错误,这是我的结果目录:

Michael-Natkins-MacBook-Pro-2:HelloPyjs michaelnatkin$ ls .
hi.js   hi.py   output
Michael-Natkins-MacBook-Pro-2:HelloPyjs michaelnatkin$ ls output
__init__.py         gchart.gif          hi.safari.cache.html
_pyjs.js            hi.html             history.html
bootstrap.js            hi.ie6.cache.html       tree_closed.gif
bootstrap_progress.js       hi.mozilla.cache.html       tree_open.gif
disclosurePanelClosed.png   hi.nocache.html         tree_white.gif
disclosurePanelClosed_rtl.png   hi.oldmoz.cache.html
disclosurePanelOpen.png     hi.opera.cache.html

然后,我将浏览器定向到 html 文件之一:file:///Users/michaelnatkin/HelloPyjs/output/hi.html

我得到......一个空白页。我的 js 控制台中的唯一错误是:

Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match. 

我想这并不太令人惊讶,因为 html 文件说:

<html>
<!-- auto-generated html - You should consider editing and adapting this
 to suit your requirements. No doctype used here to force quirks mode; see
 wiki for details: http://pyjs.org/wiki/csshellandhowtodealwithit/
-->
<head>

<title>hi (Pyjamas Auto-Generated HTML file)</title>
<meta name="pygwt:module" content="hi">
</head>
<body style="background-color:white">
<script type="text/javascript" src="bootstrap.js"></script>
<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
<script type="text/javascript" src="bootstrap.js"></script>
<iframe id="__pygwt_historyFrame" style="display:none;"></iframe>
</body>
</html>

所以..我完全被卡住了。有人能告诉我如何让这个坏男孩产生输出吗?我想创建一个更复杂的应用程序,但如果我不能说“你好”,它就不会顺利进行。谢谢!

4

1 回答 1

0

您是否也在 Firefox 中尝试过?虽然 Chrome 没有显示任何内容,但使用 Firefox 我收到一条错误消息,该消息来自您导入 RootPanel 和 Button 的方式。您应该将单行替换为:

from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.Button import Button

之后,您的按钮正确地向我打招呼。

关于 Chrome 问题,要么使用 --allow-file-access-from-files 启动它,要么运行本地 Web 服务器来显示您的页面。更多详细信息:https ://github.com/pyjs/pyjs/wiki/googlechromeproblems

于 2013-12-17T18:05:18.427 回答