Pyjs newbie - blank screen of doom

80 views
Skip to first unread message

Michael Natkin

unread,
Dec 16, 2013, 11:31:13 PM12/16/13
to pyjs-...@googlegroups.com
I'm trying to use pyjamas (http://pyjs.org/) for the first time. My input file, named hi.py, looks like this:
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)

I run the following command:

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

Which appears to run without errors, and here is my resulting directory:

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

I then direct my browser to one of the html files: file:///Users/michaelnatkin/HelloPyjs/output/hi.html

and I get... a blank page. The only error in my js console is:

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

which I guess isn't too surprising since the html file says:

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

So.. I'm completely stuck. Can someone tell me how to get this bad boy to produce output? I've got a much more complicated app I want to create, but if I can't say "Hello" it isn't going to go well. Thank you!

Łukasz Mach

unread,
Dec 17, 2013, 7:27:11 AM12/17/13
to pyjs-...@googlegroups.com

W dniu 17.12.2013 05:31, Michael Natkin pisze:
[...]

which I guess isn't too surprising since the html file says:

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

So.. I'm completely stuck. Can someone tell me how to get this bad boy to produce output? I've got a much more complicated app I want to create, but if I can't say "Hello" it isn't going to go well. Thank you!

I think that output is quite ok (except double iframe), but you probably use chrome/chromium - in such case put it in your webserver directory (eg. /var/www/pyjs) and launch http://localhost/pyjs/

if it's Firefox - it should work without webserver.

regards

Maho

Michael Natkin

unread,
Dec 17, 2013, 1:39:44 PM12/17/13
to pyjs-...@googlegroups.com
Hey Maho - thanks a million, that was exactly the problem. If anyone has time, a followup question. The thing I'm actually trying to translate from python to javascript is essentially a headless mathematical calculation. In simplest form, suppose my python program was

def superComplicatedCalculation(a, b):
    return a+b

my whole UI is already built in JS so I don't want to use pyjs widgets at all. Could anyone point me in the direction of whatever wrapping and compilation steps I'd need to do to be able to call superComplicatedCalculation from JS?


----------------------------------------------------------------------------------------------------------------------------------


Michael Natkin
CTO


--
 
---
You received this message because you are subscribed to a topic in the Google Groups "Pyjs.org Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyjs-users/aBXdpuB8rWE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyjs-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Łukasz Mach

unread,
Dec 17, 2013, 6:46:39 PM12/17/13
to pyjs-...@googlegroups.com

W dniu 17.12.2013 19:39, Michael Natkin pisze:
> Hey Maho - thanks a million, that was exactly the problem. If anyone
> has time, a followup question. The thing I'm actually trying to
> translate from python to javascript is essentially a headless
> mathematical calculation. In simplest form, suppose my python program was
>
> def superComplicatedCalculation(a, b):
> return a+b
>
> my whole UI is already built in JS so I don't want to use pyjs widgets
> at all. Could anyone point me in the direction of whatever wrapping
> and compilation steps I'd need to do to be able to call
> superComplicatedCalculation from JS?

Yep, it's very easy.

def fn():
return "something"

if __name__ == '__main__':
from __pyjamas__ import wnd

wnd().fn = fn

And in your javascript code you run fn() or window.fn() ( I don't remember)

Michael Natkin

unread,
Dec 17, 2013, 6:47:27 PM12/17/13
to pyjs-...@googlegroups.com
Thank you so much!!

----------------------------------------------------------------------------------------------------------------------------------


Michael Natkin
CTO


--

--- You received this message because you are subscribed to a topic in the Google Groups "Pyjs.org Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyjs-users/aBXdpuB8rWE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyjs-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages