Mercurial > libervia-web
changeset 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 | 2744dd31e8a5 |
files | browser_side/dialog.py browser_side/panels.py browser_side/register.py libervia.py |
diffstat | 4 files changed, 33 insertions(+), 24 deletions(-) [+] |
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)
--- a/browser_side/panels.py Mon May 23 00:45:19 2011 +0200 +++ b/browser_side/panels.py Wed May 25 14:21:48 2011 +0200 @@ -28,7 +28,6 @@ from pyjamas.ui.ScrollPanel import ScrollPanel from pyjamas.ui.TabPanel import TabPanel from pyjamas.ui.HTMLPanel import HTMLPanel -from pyjamas.ui.PopupPanel import PopupPanel from pyjamas.ui.Grid import Grid from pyjamas.ui.AutoComplete import AutoCompleteTextBox from pyjamas.ui.MenuBar import MenuBar @@ -51,7 +50,7 @@ from tools import html_sanitize from datetime import datetime from time import time -from dialog import ContactsChooser +from dialog import ContactsChooser, PopupPanelWrapper class MenuCmd: @@ -246,7 +245,7 @@ return contents = HTML(msg) - self._popup = PopupPanel(autoHide=False, modal=False) + self._popup = PopupPanelWrapper(autoHide=False, modal=False) self._popup.target_data = target_data self._popup.add(contents) self._popup.setStyleName("warningPopup") @@ -634,9 +633,6 @@ self.host=host AbsolutePanel.__init__(self) - #self.setHorizontalAlignment(HasAlignment.ALIGN_LEFT) - #self.setVerticalAlignment(HasAlignment.ALIGN_TOP) - menu = Menu(host) unibox_panel = UniBoxPanel(host) self.host.setUniBox(unibox_panel.unibox) @@ -652,12 +648,9 @@ self.add(self.tab_panel) self.setWidth("100%") - #self.setHeight("99%") Window.addWindowResizeListener(self) def onWindowResized(self, width, height): - print "resizing: %s %s" % (width, height) - #self.setWidth("%s%s" % (width, "px")); _elts = doc().getElementsByClassName('gwt-TabBar') if not _elts.length: tab_bar_h = 0
--- a/browser_side/register.py Mon May 23 00:45:19 2011 +0200 +++ b/browser_side/register.py Wed May 25 14:21:48 2011 +0200 @@ -48,10 +48,8 @@ vPanel.setHorizontalAlignment(HasAlignment.ALIGN_CENTER) self.loginBox = TextBox() self.loginBox.setName("login") - self.loginBox.setText("goffi_local") self.passBox = PasswordTextBox() self.passBox.setName("password") - self.passBox.setText("toto") grid = Grid(2, 2) grid.setText(0,0,"Login:") grid.setWidget(0,1, self.loginBox)
--- a/libervia.py Mon May 23 00:45:19 2011 +0200 +++ b/libervia.py Wed May 25 14:21:48 2011 +0200 @@ -22,14 +22,14 @@ import pyjd # this is dummy in pyjs from pyjamas.ui.RootPanel import RootPanel from pyjamas.ui.HTML import HTML -from pyjamas import Window +from pyjamas.ui.KeyboardListener import KEY_ESCAPE +from pyjamas import Window, DOM from pyjamas.JSONService import JSONProxy from browser_side.register import RegisterPanel, RegisterBox from browser_side.contact import ContactPanel -from browser_side.panels import MainPanel, EmptyPanel, MicroblogPanel, ChatPanel, StatusPanel +from browser_side import panels from browser_side.jid import JID - class LiberviaJsonProxy(JSONProxy): def __init__(self, *args, **kwargs): JSONProxy.__init__(self, *args, **kwargs) @@ -81,12 +81,12 @@ self.bridge_signals = BridgeSignals() self.selected = None self.uni_box = None - self.status_panel = StatusPanel(self) + self.status_panel = panels.StatusPanel(self) self.contact_panel = ContactPanel(self) - self.panel = MainPanel(self) + self.panel = panels.MainPanel(self) self.discuss_panel = self.panel.discuss_panel self.tab_panel = self.panel.tab_panel - self.mpanels = [EmptyPanel(self), MicroblogPanel(self, accept_all=True), EmptyPanel(self)] + self.mpanels = [panels.EmptyPanel(self), panels.MicroblogPanel(self, accept_all=True), panels.EmptyPanel(self)] self.other_panels = [] #panels not on the main tab #FIXME: temporary, need to be changed self.room_list = set() #set of rooms self.discuss_panel.changePanel(0,self.mpanels[0]) @@ -94,6 +94,7 @@ self.discuss_panel.changePanel(2,self.mpanels[2]) self._dialog = None RootPanel().add(self.panel) + DOM.addEventPreview(self) self.resize() self._register = RegisterCall() self._register.call('isRegistered',self._isRegisteredCB) @@ -102,6 +103,12 @@ """Resize elements""" Window.onResize() + 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 True + def setUniBox(self, unibox): """register the unibox widget""" self.uni_box = unibox @@ -200,7 +207,7 @@ else: _groups=None for panel in self.mpanels: - if isinstance(panel,MicroblogPanel) and (panel.isJidAccepted(sender) or _groups == None or _groups.intersection(panel.accepted_groups)): #TODO: check this + if isinstance(panel,panels.MicroblogPanel) and (panel.isJidAccepted(sender) or _groups == None or _groups.intersection(panel.accepted_groups)): #TODO: check this content = data['content'] author = data.get('author') timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here @@ -210,7 +217,7 @@ _from = JID(from_jid) _to = JID(to_jid) for panel in self.mpanels + self.other_panels: - if isinstance(panel,ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): + if isinstance(panel,panels.ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): panel.printMessage(_from, msg) def _presenceUpdateCb(self, entity, show, priority, statuses): @@ -224,7 +231,7 @@ def _roomJoinedCb(self, room_id, room_service, room_nicks, user_nick): _target = JID("%s@%s" % (room_id,room_service)) self.room_list.add(_target) - chat_panel = ChatPanel(self, _target, type='group') + chat_panel = panels.ChatPanel(self, _target, type='group') chat_panel.setUserNick(user_nick) if room_id.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :) self.addTab(chat_panel, "Tarot") @@ -235,23 +242,23 @@ def _roomUserJoinedCb(self, room_id, room_service, user_nick, user_data): for panel in self.mpanels + self.other_panels: - if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): + if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): panel.userJoined(user_nick, user_data) def _roomUserLeftCb(self, room_id, room_service, user_nick, user_data): for panel in self.mpanels + self.other_panels: - if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): + if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): panel.userLeft(user_nick, user_data) def _tarotGameStartedCb(self, room_jid, referee, players): print ("Tarot Game Started \o/") for panel in self.mpanels + self.other_panels: - if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: + if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: panel.startGame("Tarot", referee, players) def _tarotGameGenericCb(self, event_name, room_jid, args): for panel in self.mpanels + self.other_panels: - if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: + if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: getattr(panel.getGame("Tarot"), event_name)(*args) def _getPresenceStatusCB(self, presence_data):