2013-12-17 42 views
0

我试图使用睡衣(http://pyjs.org/)。我的输入文件,命名为hi.py,看起来是这样的:空白页尽可能简单的pyjs(睡衣)应用程序

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文件之一:文件:///Users/michaelnatkin/HelloPyjs/output/hi.html

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

<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> 

所以..我完全被卡住:因为HTML文件说

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

。我想这不是太奇怪了。有人能告诉我如何让这个坏男孩产生输出吗?我有一个更复杂的应用程序,我想创建,但如果我不能说“你好”,它不会很好。谢谢!

回答

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

+0

是的,就是这样。与Chrome的安全行为有关。谢谢! –