# HG changeset patch # User Goffi # Date 1302825694 -7200 # Node ID 099c05a0dcabe955286942275db4b24d88c8142d # Parent 78bfc398926b2da26e9b8f02e54d42b65ded07e3 browser side: microblog panel improvments - panels can now be changed by DnD - contacts panel's title can be used by DnD for the global microblog panel - microblogs now appear in reverse order (from bottom to top) - MicroblogPanel now use a ScrollPanel and 100% space - user's message now appear in correct group when using groupblog - MagicBox renamed to UniBox diff -r 78bfc398926b -r 099c05a0dcab contact.py --- a/contact.py Sat Apr 09 13:14:39 2011 +0200 +++ b/contact.py Fri Apr 15 02:01:34 2011 +0200 @@ -31,19 +31,19 @@ from pyjamas.ui.DragWidget import DragWidget, DragContainer from tools.jid import JID -class GroupLabel(DragWidget, Label): - def __init__(self, group): - Label.__init__(self, group) #, Element=DOM.createElement('div') - self.group = group - self.setStyleName('group') +class DragLabel(DragWidget): + + def __init__(self, text, type): DragWidget.__init__(self) + self._text = text + self._type = type def onDragStart(self, event): print "onDragStart" dt = event.dataTransfer #self.addMessage('types is %s' % dt.getTypes()) - dt.setData('Text', self.group) - dt.setData('type', "GROUP") + dt.setData('Text', self._text) + dt.setData('type', self._type) #self.addMessage('after setting, len is %s' % len(dt.dataStore.items)) #self.addMessage('types is %s' % dt.getTypes()) dt.setDragImage(self.getElement(), 15, 15) @@ -62,6 +62,14 @@ # parent = parent.getParent() #parent.addMessage(message) +class GroupLabel(DragLabel, Label): + def __init__(self, group): + self.group = group + Label.__init__(self, group) #, Element=DOM.createElement('div') + self.setStyleName('group') + DragLabel.__init__(self, group, "GROUP") + + class ContactLabel(Label): def __init__(self, jid, name=None): if not name: @@ -97,6 +105,12 @@ VerticalPanel.add(self, _item) self.contacts.append(_item) +class ContactTitleLabel(DragLabel, Label): + def __init__(self, text): + Label.__init__(self, text) #, Element=DOM.createElement('div') + self.setStyleName('contactTitle') + DragLabel.__init__(self, text, "CONTACT") + class ContactPanel(SimplePanel): """Manage the contacts and groups""" @@ -106,8 +120,8 @@ self.groups={} self.vPanel = VerticalPanel() - _title = Label('Contacts') - _title.setStyleName('contactTitle') + _title = ContactTitleLabel('Contacts') + DOM.setStyleAttribute(_title.getElement(), "cursor", "pointer") self._contactList = ContactList() self._contactList.setStyleName('contactList') @@ -129,7 +143,7 @@ if not self.groups.has_key(group): self.groups[group] = set() self._groupList.add(group) - self.host.magicBox.addKey("@%s: " % group) + self.host.uniBox.addKey("@%s: " % group) self.groups[group].add(jid) self._contactList.add(jid) diff -r 78bfc398926b -r 099c05a0dcab libervia.py --- a/libervia.py Sat Apr 09 13:14:39 2011 +0200 +++ b/libervia.py Fri Apr 15 02:01:34 2011 +0200 @@ -25,6 +25,7 @@ from pyjamas.ui.VerticalPanel import VerticalPanel from pyjamas.ui.HorizontalPanel import HorizontalPanel from pyjamas.ui.HTMLPanel import HTMLPanel +from pyjamas.ui.ScrollPanel import ScrollPanel from pyjamas.ui.Grid import Grid from pyjamas.ui.Label import Label from pyjamas.ui import HasAlignment @@ -119,7 +120,7 @@ def onXiangqiGame(self): Window.alert("Xiangqi selected") -class MagicBox(AutoCompleteTextBox): +class UniBox(AutoCompleteTextBox): def __init__(self, host): AutoCompleteTextBox.__init__(self) @@ -138,28 +139,31 @@ #XXX: fixed directly on pyjamas, if the patch is accepted, no need to walk around this return AutoCompleteTextBox.complete(self) -class EmptyPanel(DropWidget, SimplePanel): - """Empty dropable panel""" - - def __init__(self, host, data): - SimplePanel.__init__(self) - self.host = host - self.data = data - _panel = HTMLPanel(" ") - self.add(_panel) - self.setHeight('100%') +class DropCell(DropWidget): + """Cell in the middle grid which replace itself with the dropped widget on DnD""" + + def __init__(self): DropWidget.__init__(self) def onDragEnter(self, event): + print "drag enter" self.addStyleName('dragover') DOM.eventPreventDefault(event) def onDragLeave(self, event): + print "drag leave" self.removeStyleName('dragover') def onDragOver(self, event): DOM.eventPreventDefault(event) + def _getCellAndRow(self, grid, event): + """Return cell and row index where the event is occuring""" + cell = grid.getEventTargetCell(event) + row = DOM.getParent(cell) + return (row.rowIndex, cell.cellIndex) + + def onDrop(self, event): print "Empty Panel: onDrop" dt = event.dataTransfer @@ -174,14 +178,34 @@ item=' ' item_type = None DOM.eventPreventDefault(event) - _mblog = MicroblogPanel(self.host, item) if item_type=="GROUP": + _mblog = MicroblogPanel(self.host, item) _mblog.setAcceptedGroup(item) - self.host.mpanels.insert(0,_mblog) - self.host.middle_panel.changePanel(self.data,self.host.mpanels[0]) + elif item_type=="CONTACT": + _mblog = MicroblogPanel(self.host, accept_all=True) + self.host.mpanels.remove(self) + self.host.mpanels.append(_mblog) + print "DEBUG" + grid = self.getParent() + row_idx, cell_idx = self._getCellAndRow(grid, event) + self.removeFromParent() + grid.setWidget(row_idx, cell_idx, _mblog) + print "index:", row_idx, cell_idx + #FIXME: delete object ? Check the right way with pyjamas + #self.host.middle_panel.changePanel(self.data,self.host.mpanels[0]) + +class EmptyPanel(DropCell, SimplePanel): + """Empty dropable panel""" - + def __init__(self, host): + SimplePanel.__init__(self) + self.host = host + _panel = HTMLPanel(" ") + self.add(_panel) + self.setHeight('100%') + DropCell.__init__(self) + class MicroblogEntry(SimplePanel): def __init__(self, body, author, timestamp): @@ -198,19 +222,27 @@ self.add(panel) -class MicroblogPanel(VerticalPanel): +class MicroblogPanel(DropCell, ScrollPanel): def __init__(self,host, title=' ', accept_all=False): + """Panel used to show microblog + @param title: title of the panel + @param accept_all: if true, show every message, without filtering jids""" self.host = host self.accept_all = accept_all title=title.replace('<','<').replace('>','>') - VerticalPanel.__init__(self) self.accepted_groups = [] _class = ['mb_panel_header'] if title == ' ': _class.append('empty_header') - self.add(HTMLPanel("
%s
" % (','.join(_class),title))) + ScrollPanel.__init__(self) + self.vpanel = VerticalPanel() + self.vpanel.add(HTMLPanel("
%s
" % (','.join(_class),title))) + self.vpanel.setWidth('100%') + self.setHeight('100%') self.setStyleName('microblogPanel') + self.add(self.vpanel) + DropCell.__init__(self) def addEntry(self, text, author=None, timestamp=None): """Add an entry to the panel @@ -218,7 +250,7 @@ @param author: who wrote the entry @param date: when the entry was written""" _entry = MicroblogEntry(text, author, timestamp) - self.add(_entry) + self.vpanel.insert(_entry,1) def setAcceptedGroup(self, group): """Set the group which can be displayed in this panel @@ -239,6 +271,7 @@ if self.host.contactPanel.isContactInGroup(group, jid): return True return False + class MiddlePannel(HorizontalPanel): @@ -271,18 +304,18 @@ self.setVerticalAlignment(HasAlignment.ALIGN_TOP) menu = Menu() - magic_box = host.magicBox + uni_box = host.uniBox self.middle_panel = MiddlePannel(self.host) self.middle_panel.setWidth('100%') self.add(menu) - self.add(magic_box) + self.add(uni_box) self.add(self.middle_panel) self.setCellHeight(menu, "5%") - self.setCellHeight(magic_box, "5%") - self.setCellVerticalAlignment(magic_box, HasAlignment.ALIGN_CENTER) - self.setCellHorizontalAlignment(magic_box, HasAlignment.ALIGN_CENTER) + self.setCellHeight(uni_box, "5%") + self.setCellVerticalAlignment(uni_box, HasAlignment.ALIGN_CENTER) + self.setCellHorizontalAlignment(uni_box, HasAlignment.ALIGN_CENTER) self.setCellHeight(self.middle_panel, "90%") self.setCellWidth(self.middle_panel, "100%") @@ -293,15 +326,15 @@ def onModuleLoad(self): self.bridge = BridgeCall() self.bridge_signals = BridgeSignals() - self.magicBox = MagicBox(self) - self.magicBox.addKey("@@: ") + self.uniBox = UniBox(self) + self.uniBox.addKey("@@: ") self.contactPanel = ContactPanel(self) self.panel = MainPanel(self) self.middle_panel = self.panel.middle_panel - self.mpanels = [MicroblogPanel(self, accept_all=True)] - self.middle_panel.changePanel(1,self.mpanels[0]) - self.middle_panel.changePanel(0,EmptyPanel(self, 0)) - self.middle_panel.changePanel(2,EmptyPanel(self, 2)) + self.mpanels = [EmptyPanel(self), MicroblogPanel(self, accept_all=True), EmptyPanel(self)] + self.middle_panel.changePanel(0,self.mpanels[0]) + self.middle_panel.changePanel(1,self.mpanels[1]) + self.middle_panel.changePanel(2,self.mpanels[2]) self._dialog = None RootPanel().add(self.panel) self._register = RegisterCall() @@ -349,8 +382,14 @@ if not data.has_key('content'): print ("WARNING: No content found in microblog data") return + print dir('') + if data.has_key('groups'): + _groups = set(data['groups'].split() if data['groups'] else []) + else: + _groups=None + print "_groups=",_groups for panel in self.mpanels: - if isinstance(panel,MicroblogPanel) and panel.isJidAccepted(sender): + if isinstance(panel,MicroblogPanel) and (panel.isJidAccepted(sender) or _groups == None or _groups.intersection(panel.accepted_groups)): print "sender:",sender content = data['content'] author = data.get('author')