2013-12-17 44 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的安全行爲有關。謝謝! –