pyjs/pyjs — pull request #824 by chopin (2014-05-31 10:03:57+00:00)
Title: catching Window closing event in pyjd

This is a normal way to catch a window closing event. It worked in web-browser versions, but not in pyjd.

from pyjamas import Window
class CloseHandler(object):
def __init__(self):
Window.addWindowCloseListener(self)
def onWindowClosed(self):
Window.alert('in onWindowClosed()')
def onWindowClosing(self):
Window.alert('in onWindowClosing()')

I found that Browser.on_unload_callback() in mshtml.py catches the window close event, and it did nothing. I modified Browser() class to add event handlers, and pyjd to return the browser object created. This is how to start pyjd to add a windnow close handler:

import pyjd
from pyjamas import Window
browser=pyjd.setup(url)
browser.addCloseHandler(Window.onClosing)

Now, the added handler will catch the event and call CloseHandler.onWindowClosing(). I don't know how to catch onWindowClosed, Browser.on_before_unload_callback() doesn't exist.

The current GitHub version modified after pip installation doesn't have pyjd installation, so I tested my code in the release version pyjs-0.8.1a.