| 18 | |
| 19 | class MyApp(App): |
| 20 | def main(self, name='world'): |
| 21 | # margin 0px auto allows to center the app to the screen |
| 22 | wid = gui.VBox(width=300, height=200, margin='0px auto') |
| 23 | |
| 24 | lbl = gui.Label("Close or reload the page, the console thread will stop automatically.") |
| 25 | wid.append(lbl) |
| 26 | |
| 27 | # add the following 3 lines to your app and the on_window_close method to make the console close automatically |
| 28 | tag = gui.Tag(_type='script') |
| 29 | tag.add_child("javascript", """window.onunload=function(e){remi.sendCallback('%s','%s');return "close?";};""" % ( |
| 30 | str(id(self)), "on_window_close")) |
| 31 | wid.add_child("onunloadevent", tag) |
| 32 | |
| 33 | # returning the root widget |
| 34 | return wid |
| 35 | |
| 36 | def on_window_close(self): |
| 37 | # here you can handle the unload |