Mercurial > libervia-web
diff 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 |
line wrap: on
line diff
--- a/libervia.py Sun Jun 26 03:04:17 2011 +0200 +++ b/libervia.py Sun Jun 26 23:23:22 2011 +0200 @@ -102,14 +102,13 @@ self.contact_panel = ContactPanel(self) self.panel = panels.MainPanel(self) self.discuss_panel = self.panel.discuss_panel - self.tab_panel = self.panel.tab_panel - 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.tab_panel = self.panel.tab_panel + self.libervia_widgets = set() #keep track of all actives LiberviaWidgets self.room_list = set() #set of rooms self.mblog_cache = [] #used to keep blog entries in memory, to show them in new mblog panel - self.discuss_panel.addWidget(self.mpanels[0]) - self.discuss_panel.addWidget(self.mpanels[1]) - self.discuss_panel.addWidget(self.mpanels[2]) + self.discuss_panel.addWidget(panels.EmptyPanel(self)) + self.discuss_panel.addWidget(panels.MicroblogPanel(self, accept_all=True)) + self.discuss_panel.addWidget(panels.EmptyPanel(self)) self._register_box = None RootPanel().add(self.panel) DOM.addEventPreview(self) @@ -127,6 +126,16 @@ event.preventDefault() return True + def registerWidget(self, wid): + print "Registering", wid + self.libervia_widgets.add(wid) + + def unregisterWidget(self, wid): + try: + self.libervia_widgets.remove(wid) + except KeyError: + print ('WARNING: trying to remove a non registered Widget:', wid) + def setUniBox(self, unibox): """register the unibox widget""" self.uni_box = unibox @@ -147,7 +156,6 @@ @param panel: panel to add @param label: label of the tab""" self.tab_panel.add(panel, label) - self.other_panels.append(panel) def _isRegisteredCB(self, registered): if not registered: @@ -236,9 +244,9 @@ _groups=None mblog_entry = MicroblogEntry(data) - for panel in self.mpanels: - if isinstance(panel, panels.MicroblogPanel): - self.addBlogEntry(panel, sender, _groups, mblog_entry) + for lib_wid in self.libervia_widgets: + if isinstance(lib_wid, panels.MicroblogPanel): + self.addBlogEntry(lib_wid, sender, _groups, mblog_entry) self.mblog_cache.append((sender, _groups, mblog_entry)) if len(self.mblog_cache) > MAX_MBLOG_CACHE: @@ -265,9 +273,9 @@ _from = JID(from_jid) _to = JID(to_jid) showed = False - for panel in self.mpanels + self.other_panels: - if isinstance(panel,panels.ChatPanel) and (panel.target.bare == _from.bare or panel.target.bare == _to.bare): - panel.printMessage(_from, msg) + for lib_wid in self.libervia_widgets: + if isinstance(lib_wid,panels.ChatPanel) and (lib_wid.target.bare == _from.bare or lib_wid.target.bare == _to.bare): + lib_wid.printMessage(_from, msg) showed = True if not showed: #The message has not been showed, we must indicate it @@ -297,25 +305,25 @@ chat_panel.historyPrint() def _roomUserJoinedCb(self, room_id, room_service, user_nick, user_data): - for panel in self.mpanels + self.other_panels: - 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) + for lib_wid in self.libervia_widgets: + if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == "%s@%s" % (room_id, room_service): + lib_wid.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,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): - panel.userLeft(user_nick, user_data) + for lib_wid in self.libervia_widgets: + if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == "%s@%s" % (room_id, room_service): + lib_wid.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,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: - panel.startGame("Tarot", referee, players) + for lib_wid in self.libervia_widgets: + if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid: + lib_wid.startGame("Tarot", referee, players) def _tarotGameGenericCb(self, event_name, room_jid, args): - for panel in self.mpanels + self.other_panels: - if isinstance(panel,panels.ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid: - getattr(panel.getGame("Tarot"), event_name)(*args) + for lib_wid in self.libervia_widgets: + if isinstance(lib_wid,panels.ChatPanel) and lib_wid.type == 'group' and lib_wid.target.bare == room_jid: + getattr(lib_wid.getGame("Tarot"), event_name)(*args) def _getPresenceStatusCb(self, presence_data): for entity in presence_data: