changeset 6:a663b9955cf3

drap and drop first draft
author Goffi <goffi@goffi.org>
date Mon, 14 Feb 2011 01:46:07 +0100
parents c8d3821efc36
children 7acca1ce1ca4
files contact.py libervia.py
diffstat 2 files changed, 72 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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):
--- 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("&nbsp;")
+        #_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("<div class='mb_entry_author'>%(author)s on <span class='mb_entry_timestamp'>%(timestamp)s</span></div><p class='mb_entry_body'>%(body)s</p>" %
+        panel = HTMLPanel("<div class='mb_entry_header'><span class='mb_entry_author'>%(author)s</span> on <span class='mb_entry_timestamp'>%(timestamp)s</span></div><div class='mb_entry_body'>%(body)s</div>" %
             {"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()