Mercurial > libervia-web
diff libervia.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 | 7782a786b2f0 |
children | 72c51a4839cc |
line wrap: on
line diff
--- 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):