Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
42:71a9cc9b9d57 | 43:a7ff1e6f1229 |
---|---|
20 """ | 20 """ |
21 | 21 |
22 import pyjd # this is dummy in pyjs | 22 import pyjd # this is dummy in pyjs |
23 from pyjamas.ui.RootPanel import RootPanel | 23 from pyjamas.ui.RootPanel import RootPanel |
24 from pyjamas.ui.HTML import HTML | 24 from pyjamas.ui.HTML import HTML |
25 from pyjamas import Window | 25 from pyjamas.ui.KeyboardListener import KEY_ESCAPE |
26 from pyjamas import Window, DOM | |
26 from pyjamas.JSONService import JSONProxy | 27 from pyjamas.JSONService import JSONProxy |
27 from browser_side.register import RegisterPanel, RegisterBox | 28 from browser_side.register import RegisterPanel, RegisterBox |
28 from browser_side.contact import ContactPanel | 29 from browser_side.contact import ContactPanel |
29 from browser_side.panels import MainPanel, EmptyPanel, MicroblogPanel, ChatPanel, StatusPanel | 30 from browser_side import panels |
30 from browser_side.jid import JID | 31 from browser_side.jid import JID |
31 | |
32 | 32 |
33 class LiberviaJsonProxy(JSONProxy): | 33 class LiberviaJsonProxy(JSONProxy): |
34 def __init__(self, *args, **kwargs): | 34 def __init__(self, *args, **kwargs): |
35 JSONProxy.__init__(self, *args, **kwargs) | 35 JSONProxy.__init__(self, *args, **kwargs) |
36 self.handler=self | 36 self.handler=self |
79 self.whoami = None | 79 self.whoami = None |
80 self.bridge = BridgeCall() | 80 self.bridge = BridgeCall() |
81 self.bridge_signals = BridgeSignals() | 81 self.bridge_signals = BridgeSignals() |
82 self.selected = None | 82 self.selected = None |
83 self.uni_box = None | 83 self.uni_box = None |
84 self.status_panel = StatusPanel(self) | 84 self.status_panel = panels.StatusPanel(self) |
85 self.contact_panel = ContactPanel(self) | 85 self.contact_panel = ContactPanel(self) |
86 self.panel = MainPanel(self) | 86 self.panel = panels.MainPanel(self) |
87 self.discuss_panel = self.panel.discuss_panel | 87 self.discuss_panel = self.panel.discuss_panel |
88 self.tab_panel = self.panel.tab_panel | 88 self.tab_panel = self.panel.tab_panel |
89 self.mpanels = [EmptyPanel(self), MicroblogPanel(self, accept_all=True), EmptyPanel(self)] | 89 self.mpanels = [panels.EmptyPanel(self), panels.MicroblogPanel(self, accept_all=True), panels.EmptyPanel(self)] |
90 self.other_panels = [] #panels not on the main tab #FIXME: temporary, need to be changed | 90 self.other_panels = [] #panels not on the main tab #FIXME: temporary, need to be changed |
91 self.room_list = set() #set of rooms | 91 self.room_list = set() #set of rooms |
92 self.discuss_panel.changePanel(0,self.mpanels[0]) | 92 self.discuss_panel.changePanel(0,self.mpanels[0]) |
93 self.discuss_panel.changePanel(1,self.mpanels[1]) | 93 self.discuss_panel.changePanel(1,self.mpanels[1]) |
94 self.discuss_panel.changePanel(2,self.mpanels[2]) | 94 self.discuss_panel.changePanel(2,self.mpanels[2]) |
95 self._dialog = None | 95 self._dialog = None |
96 RootPanel().add(self.panel) | 96 RootPanel().add(self.panel) |
97 DOM.addEventPreview(self) | |
97 self.resize() | 98 self.resize() |
98 self._register = RegisterCall() | 99 self._register = RegisterCall() |
99 self._register.call('isRegistered',self._isRegisteredCB) | 100 self._register.call('isRegistered',self._isRegisteredCB) |
100 | 101 |
101 def resize(self): | 102 def resize(self): |
102 """Resize elements""" | 103 """Resize elements""" |
103 Window.onResize() | 104 Window.onResize() |
105 | |
106 def onEventPreview(self, event): | |
107 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: | |
108 #needed to prevent request cancellation in Firefox | |
109 event.preventDefault() | |
110 return True | |
104 | 111 |
105 def setUniBox(self, unibox): | 112 def setUniBox(self, unibox): |
106 """register the unibox widget""" | 113 """register the unibox widget""" |
107 self.uni_box = unibox | 114 self.uni_box = unibox |
108 self.uni_box.addKey("@@: ") | 115 self.uni_box.addKey("@@: ") |
198 if data.has_key('groups'): | 205 if data.has_key('groups'): |
199 _groups = set(data['groups'].split() if data['groups'] else []) | 206 _groups = set(data['groups'].split() if data['groups'] else []) |
200 else: | 207 else: |
201 _groups=None | 208 _groups=None |
202 for panel in self.mpanels: | 209 for panel in self.mpanels: |
203 if isinstance(panel,MicroblogPanel) and (panel.isJidAccepted(sender) or _groups == None or _groups.intersection(panel.accepted_groups)): #TODO: check this | 210 if isinstance(panel,panels.MicroblogPanel) and (panel.isJidAccepted(sender) or _groups == None or _groups.intersection(panel.accepted_groups)): #TODO: check this |
204 content = data['content'] | 211 content = data['content'] |
205 author = data.get('author') | 212 author = data.get('author') |
206 timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here | 213 timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here |
207 panel.addEntry(content, author, timestamp) | 214 panel.addEntry(content, author, timestamp) |
208 | 215 |
209 def _newMessageCb(self, from_jid, msg, msg_type, to_jid): | 216 def _newMessageCb(self, from_jid, msg, msg_type, to_jid): |
210 _from = JID(from_jid) | 217 _from = JID(from_jid) |
211 _to = JID(to_jid) | 218 _to = JID(to_jid) |
212 for panel in self.mpanels + self.other_panels: | 219 for panel in self.mpanels + self.other_panels: |
213 if isinstance(panel,ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): | 220 if isinstance(panel,panels.ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): |
214 panel.printMessage(_from, msg) | 221 panel.printMessage(_from, msg) |
215 | 222 |
216 def _presenceUpdateCb(self, entity, show, priority, statuses): | 223 def _presenceUpdateCb(self, entity, show, priority, statuses): |
217 _entity = JID(entity) | 224 _entity = JID(entity) |
218 #XXX: QnD way to get our status | 225 #XXX: QnD way to get our status |
222 self.contact_panel.setConnected(_entity.bare, _entity.resource, show, priority, statuses) | 229 self.contact_panel.setConnected(_entity.bare, _entity.resource, show, priority, statuses) |
223 | 230 |
224 def _roomJoinedCb(self, room_id, room_service, room_nicks, user_nick): | 231 def _roomJoinedCb(self, room_id, room_service, room_nicks, user_nick): |
225 _target = JID("%s@%s" % (room_id,room_service)) | 232 _target = JID("%s@%s" % (room_id,room_service)) |
226 self.room_list.add(_target) | 233 self.room_list.add(_target) |
227 chat_panel = ChatPanel(self, _target, type='group') | 234 chat_panel = panels.ChatPanel(self, _target, type='group') |
228 chat_panel.setUserNick(user_nick) | 235 chat_panel.setUserNick(user_nick) |
229 if room_id.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :) | 236 if room_id.startswith('sat_tarot_'): #XXX: it's not really beautiful, but it works :) |
230 self.addTab(chat_panel, "Tarot") | 237 self.addTab(chat_panel, "Tarot") |
231 else: | 238 else: |
232 self.addTab(chat_panel, str(_target)) | 239 self.addTab(chat_panel, str(_target)) |
233 chat_panel.setPresents(room_nicks) | 240 chat_panel.setPresents(room_nicks) |
234 chat_panel.historyPrint() | 241 chat_panel.historyPrint() |
235 | 242 |
236 def _roomUserJoinedCb(self, room_id, room_service, user_nick, user_data): | 243 def _roomUserJoinedCb(self, room_id, room_service, user_nick, user_data): |
237 for panel in self.mpanels + self.other_panels: | 244 for panel in self.mpanels + self.other_panels: |
238 if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): | 245 if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): |
239 panel.userJoined(user_nick, user_data) | 246 panel.userJoined(user_nick, user_data) |
240 | 247 |
241 def _roomUserLeftCb(self, room_id, room_service, user_nick, user_data): | 248 def _roomUserLeftCb(self, room_id, room_service, user_nick, user_data): |
242 for panel in self.mpanels + self.other_panels: | 249 for panel in self.mpanels + self.other_panels: |
243 if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): | 250 if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): |
244 panel.userLeft(user_nick, user_data) | 251 panel.userLeft(user_nick, user_data) |
245 | 252 |
246 def _tarotGameStartedCb(self, room_jid, referee, players): | 253 def _tarotGameStartedCb(self, room_jid, referee, players): |
247 print ("Tarot Game Started \o/") | 254 print ("Tarot Game Started \o/") |
248 for panel in self.mpanels + self.other_panels: | 255 for panel in self.mpanels + self.other_panels: |
249 if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: | 256 if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: |
250 panel.startGame("Tarot", referee, players) | 257 panel.startGame("Tarot", referee, players) |
251 | 258 |
252 def _tarotGameGenericCb(self, event_name, room_jid, args): | 259 def _tarotGameGenericCb(self, event_name, room_jid, args): |
253 for panel in self.mpanels + self.other_panels: | 260 for panel in self.mpanels + self.other_panels: |
254 if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: | 261 if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: |
255 getattr(panel.getGame("Tarot"), event_name)(*args) | 262 getattr(panel.getGame("Tarot"), event_name)(*args) |
256 | 263 |
257 def _getPresenceStatusCB(self, presence_data): | 264 def _getPresenceStatusCB(self, presence_data): |
258 for entity in presence_data: | 265 for entity in presence_data: |
259 for resource in presence_data[entity]: | 266 for resource in presence_data[entity]: |