comparison libervia.py @ 84:8f35e9970e7f

browser side: new widget handling: - new design integration improved (ChatPanel is now working) - widget now register themselves for event handling
author Goffi <goffi@goffi.org>
date Sun, 26 Jun 2011 23:23:22 +0200
parents 68d360caeecb
children a8f027738c16
comparison
equal deleted inserted replaced
83:68d360caeecb 84:8f35e9970e7f
100 self.uni_box = None 100 self.uni_box = None
101 self.status_panel = panels.StatusPanel(self) 101 self.status_panel = panels.StatusPanel(self)
102 self.contact_panel = ContactPanel(self) 102 self.contact_panel = ContactPanel(self)
103 self.panel = panels.MainPanel(self) 103 self.panel = panels.MainPanel(self)
104 self.discuss_panel = self.panel.discuss_panel 104 self.discuss_panel = self.panel.discuss_panel
105 self.tab_panel = self.panel.tab_panel 105 self.tab_panel = self.panel.tab_panel
106 self.mpanels = [panels.EmptyPanel(self), panels.MicroblogPanel(self, accept_all=True), panels.EmptyPanel(self)] 106 self.libervia_widgets = set() #keep track of all actives LiberviaWidgets
107 self.other_panels = [] #panels not on the main tab #FIXME: temporary, need to be changed
108 self.room_list = set() #set of rooms 107 self.room_list = set() #set of rooms
109 self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel 108 self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel
110 self.discuss_panel.addWidget(self.mpanels[0]) 109 self.discuss_panel.addWidget(panels.EmptyPanel(self))
111 self.discuss_panel.addWidget(self.mpanels[1]) 110 self.discuss_panel.addWidget(panels.MicroblogPanel(self, accept_all=True))
112 self.discuss_panel.addWidget(self.mpanels[2]) 111 self.discuss_panel.addWidget(panels.EmptyPanel(self))
113 self._register_box = None 112 self._register_box = None
114 RootPanel().add(self.panel) 113 RootPanel().add(self.panel)
115 DOM.addEventPreview(self) 114 DOM.addEventPreview(self)
116 self.resize() 115 self.resize()
117 self._register = RegisterCall() 116 self._register = RegisterCall()
125 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE: 124 if event.type in ["keydown", "keypress", "keyup"] and event.keyCode == KEY_ESCAPE:
126 #needed to prevent request cancellation in Firefox 125 #needed to prevent request cancellation in Firefox
127 event.preventDefault() 126 event.preventDefault()
128 return True 127 return True
129 128
129 def registerWidget(self, wid):
130 print "Registering", wid
131 self.libervia_widgets.add(wid)
132
133 def unregisterWidget(self, wid):
134 try:
135 self.libervia_widgets.remove(wid)
136 except KeyError:
137 print ('WARNING: trying to remove a non registered Widget:', wid)
138
130 def setUniBox(self, unibox): 139 def setUniBox(self, unibox):
131 """register the unibox widget""" 140 """register the unibox widget"""
132 self.uni_box = unibox 141 self.uni_box = unibox
133 self.uni_box.addKey("@@: ") 142 self.uni_box.addKey("@@: ")
134 143
145 def addTab(self, panel, label): 154 def addTab(self, panel, label):
146 """Add a panel in a tab 155 """Add a panel in a tab
147 @param panel: panel to add 156 @param panel: panel to add
148 @param label: label of the tab""" 157 @param label: label of the tab"""
149 self.tab_panel.add(panel, label) 158 self.tab_panel.add(panel, label)
150 self.other_panels.append(panel)
151 159
152 def _isRegisteredCB(self, registered): 160 def _isRegisteredCB(self, registered):
153 if not registered: 161 if not registered:
154 self._register_box = RegisterBox(self.logged) 162 self._register_box = RegisterBox(self.logged)
155 self._register_box.centerBox() 163 self._register_box.centerBox()
234 _groups = set(data['groups'].split() if data['groups'] else []) 242 _groups = set(data['groups'].split() if data['groups'] else [])
235 else: 243 else:
236 _groups=None 244 _groups=None
237 mblog_entry = MicroblogEntry(data) 245 mblog_entry = MicroblogEntry(data)
238 246
239 for panel in self.mpanels: 247 for lib_wid in self.libervia_widgets:
240 if isinstance(panel, panels.MicroblogPanel): 248 if isinstance(lib_wid, panels.MicroblogPanel):
241 self.addBlogEntry(panel, sender, _groups, mblog_entry) 249 self.addBlogEntry(lib_wid, sender, _groups, mblog_entry)
242 250
243 self.mblog_cache.append((sender, _groups, mblog_entry)) 251 self.mblog_cache.append((sender, _groups, mblog_entry))
244 if len(self.mblog_cache) > MAX_MBLOG_CACHE: 252 if len(self.mblog_cache) > MAX_MBLOG_CACHE:
245 del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)] 253 del self.mblog_cache[0:len(self.mblog_cache-MAX_MBLOG_CACHE)]
246 254
263 271
264 def _newMessageCb(self, from_jid, msg, msg_type, to_jid): 272 def _newMessageCb(self, from_jid, msg, msg_type, to_jid):
265 _from = JID(from_jid) 273 _from = JID(from_jid)
266 _to = JID(to_jid) 274 _to = JID(to_jid)
267 showed = False 275 showed = False
268 for panel in self.mpanels + self.other_panels: 276 for lib_wid in self.libervia_widgets:
269 if isinstance(panel,panels.ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): 277 if isinstance(lib_wid,panels.ChatPanel) and (lib_wid.target.bare == _from.bare or lib_wid.target.bare == _to.bare):
270 panel.printMessage(_from, msg) 278 lib_wid.printMessage(_from, msg)
271 showed = True 279 showed = True
272 if not showed: 280 if not showed:
273 #The message has not been showed, we must indicate it 281 #The message has not been showed, we must indicate it
274 other = _to if _from.bare == self.whoami.bare else _from 282 other = _to if _from.bare == self.whoami.bare else _from
275 self.contact_panel.setContactMessageWaiting(other.bare, True) 283 self.contact_panel.setContactMessageWaiting(other.bare, True)
295 self.addTab(chat_panel, str(_target)) 303 self.addTab(chat_panel, str(_target))
296 chat_panel.setPresents(room_nicks) 304 chat_panel.setPresents(room_nicks)
297 chat_panel.historyPrint() 305 chat_panel.historyPrint()
298 306
299 def _roomUserJoinedCb(self, room_id, room_service, user_nick, user_data): 307 def _roomUserJoinedCb(self, room_id, room_service, user_nick, user_data):
300 for panel in self.mpanels + self.other_panels: 308 for lib_wid in self.libervia_widgets:
301 if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): 309 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == "%s@%s" % (room_id, room_service):
302 panel.userJoined(user_nick, user_data) 310 lib_wid.userJoined(user_nick, user_data)
303 311
304 def _roomUserLeftCb(self, room_id, room_service, user_nick, user_data): 312 def _roomUserLeftCb(self, room_id, room_service, user_nick, user_data):
305 for panel in self.mpanels + self.other_panels: 313 for lib_wid in self.libervia_widgets:
306 if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): 314 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == "%s@%s" % (room_id, room_service):
307 panel.userLeft(user_nick, user_data) 315 lib_wid.userLeft(user_nick, user_data)
308 316
309 def _tarotGameStartedCb(self, room_jid, referee, players): 317 def _tarotGameStartedCb(self, room_jid, referee, players):
310 print ("Tarot Game Started \o/") 318 print ("Tarot Game Started \o/")
311 for panel in self.mpanels + self.other_panels: 319 for lib_wid in self.libervia_widgets:
312 if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: 320 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid:
313 panel.startGame("Tarot", referee, players) 321 lib_wid.startGame("Tarot", referee, players)
314 322
315 def _tarotGameGenericCb(self, event_name, room_jid, args): 323 def _tarotGameGenericCb(self, event_name, room_jid, args):
316 for panel in self.mpanels + self.other_panels: 324 for lib_wid in self.libervia_widgets:
317 if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: 325 if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid:
318 getattr(panel.getGame("Tarot"), event_name)(*args) 326 getattr(lib_wid.getGame("Tarot"), event_name)(*args)
319 327
320 def _getPresenceStatusCb(self, presence_data): 328 def _getPresenceStatusCb(self, presence_data):
321 for entity in presence_data: 329 for entity in presence_data:
322 for resource in presence_data[entity]: 330 for resource in presence_data[entity]:
323 args = presence_data[entity][resource] 331 args = presence_data[entity][resource]