Thanks Lukasz, but it didn't work.
Doing
wnd().js_callback = py_callback
is not really making anything accessible via "window" to javascript.
Anyway, following your suggestion I have tried several things, and I came
up with the following code which is working fine:
class MyWebSocket:
def __init__(self):
pass
def process_event(self, event):
JS('''alert(@{{event}}.data);''')
def connect_websocket(self, group, server="127.0.0.1", port=8888):
url = 'ws://%s:%s/realtime/%s' % (server, port, group)
callback = self.process_event
JS('''parent.jQuery(document).ready(function(){
if(!top.web2py_websocket(@{{url}},@{{callback}})) {
alert("html5 websocket not supported by your browser, try
Google Chrome");
}
});''')
BR,
Daniel
On Wednesday, February 6, 2013 2:34:34 AM UTC+1, Maho wrote:
>
> W dniu 06.02.2013 01:51, Daniel Gonzalez pisze:
> [...]
> > How can I call a pyjs class method from the embedded javascript?
>
> I would do it in such way:
> #v+
> from __pyjamas__ import wnd
>
> wnd().js_callback = py_callback
> #v-
>
> and in .js part I would call:
>
> #v+
> window.js_callback()
> #v-
>
> --
> pozdrawiam
>
> Łukasz Mach - [email protected] <javascript:>
>
--
---
You received this message because you are subscribed to the Google Groups
"Pyjs.org Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.