# HG changeset patch # User Goffi # Date 1297644367 -3600 # Node ID a663b9955cf3e46557d3d49c52a4b9fe023db715 # Parent c8d3821efc360b9098a2cee5f8644131bd475497 drap and drop first draft diff -r c8d3821efc36 -r a663b9955cf3 contact.py --- a/contact.py Sun Feb 13 16:21:45 2011 +0100 +++ b/contact.py Mon Feb 14 01:46:07 2011 +0100 @@ -27,12 +27,38 @@ from pyjamas import Window from pyjamas import DOM +from pyjamas.dnd import makeDraggable +from pyjamas.ui.DragWidget import DragWidget, DragContainer -class GroupLabel(Label): +class GroupLabel(DragWidget, Label): def __init__(self, group): - Label.__init__(self, group) + Label.__init__(self, group) #, Element=DOM.createElement('div') self.group = group self.setStyleName('group') + DragWidget.__init__(self) + + def onDragStart(self, event): + print "onDragStart" + dt = event.dataTransfer + #self.addMessage('types is %s' % dt.getTypes()) + dt.setData('Text', self.group) + #self.addMessage('after setting, len is %s' % len(dt.dataStore.items)) + #self.addMessage('types is %s' % dt.getTypes()) + dt.setDragImage(self.getElement(), 15, 15) + #dt.effectAllowed = 'copy' + #self.addMessage('mode is %s' % dt.dataStore.items.mode) + + def onDragEnd(self, event): + print "onDragEnd" + #self.addMessage('Drag ended') + #self.addMessage('mode is %s' % dt._data.mode) + + def addMessage(self, message): + print "addMessage" + #parent = self.getParent() + #while not hasattr(parent, 'addMessage'): + # parent = parent.getParent() + #parent.addMessage(message) class ContactLabel(Label): def __init__(self, jid, name=None): diff -r c8d3821efc36 -r a663b9955cf3 libervia.py --- a/libervia.py Sun Feb 13 16:21:45 2011 +0100 +++ b/libervia.py Mon Feb 14 01:46:07 2011 +0100 @@ -30,8 +30,9 @@ from pyjamas.ui import HasAlignment from pyjamas.ui.MenuBar import MenuBar from pyjamas.ui.MenuItem import MenuItem +from pyjamas.ui.AutoComplete import AutoCompleteTextBox +from pyjamas.ui.DropWidget import DropWidget from pyjamas import Window -from pyjamas.ui.AutoComplete import AutoCompleteTextBox from pyjamas.JSONService import JSONProxy from register import RegisterPanel, RegisterBox from pyjamas import DOM @@ -158,6 +159,44 @@ if contact.jid in self.groups[sender.group]: contact.removeStyleName("selected") +class EmptyPanel(DropWidget, SimplePanel): + """Empty dropable panel""" + + def __init__(self): + SimplePanel.__init__(self) + _panel = HTMLPanel(" ") + #_panel.setHeight('100%') + #_panel.setWidth('100%') + self.add(_panel) + self.setHeight('100%') + DropWidget.__init__(self) + + def onDragEnter(self, event): + print "Empty Panel: onDragEnter" + self.addStyleName('dragover') + DOM.eventPreventDefault(event) + + def onDragLeave(self, event): + print "Empty Panel: onDragLeave" + self.removeStyleName('dragover') + + def onDragOver(self, event): + print "Empty Panel: onDragOver" + DOM.eventPreventDefault(event) + + def onDrop(self, event): + print "Empty Panel: onDragOver" + dt = event.dataTransfer + #'text', 'text/plain', and 'Text' are equivalent. + try: + item = dt.getData("text/plain") + print "message: %s" % item + except: + print "no message found" + DOM.eventPreventDefault(event) + + + class MicroblogEntry(SimplePanel): def __init__(self, body, author, timestamp): @@ -165,7 +204,7 @@ _datetime = datetime.fromtimestamp(timestamp) - panel = HTMLPanel("
%(author)s on

%(body)s

" % + panel = HTMLPanel("
on
%(body)s
" % {"author": author, "timestamp": _datetime, "body": body} @@ -201,6 +240,7 @@ self.setCellWidth(self._left, "15%") self.add(self._right) self.setCellWidth(self._right, "85%") + self.setHeight('100%') def changePanel(self, idx, panel): print "panel:",panel @@ -243,6 +283,8 @@ self.middle_panel = self.panel.middle_panel self.mpanels = [MicroblogPanel()] self.middle_panel.changePanel(1,self.mpanels[0]) + self.middle_panel.changePanel(0,EmptyPanel()) + self.middle_panel.changePanel(2,EmptyPanel()) self._dialog = None RootPanel().add(self.panel) self._register = RegisterCall()