Skip to content

Conversation

@chopin
Copy link

@chopin chopin commented May 31, 2014

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.

@chopin
Copy link
Author

chopin commented Jun 1, 2014

pyjd.setup() returns None in pyjs mode. So, a safe way to run both in pyjs and pyjd is:

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

@anthonyrisinger
Copy link
Contributor

the API you've suggested looks good, but you'll need to rebase this down to at most a handful of functional commits/changes implementing what you need, and nothing else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants