Mercurial > libervia-web
changeset 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 |
files | browser_side/panels.py libervia.py |
diffstat | 2 files changed, 84 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/browser_side/panels.py Sun Jun 26 03:04:17 2011 +0200 +++ b/browser_side/panels.py Sun Jun 26 23:23:22 2011 +0200 @@ -107,9 +107,11 @@ _new_panel = MicroblogPanel(self.host, accept_all=True) self.host.FillMicroblogPanel(_new_panel) else: - return - self.host.mpanels.remove(self) - self.host.mpanels.append(_new_panel) + return False + if isinstance(self, LiberviaWidget): + self.host.unregisterWidget(self) + if not isinstance(_new_panel, LiberviaWidget): + print ('WARNING: droping an object which is not a class of LiberviaWidget') grid = self.getParent() row_idx, cell_idx = self._getCellAndRow(grid, event) if self.host.selected == self: @@ -125,19 +127,26 @@ DOM.setStyleAttribute(td_elt, "width", "%s%%" % _width) #FIXME: delete object ? Check the right way with pyjamas -class LiberviaWidget(DropCell, VerticalPanel): +class LiberviaWidget(DropCell, VerticalPanel, ClickHandler): """Libervia's widget which can replace itself with a dropped widget on DnD""" - def __init__(self, title=''): + def __init__(self, host, title='', selectable=False): + """Init the widget + @param host: SatWebFrontend object + @param title: title show in the header of the widget + @param selectable: True is widget can be selected by user""" VerticalPanel.__init__(self) DropCell.__init__(self) - self.title_id = HTMLPanel.createUniqueId() - self.setting_button_id = HTMLPanel.createUniqueId() - self.close_button_id = HTMLPanel.createUniqueId() + ClickHandler.__init__(self) + self.host = host + self.__selectable = selectable + self.__title_id = HTMLPanel.createUniqueId() + self.__setting_button_id = HTMLPanel.createUniqueId() + self.__close_button_id = HTMLPanel.createUniqueId() header = AbsolutePanel() - self.title = Label(title) - self.title.setStyleName('widgetHeader_title') - header.add(self.title) + self.__title = Label(title) + self.__title.setStyleName('widgetHeader_title') + header.add(self.__title) #header.setCellVerticalAlignment(self.title, HasAlignment.ALIGN_MIDDLE) #header.setCellWidth(self.title, '100%') button_group_wrapper = SimplePanel() @@ -156,11 +165,30 @@ header.addStyleName('widgetHeader') self.setSize('100%', '100%') self.addStyleName('widget') + if self.__selectable: + self.addClickListener(self) + self.host.registerWidget(self) + + def onClick(self, sender): + self.host.select(self) def setTitle(self, text): """change the title in the header of the widget @param text: text of the new title""" - self.title.setText(text) + self.__title.setText(text) + + def isSelectable(self): + return self.__selectable + + def setSelectable(self, selectable): + if not self.__selectable: + try: + self.removeClickListener(self) + except ValueError: + pass + if self.selectable and not self in self._clickListeners: + self.addClickListener(self) + self.__selectable = selectable def setWidget(self, widget, scrollable=True): """Set the widget that will be in the body of the LiberviaWidget @@ -365,10 +393,9 @@ """Panel used to show microblog @param title: title of the panel @param accept_all: if true, show every message, without filtering jids""" - LiberviaWidget.__init__(self, title) + LiberviaWidget.__init__(self, host, title) #ScrollPanelWrapper.__init__(self) #DropCell.__init__(self) - self.host = host self.accept_all = accept_all self.accepted_groups = [] self.entries = {} @@ -476,50 +503,40 @@ self.occupants_list.clear() AbsolutePanel.clear(self) -class ChatPanel(DropCell, ClickHandler, ScrollPanelWrapper): +class ChatPanel(LiberviaWidget): def __init__(self, host, target, type='one2one'): """Panel used for conversation (one 2 one or group chat) @param host: SatWebFrontend instance @param target: entity (JID) with who we have a conversation (contact's jid for one 2 one chat, or MUC room) @param type: one2one for simple conversation, group for MUC""" - ScrollPanelWrapper.__init__(self) - DropCell.__init__(self) - ClickHandler.__init__(self) + LiberviaWidget.__init__(self, host, target.bare, selectable = True) self.vpanel = VerticalPanel() self.vpanel.setSize('100%','100%') - self.host = host self.type = type self.nick = None if not target: print "ERROR: Empty target !" return self.target = target - title="%s" % target.bare - _class = ['mb_panel_header'] - self.header = HTMLPanel("<div class='%s'>%s</div>" % (','.join(_class),html_sanitize(title))) - self.header.setStyleName('chatHeader') - self.body = AbsolutePanel() - self.body.setStyleName('chatPanel_body') + self.__body = AbsolutePanel() + self.__body.setStyleName('chatPanel_body') chat_area = HorizontalPanel() chat_area.setStyleName('chatArea') if type == 'group': self.occupants_list = OccupantsList() chat_area.add(self.occupants_list) - self.body.add(chat_area) + self.__body.add(chat_area) self.content = AbsolutePanel() self.content.setStyleName('chatContent') self.content_scroll = ScrollPanelWrapper(self.content) chat_area.add(self.content_scroll) chat_area.setCellWidth(self.content_scroll, '100%') - self.vpanel.add(self.header) - self.vpanel.setCellHeight(self.header, '1%') - self.vpanel.add(self.body) + self.vpanel.add(self.__body) + self.addStyleName('chatPanel') self.setWidget(self.vpanel) - self.setStyleName('chatPanel') - self.addClickListener(self) - def doDetachChildren(self): + """def doDetachChildren(self): #We need to force the use of a panel subclass method here, #for the same reason as doAttachChildren ScrollPanelWrapper.doDetachChildren(self) @@ -527,11 +544,8 @@ def doAttachChildren(self): #We need to force the use of a panel subclass method here, else #the event will not propagate to children - ScrollPanelWrapper.doAttachChildren(self) + ScrollPanelWrapper.doAttachChildren(self)""" - def onClick(self, sender): - self.host.select(self) - def setUserNick(self, nick): """Set the nick of the user, usefull for e.g. change the color of the user""" self.nick = nick @@ -579,6 +593,7 @@ def printMessage(self, from_jid, msg, timestamp=None): """Print message in chat window. Must be implemented by child class""" + print "print message:",msg _jid=JID(from_jid) nick = _jid.node if self.type=='one2one' else _jid.resource mymess = _jid.resource == self.nick if self.type == "group" else _jid.bare == self.host.whoami.bare #mymess = True if message comes from local user
--- 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: