diff browser_side/dialog.py @ 43:a7ff1e6f1229

browser_side: prevent default for escape key (cancel HTTPRequest in FF)
author Goffi <goffi@goffi.org>
date Wed, 25 May 2011 14:21:48 +0200
parents 71a9cc9b9d57
children 153de5d461a4
line wrap: on
line diff
--- a/browser_side/dialog.py	Mon May 23 00:45:19 2011 +0200
+++ b/browser_side/dialog.py	Wed May 25 14:21:48 2011 +0200
@@ -21,10 +21,12 @@
 
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HorizontalPanel import HorizontalPanel
+from pyjamas.ui.PopupPanel import PopupPanel
 from pyjamas.ui.DialogBox import DialogBox
 from pyjamas.ui.ListBox import ListBox
 from pyjamas.ui.Button import Button
 from pyjamas.ui.HTML import HTML
+from pyjamas.ui.KeyboardListener import KEY_ESCAPE
 
 class ContactsChooser(DialogBox):
 
@@ -130,3 +132,12 @@
         self.hide()
         if self.callback:
             self.callback()
+
+class PopupPanelWrapper(PopupPanel):
+    """This wrapper catch Escape event to avoid request cancellation by Firefox"""
+
+    def onEventPreview(self, event):
+        if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE:
+            #needed to prevent request cancellation in Firefox
+            event.preventDefault()
+        return PopupPanel.onEventPreview(self, event)