<s> import pyjd <EOL> from pyjamas . ui import HasVerticalAlignment <EOL> from pyjamas . Timer import Timer <EOL> from datetime import datetime <EOL> from __pyjamas__ import doc <EOL> from pyjamas . ui . Widget import Widget <EOL> from pyjamas import DOM <EOL> from pyjamas . ui . Label import Label <EOL> from pyjamas . ui . Button import Button <EOL> from pyjamas . ui . HTML import HTML <EOL> from pyjamas . ui . RootPanel import RootPanel <EOL> from pyjamas . ui . VerticalPanel import VerticalPanel <EOL> from pyjamas . ui . HorizontalPanel import HorizontalPanel <EOL> from pyjamas . Canvas . GWTCanvas import GWTCanvas <EOL> import pyjamas . Canvas . Color as Color <EOL> from pyjamas . dnd import makeDraggable <EOL> from pyjamas . ui . DragWidget import DragWidget , DragContainer <EOL> from pyjamas . ui . DropWidget import DropWidget <EOL> from pyjamas . ui . Panel import Panel <EOL> from pyjamas . dnd import getTypes <EOL> from pyjamas import Window <EOL> import json <EOL> class DNDDemos ( VerticalPanel ) : <EOL> def __init__ ( self ) : <EOL> VerticalPanel . __init__ ( self ) <EOL> self . width = '<STR_LIT>' <EOL> self . setID ( '<STR_LIT:content>' ) <EOL> self . add ( TopVerbage ( ) ) <EOL> self . add ( NewSchool ( ) ) <EOL> self . add ( Delegated ( ) ) <EOL> self . add ( ImageDrop ( ) ) <EOL> self . add ( DataTransferDemo ( ) ) <EOL> self . add ( DragEffects ( ) ) <EOL> self . add ( AbsolutePosition ( ) ) <EOL> self . add ( MultiTargetDemo ( ) ) <EOL> class AddablePanel ( Panel ) : <EOL> def __init__ ( self , ** kw ) : <EOL> Panel . __init__ ( self , ** kw ) <EOL> def add ( self , widget , container = None ) : <EOL> self . adopt ( widget , self . getElement ( ) ) <EOL> self . children . append ( widget ) <EOL> def remove ( self , widget ) : <EOL> self . disown ( widget ) <EOL> self . children . remove ( widget ) <EOL> class TopVerbage ( AddablePanel ) : <EOL> title = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> AddablePanel . __init__ ( self , Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> self . setID ( '<STR_LIT>' ) <EOL> img = '<STR_LIT>' <EOL> self . add ( HTML ( '<STR_LIT>' % ( self . title % img , ) ) ) <EOL> self . add ( HTML ( <EOL> """<STR_LIT>""" <EOL> ) ) <EOL> class DragWidget1 ( DragWidget , Label ) : <EOL> def __init__ ( self ) : <EOL> Label . __init__ ( self , Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> self . setText ( "<STR_LIT>" ) <EOL> DragWidget . __init__ ( self ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> def onDragStart ( self , event ) : <EOL> dt = event . dataTransfer <EOL> dt . setData ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> dt . effectAllowed = '<STR_LIT>' <EOL> def onDragEnd ( self , event ) : <EOL> self . addMessage ( '<STR_LIT>' ) <EOL> def addMessage ( self , message ) : <EOL> parent = self . getParent ( ) <EOL> while not hasattr ( parent , '<STR_LIT>' ) : <EOL> parent = parent . getParent ( ) <EOL> parent . addMessage ( message ) <EOL> class DropWidget1 ( DropWidget , Label ) : <EOL> def __init__ ( self ) : <EOL> Label . __init__ ( self , Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> DropWidget . __init__ ( self ) <EOL> self . setText ( "<STR_LIT>" ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> def onDragEnter ( self , event ) : <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDragLeave ( self , event ) : <EOL> self . removeStyleName ( '<STR_LIT>' ) <EOL> def onDragOver ( self , event ) : <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDrop ( self , event ) : <EOL> dt = event . dataTransfer <EOL> try : <EOL> item = dt . getData ( "<STR_LIT>" ) <EOL> self . addMessage ( item ) <EOL> except : <EOL> self . addMessage ( '<STR_LIT>' ) <EOL> DOM . eventPreventDefault ( event ) <EOL> def addMessage ( self , message ) : <EOL> parent = self . getParent ( ) <EOL> while not hasattr ( parent , '<STR_LIT>' ) : <EOL> parent = parent . getParent ( ) <EOL> parent . addMessage ( message ) <EOL> class Messages ( Widget ) : <EOL> def __init__ ( self ) : <EOL> Widget . __init__ ( self , Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> def addMessage ( self , text ) : <EOL> d = datetime . now ( ) . strftime ( "<STR_LIT>" ) <EOL> li = DOM . createElement ( '<STR_LIT>' ) <EOL> DOM . setInnerHTML ( li , <EOL> '<STR_LIT>' % ( <EOL> d , text ) ) <EOL> DOM . insertChild ( self . element , li , <NUM_LIT:0> ) <EOL> class DNDDemo ( AddablePanel ) : <EOL> """<STR_LIT>""" <EOL> title = "<STR_LIT>" <EOL> id = '<STR_LIT:none>' <EOL> drag_widget = None <EOL> drop_widget = None <EOL> def __init__ ( self ) : <EOL> AddablePanel . __init__ ( self , Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> self . setID ( self . id ) <EOL> self . h2 = HTML ( '<STR_LIT>' % self . title ) <EOL> self . append ( self . h2 ) <EOL> demo_div = AddablePanel ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> demo_div . setStyleName ( '<STR_LIT>' ) <EOL> top_frame = HorizontalPanel ( ) <EOL> g = self . drag_widget <EOL> if g is not None : <EOL> top_frame . add ( g ) <EOL> p = self . drop_widget <EOL> if p is not None : <EOL> top_frame . add ( p ) <EOL> demo_div . add ( top_frame ) <EOL> self . messages = Messages ( ) <EOL> demo_div . append ( self . messages ) <EOL> self . add ( demo_div ) <EOL> def addMessage ( self , message ) : <EOL> self . messages . addMessage ( message ) <EOL> class NewSchool ( DNDDemo ) : <EOL> def __init__ ( self ) : <EOL> self . title = "<STR_LIT>" <EOL> self . id = '<STR_LIT>' <EOL> self . drag_widget = DragWidget1 ( ) <EOL> self . drop_widget = DropWidget1 ( ) <EOL> DNDDemo . __init__ ( self ) <EOL> class DragWidget2 ( DragContainer , AddablePanel ) : <EOL> def onDragStart ( self , event ) : <EOL> target = DOM . eventGetTarget ( event ) <EOL> dt = event . dataTransfer <EOL> dt . setData ( "<STR_LIT>" , "<STR_LIT>" % target . id ) <EOL> dt . effectAllowed = '<STR_LIT>' <EOL> def __init__ ( self ) : <EOL> self . setElement ( DOM . createElement ( '<STR_LIT>' ) ) <EOL> DragContainer . __init__ ( self ) <EOL> AddablePanel . __init__ ( self ) <EOL> def onLoad ( self ) : <EOL> link = self . makeLink ( ) <EOL> link . addClickListener ( self ) <EOL> li = AddablePanel ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> li . add ( link ) <EOL> self . button = li <EOL> self . add ( self . button ) <EOL> for k in range ( <NUM_LIT:3> ) : <EOL> self . addDragWidget ( ) <EOL> def addMessage ( self , message ) : <EOL> parent = self . getParent ( ) <EOL> while not hasattr ( parent , '<STR_LIT>' ) : <EOL> parent = parent . getParent ( ) <EOL> parent . addMessage ( message ) <EOL> def addDragWidget ( self ) : <EOL> self . remove ( self . button ) <EOL> s = len ( self . children ) <EOL> w = Label ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> w . setID ( '<STR_LIT>' + str ( s ) ) <EOL> w . setStyleName ( '<STR_LIT>' ) <EOL> w . setText ( '<STR_LIT>' + str ( s ) ) <EOL> self . add ( w ) <EOL> makeDraggable ( w ) <EOL> self . add ( self . button ) <EOL> def makeLink ( self ) : <EOL> link = Button ( ) <EOL> link . setText ( "<STR_LIT>" ) <EOL> return link <EOL> def onClick ( self , sender ) : <EOL> self . addDragWidget ( ) <EOL> class DropWidget2 ( DropWidget , AddablePanel ) : <EOL> def __init__ ( self ) : <EOL> self . setElement ( DOM . createElement ( '<STR_LIT>' ) ) <EOL> DropWidget . __init__ ( self ) <EOL> AddablePanel . __init__ ( self ) <EOL> def onLoad ( self ) : <EOL> button = self . makeButton ( ) <EOL> button . addClickListener ( self ) <EOL> li = AddablePanel ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> li . add ( button ) <EOL> self . button = li <EOL> self . add ( self . button ) <EOL> for k in range ( <NUM_LIT:3> ) : <EOL> self . addDropWidget ( ) <EOL> def addDropWidget ( self ) : <EOL> self . remove ( self . button ) <EOL> s = len ( self . children ) <EOL> w = Label ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> w . setID ( '<STR_LIT>' + str ( s ) ) <EOL> w . setStyleName ( '<STR_LIT>' ) <EOL> w . setText ( '<STR_LIT>' + str ( s ) ) <EOL> self . append ( w ) <EOL> self . append ( self . button ) <EOL> def onDragEnter ( self , event ) : <EOL> target = DOM . eventGetTarget ( event ) <EOL> t = Widget ( Element = target ) <EOL> try : <EOL> class_names = t . getStyleName ( ) <EOL> except : <EOL> class_names = None <EOL> dt = event . dataTransfer <EOL> dt . dropEffect = '<STR_LIT>' <EOL> if class_names is not None : <EOL> if '<STR_LIT>' in class_names : <EOL> t . addStyleName ( '<STR_LIT>' ) <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDragOver ( self , event ) : <EOL> target = DOM . eventGetTarget ( event ) <EOL> t = Widget ( Element = target ) <EOL> dt = event . dataTransfer <EOL> dt . dropEffect = '<STR_LIT>' <EOL> class_names = t . getStyleName ( ) <EOL> if class_names is not None : <EOL> if '<STR_LIT>' in class_names : <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDragLeave ( self , event ) : <EOL> target = DOM . eventGetTarget ( event ) <EOL> t = Widget ( Element = target ) <EOL> try : <EOL> class_names = t . getStyleName ( ) <EOL> except : <EOL> class_names = None <EOL> if class_names is not None : <EOL> if '<STR_LIT>' in class_names : <EOL> t . removeStyleName ( '<STR_LIT>' ) <EOL> def onDrop ( self , event ) : <EOL> dt = event . dataTransfer <EOL> text = dt . getData ( '<STR_LIT>' ) <EOL> target = DOM . eventGetTarget ( event ) <EOL> t = Widget ( Element = target ) <EOL> class_names = t . getStyleName ( ) <EOL> DOM . eventPreventDefault ( event ) <EOL> if class_names is not None : <EOL> if '<STR_LIT>' in class_names : <EOL> self . addMessage ( '<STR_LIT>' % ( text , target . id ) ) <EOL> return <EOL> def makeButton ( self ) : <EOL> button = Button ( "<STR_LIT>" ) <EOL> return button <EOL> def onClick ( self , sender ) : <EOL> self . addDropWidget ( ) <EOL> def addMessage ( self , message ) : <EOL> parent = self . getParent ( ) <EOL> while not hasattr ( parent , '<STR_LIT>' ) : <EOL> parent = parent . getParent ( ) <EOL> parent . addMessage ( message ) <EOL> class Delegated ( DNDDemo ) : <EOL> title = "<STR_LIT>" <EOL> id = "<STR_LIT>" <EOL> def __init__ ( self ) : <EOL> self . drag_widget = DragWidget2 ( ) <EOL> drag = self . drag_widget <EOL> drag . setStyleName ( '<STR_LIT>' ) <EOL> drag . addStyleName ( '<STR_LIT>' ) <EOL> self . drop_widget = DropWidget2 ( ) <EOL> drop = self . drop_widget <EOL> drop . setStyleName ( '<STR_LIT>' ) <EOL> drop . addStyleName ( '<STR_LIT>' ) <EOL> DNDDemo . __init__ ( self ) <EOL> class DragWidget3 ( DragWidget2 ) : <EOL> def __init__ ( self ) : <EOL> self . setElement ( DOM . createElement ( '<STR_LIT>' ) ) <EOL> super ( DragWidget3 , self ) . __init__ ( ) <EOL> def onLoad ( self ) : <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> for k in range ( <NUM_LIT:4> ) : <EOL> self . addDragWidget ( ) <EOL> def makeCanvasImg ( self , canvas ) : <EOL> ctx = canvas <EOL> ctx . beginPath ( ) <EOL> ctx . setLineWidth ( <NUM_LIT:3> ) <EOL> ctx . setStrokeStyle ( Color . ORANGE ) <EOL> ctx . moveTo ( <NUM_LIT> , <NUM_LIT> ) <EOL> ctx . lineTo ( <NUM_LIT:50> , <NUM_LIT:50> ) <EOL> ctx . lineTo ( <NUM_LIT> , <NUM_LIT:50> ) <EOL> ctx . lineTo ( <NUM_LIT> , <NUM_LIT> ) <EOL> ctx . stroke ( ) <EOL> def onDragStart ( self , event ) : <EOL> dt = event . dataTransfer <EOL> target = DOM . eventGetTarget ( event ) <EOL> target = Widget ( Element = target ) <EOL> id = target . getID ( ) <EOL> dt . setData ( "<STR_LIT>" , "<STR_LIT>" % target . getID ( ) ) <EOL> dt . effectAllowed = '<STR_LIT>' <EOL> if id == '<STR_LIT>' : <EOL> parent = self . getParent ( ) <EOL> while not hasattr ( parent , '<STR_LIT>' ) : <EOL> parent = parent . getParent ( ) <EOL> dt . setDragImage ( parent . h2 . getElement ( ) , <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> elif id == '<STR_LIT>' : <EOL> dt . setDragImage ( doc ( ) . getElementById ( '<STR_LIT>' ) , <NUM_LIT:10> , <NUM_LIT:10> ) <EOL> elif id == '<STR_LIT>' : <EOL> ctx = GWTCanvas ( <NUM_LIT:50> , <NUM_LIT:50> ) <EOL> self . makeCanvasImg ( ctx ) <EOL> try : <EOL> img = DOM . createImg ( ) <EOL> DOM . setAttribute ( img , '<STR_LIT:src>' , ctx . canvas . toDataURL ( ) ) <EOL> dt . setDragImage ( img , <NUM_LIT> , <NUM_LIT> ) <EOL> except : <EOL> dt . setDragImage ( ctx . canvas , <NUM_LIT> , <NUM_LIT> ) <EOL> def addDragWidget ( self ) : <EOL> s = len ( self . children ) <EOL> w = Label ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> w . setStyleName ( '<STR_LIT>' ) <EOL> w . setID ( '<STR_LIT>' + str ( s ) ) <EOL> texts = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> w . setText ( texts [ s ] ) <EOL> self . add ( w ) <EOL> makeDraggable ( w ) <EOL> class DropWidget3 ( DropWidget1 ) : <EOL> def onLoad ( self ) : <EOL> self . setID ( "<STR_LIT>" ) <EOL> class ImageDrop ( DNDDemo ) : <EOL> def __init__ ( self ) : <EOL> self . title = "<STR_LIT>" <EOL> self . id = "<STR_LIT>" <EOL> self . drop_widget = DropWidget3 ( ) <EOL> self . drag_widget = DragWidget3 ( ) <EOL> DNDDemo . __init__ ( self ) <EOL> class DragWidget4 ( DragWidget2 ) : <EOL> def __init__ ( self ) : <EOL> self . setElement ( DOM . createElement ( '<STR_LIT>' ) ) <EOL> super ( DragWidget4 , self ) . __init__ ( ) <EOL> def onLoad ( self ) : <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> self . following_text = HTML ( """<STR_LIT>""" ) <EOL> for k in range ( <NUM_LIT:3> ) : <EOL> self . addDragWidget ( ) <EOL> self . append ( self . following_text ) <EOL> def addDragWidget ( self ) : <EOL> s = len ( self . children ) <EOL> w = Label ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> w . setID ( '<STR_LIT>' + str ( s ) ) <EOL> w . setStyleName ( '<STR_LIT>' ) <EOL> texts = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> w . setText ( texts [ s ] ) <EOL> self . append ( w ) <EOL> makeDraggable ( w ) <EOL> def onDragStart ( self , event ) : <EOL> dt = event . dataTransfer <EOL> target = DOM . eventGetTarget ( event ) <EOL> target = Widget ( Element = target ) <EOL> try : <EOL> id = target . getID ( ) <EOL> except : <EOL> id = '<STR_LIT>' <EOL> if id == '<STR_LIT>' : <EOL> dt . setData ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif id == '<STR_LIT>' : <EOL> logo = doc ( ) . getElementById ( '<STR_LIT>' ) <EOL> logo_parent_element = DOM . getParent ( logo ) <EOL> text = DOM . getInnerText ( logo_parent_element ) <EOL> html = DOM . getInnerHTML ( logo_parent_element ) <EOL> uri = DOM . getAttribute ( logo , '<STR_LIT:src>' ) <EOL> dt . setData ( '<STR_LIT>' , text ) <EOL> dt . setData ( '<STR_LIT>' , html ) <EOL> dt . setData ( '<STR_LIT>' , uri ) <EOL> elif id == '<STR_LIT>' : <EOL> dt . setData ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class DropWidget4 ( DropWidget1 ) : <EOL> def onLoad ( self ) : <EOL> self . setText ( '''<STR_LIT>''' ) <EOL> self . setID ( '<STR_LIT>' ) <EOL> def onDrop ( self , event ) : <EOL> dt = event . dataTransfer <EOL> types = getTypes ( event ) <EOL> self . addMessage ( "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( types ) ) <EOL> parent = self . getParent ( ) <EOL> parent . clearContent ( ) <EOL> self . addMessage ( '<STR_LIT>' + str ( dt ) ) <EOL> types . sort ( ) <EOL> for ctype in types : <EOL> data = dt . getData ( ctype ) <EOL> if ctype == '<STR_LIT>' : <EOL> file_names = [ ] <EOL> files = dt . files <EOL> for idx in range ( files . length ) : <EOL> item = files . item ( idx ) <EOL> try : <EOL> name = item . name <EOL> except : <EOL> name = item . fileName <EOL> file_names . append ( name ) <EOL> data = '<STR_LIT>' . join ( file_names ) <EOL> parent . addContent ( ctype , data ) <EOL> DOM . eventPreventDefault ( event ) <EOL> DOM . eventCancelBubble ( event , True ) <EOL> def onDragOver ( self , event ) : <EOL> types = getTypes ( event ) <EOL> if not '<STR_LIT>' in types : <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDragEnter ( self , event ) : <EOL> types = getTypes ( event ) <EOL> if not '<STR_LIT>' in types : <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> DOM . eventPreventDefault ( event ) <EOL> class ContentDisplay ( Label , AddablePanel ) : <EOL> def __init__ ( self , ctype , data ) : <EOL> Label . __init__ ( self ) <EOL> AddablePanel . __init__ ( self ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . setText ( "<STR_LIT>" % ctype ) <EOL> self . content = HTML ( data , StyleName = '<STR_LIT:content>' ) <EOL> self . append ( self . content ) <EOL> class DropWidgetPanel4 ( AddablePanel ) : <EOL> def __init__ ( self ) : <EOL> AddablePanel . __init__ ( self , Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> def onLoad ( self ) : <EOL> self . drop_widget = DropWidget4 ( ) <EOL> self . add ( self . drop_widget ) <EOL> self . contentPanel = AddablePanel ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> self . add ( self . contentPanel ) <EOL> def clearContent ( self ) : <EOL> self . contentPanel . clear ( ) <EOL> def addContent ( self , ctype , data ) : <EOL> display = ContentDisplay ( ctype , data ) <EOL> self . contentPanel . add ( display ) <EOL> class DataTransferDemo ( DNDDemo ) : <EOL> def __init__ ( self ) : <EOL> self . title = "<STR_LIT>" <EOL> self . id = "<STR_LIT>" <EOL> self . drag_widget = DragWidget4 ( ) <EOL> self . drop_widget = DropWidgetPanel4 ( ) <EOL> DNDDemo . __init__ ( self ) <EOL> class DragWidget5 ( DragWidget2 ) : <EOL> def onDragStart ( self , event ) : <EOL> target = DOM . eventGetTarget ( event ) <EOL> dt = event . dataTransfer <EOL> try : <EOL> id = Widget ( Element = target ) . getID ( ) <EOL> except : <EOL> id = '<STR_LIT>' <EOL> dt . setData ( "<STR_LIT>" , "<STR_LIT>" % id ) <EOL> effect_allowed = self . data [ int ( id [ - <NUM_LIT:1> ] ) ] <EOL> dt . effectAllowed = effect_allowed <EOL> def onLoad ( self ) : <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> self . data = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:all>' , '<STR_LIT:none>' ] <EOL> for k in range ( <NUM_LIT:5> ) : <EOL> self . addDragWidget ( ) <EOL> def addDragWidget ( self ) : <EOL> s = len ( self . children ) <EOL> w = Label ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> w . setID ( '<STR_LIT>' + str ( s ) ) <EOL> w . setStyleName ( '<STR_LIT>' ) <EOL> w . setText ( '<STR_LIT>' % ( s , self . data [ s ] ) ) <EOL> self . add ( w ) <EOL> makeDraggable ( w ) <EOL> class DropWidget5 ( DropWidget2 ) : <EOL> def onLoad ( self ) : <EOL> self . data = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:all>' , '<STR_LIT:none>' ] <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> for k in range ( <NUM_LIT:5> ) : <EOL> self . addDropWidget ( ) <EOL> def addDropWidget ( self ) : <EOL> s = len ( self . children ) <EOL> w = Label ( Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> w . setID ( '<STR_LIT>' + str ( s ) ) <EOL> w . setStyleName ( '<STR_LIT>' ) <EOL> w . setText ( '<STR_LIT>' % ( s , self . data [ s ] ) ) <EOL> self . append ( w ) <EOL> def onDragEnter ( self , event ) : <EOL> target = DOM . eventGetTarget ( event ) <EOL> t = Widget ( Element = target ) <EOL> try : <EOL> class_names = t . getStyleName ( ) <EOL> except : <EOL> class_names = None <EOL> if class_names is not None : <EOL> if '<STR_LIT>' in class_names : <EOL> t . addStyleName ( '<STR_LIT>' ) <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDragOver ( self , event ) : <EOL> target = DOM . eventGetTarget ( event ) <EOL> t = Widget ( Element = target ) <EOL> class_names = t . getStyleName ( ) <EOL> if class_names is not None : <EOL> if '<STR_LIT>' in class_names : <EOL> dt = event . dataTransfer <EOL> id = Widget ( Element = target ) . getID ( ) <EOL> drop_effect = self . data [ int ( id [ - <NUM_LIT:1> ] ) ] <EOL> dt . dropEffect = drop_effect <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDragLeave ( self , event ) : <EOL> target = DOM . eventGetTarget ( event ) <EOL> t = Widget ( Element = target ) <EOL> try : <EOL> class_names = t . getStyleName ( ) <EOL> except : <EOL> class_names = None <EOL> if class_names is not None : <EOL> if '<STR_LIT>' in class_names : <EOL> t . removeStyleName ( '<STR_LIT>' ) <EOL> def onDrop ( self , event ) : <EOL> dt = event . dataTransfer <EOL> text = dt . getData ( '<STR_LIT>' ) <EOL> target = DOM . eventGetTarget ( event ) <EOL> t = Widget ( Element = target ) <EOL> class_names = t . getStyleName ( ) <EOL> if class_names is not None : <EOL> if '<STR_LIT>' in class_names : <EOL> self . addMessage ( '<STR_LIT>' <EOL> % ( text , target . id , dt . effectAllowed , dt . dropEffect ) ) <EOL> DOM . eventPreventDefault ( event ) <EOL> class DragEffects ( DNDDemo ) : <EOL> def __init__ ( self ) : <EOL> self . title = "<STR_LIT>" <EOL> self . id = "<STR_LIT>" <EOL> self . drag_widget = DragWidget5 ( ) <EOL> self . drop_widget = DropWidget5 ( ) <EOL> DNDDemo . __init__ ( self ) <EOL> class AbsolutePosition ( DNDDemo ) : <EOL> def __init__ ( self ) : <EOL> self . title = "<STR_LIT>" <EOL> self . id = "<STR_LIT>" <EOL> self . drop_widget = Drop6Container ( ) <EOL> DNDDemo . __init__ ( self ) <EOL> class Drop6Container ( HorizontalPanel ) : <EOL> def __init__ ( self ) : <EOL> HorizontalPanel . __init__ ( self ) <EOL> left = DropWidget6 ( ) <EOL> right = DropWidget6 ( ) <EOL> self . setSpacing ( '<STR_LIT>' ) <EOL> drag = DragWidget6 ( "<STR_LIT>" ) <EOL> drag2 = DragWidget6 ( "<STR_LIT>" ) <EOL> left . add ( drag2 ) <EOL> drag2 . setStyleAttribute ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> drag2 . setStyleAttribute ( '<STR_LIT:left>' , '<STR_LIT:0>' ) <EOL> makeDraggable ( drag2 ) <EOL> left . add ( drag ) <EOL> drag . setStyleAttribute ( '<STR_LIT>' , '<STR_LIT:0>' ) <EOL> drag . setStyleAttribute ( '<STR_LIT:left>' , '<STR_LIT:100>' ) <EOL> makeDraggable ( drag ) <EOL> self . add ( left ) <EOL> self . add ( right ) <EOL> class DragWidget6 ( Label ) : <EOL> def __init__ ( self , text ) : <EOL> Label . __init__ ( self , text ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . setStyleAttribute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class DropWidget6 ( DropWidget , DragContainer , AddablePanel ) : <EOL> def __init__ ( self ) : <EOL> AddablePanel . __init__ ( self , Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> DropWidget . __init__ ( self ) <EOL> DragContainer . __init__ ( self ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . setStyleAttribute ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . setSize ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def onDragStart ( self , event ) : <EOL> dt = event . dataTransfer <EOL> target = DOM . eventGetTarget ( event ) <EOL> clientX = event . clientX <EOL> clientY = event . clientY <EOL> absx = clientX + Window . getScrollLeft ( ) <EOL> absy = clientY + Window . getScrollTop ( ) <EOL> package = json . dumps ( { "<STR_LIT:text>" : DOM . getInnerText ( target ) , <EOL> "<STR_LIT>" : absx - DOM . getAbsoluteLeft ( target ) , <EOL> "<STR_LIT>" : absy - DOM . getAbsoluteTop ( target ) } ) <EOL> dt . setData ( '<STR_LIT:text>' , package ) <EOL> dt . allowedEffects = '<STR_LIT>' <EOL> self . movingWidget = None <EOL> for widget in self . children : <EOL> if target == widget . getElement ( ) : <EOL> self . movingWidget = widget <EOL> def onDragLeave ( self , event ) : <EOL> dt = event . dataTransfer <EOL> dt . dropEffect = '<STR_LIT:none>' <EOL> def onDrag ( self , event ) : <EOL> self . movingWidget . addStyleName ( '<STR_LIT>' ) <EOL> def onDragEnd ( self , event ) : <EOL> dt = event . dataTransfer <EOL> self . addMessage ( '<STR_LIT>' % dt . dropEffect ) <EOL> if dt . dropEffect != '<STR_LIT:none>' : <EOL> self . remove ( self . movingWidget ) <EOL> else : <EOL> def ontimer ( timer ) : <EOL> self . movingWidget . removeStyleName ( '<STR_LIT>' ) <EOL> Timer ( <NUM_LIT> , notify = ontimer ) <EOL> def onDragEnter ( self , event ) : <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDragOver ( self , event ) : <EOL> dt = event . dataTransfer <EOL> dt . dropEffect = '<STR_LIT>' <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDrop ( self , event ) : <EOL> dt = event . dataTransfer <EOL> text = dt . getData ( '<STR_LIT:text>' ) <EOL> package = json . loads ( text ) <EOL> x = DOM . eventGetClientX ( event ) <EOL> y = DOM . eventGetClientY ( event ) <EOL> scrollY = Window . getScrollTop ( ) <EOL> scrollX = Window . getScrollLeft ( ) <EOL> offsetX = int ( package [ '<STR_LIT>' ] ) <EOL> offsetY = int ( package [ '<STR_LIT>' ] ) <EOL> at = self . getAbsoluteTop ( ) <EOL> al = self . getAbsoluteLeft ( ) <EOL> posX , posY = x - ( al - scrollX ) , y - ( at - scrollY ) <EOL> w = DragWidget6 ( package [ '<STR_LIT:text>' ] ) <EOL> self . add ( w ) <EOL> makeDraggable ( w ) <EOL> w . setStyleAttribute ( '<STR_LIT:left>' , posX - offsetX ) <EOL> w . setStyleAttribute ( '<STR_LIT>' , posY - offsetY ) <EOL> w . removeStyleName ( '<STR_LIT>' ) <EOL> self . addMessage ( <EOL> "<STR_LIT>" % ( <EOL> at , al , y , x , scrollY , scrollX , posY , posX ) ) <EOL> DOM . eventPreventDefault ( event ) <EOL> def addMessage ( self , message ) : <EOL> parent = self . getParent ( ) <EOL> while not hasattr ( parent , '<STR_LIT>' ) : <EOL> parent = parent . getParent ( ) <EOL> parent . addMessage ( message ) <EOL> class StudentWidget ( Label ) : <EOL> def __init__ ( self , name , age ) : <EOL> Label . __init__ ( self , Element = DOM . createElement ( '<STR_LIT>' ) ) <EOL> self . student_name = name <EOL> self . age = int ( age ) <EOL> self . setText ( "<STR_LIT>" % ( self . student_name , self . age ) ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> def onClick ( self , sender ) : <EOL> self . addMessage ( "<STR_LIT>" ) <EOL> def addMessage ( self , message ) : <EOL> parent = self . getParent ( ) <EOL> while not hasattr ( parent , '<STR_LIT>' ) : <EOL> parent = parent . getParent ( ) <EOL> parent . addMessage ( message ) <EOL> class StudentContainer ( DragContainer , DropWidget , VerticalPanel ) : <EOL> def __init__ ( self , min_age , max_age , id ) : <EOL> self . min_age = min_age <EOL> self . max_age = max_age <EOL> VerticalPanel . __init__ ( self ) <EOL> DropWidget . __init__ ( self ) <EOL> DragContainer . __init__ ( self ) <EOL> self . setID ( id ) <EOL> self . setWidth ( <NUM_LIT:200> ) <EOL> self . setHeight ( <NUM_LIT> ) <EOL> self . setVerticalAlignment ( HasVerticalAlignment . ALIGN_TOP ) <EOL> self . setStyleName ( '<STR_LIT>' ) <EOL> self . addTitle ( ) <EOL> def getNames ( self ) : <EOL> names = [ ] <EOL> for item in self . children : <EOL> if isinstance ( item , StudentWidget ) : <EOL> names . append ( ( item . student_name , item . age ) ) <EOL> return names <EOL> def addTitle ( self ) : <EOL> self . append ( Label ( "<STR_LIT>" % ( self . min_age , self . max_age ) ) ) <EOL> def addStudent ( self , name , age ) : <EOL> new_names = self . getNames ( ) <EOL> found = False <EOL> for item in new_names : <EOL> if item == ( name , age ) : <EOL> found = True <EOL> break <EOL> if not found : <EOL> new_names . append ( ( name , age ) ) <EOL> new_names . sort ( ) <EOL> while len ( self . children ) : <EOL> self . remove ( self . children [ <NUM_LIT:0> ] ) <EOL> self . addTitle ( ) <EOL> for student in new_names : <EOL> sw = StudentWidget ( student [ <NUM_LIT:0> ] , student [ <NUM_LIT:1> ] ) <EOL> makeDraggable ( sw ) <EOL> self . append ( sw ) <EOL> self . setCellVerticalAlignment ( sw , HasVerticalAlignment . ALIGN_TOP ) <EOL> def onDragStart ( self , event ) : <EOL> self . removeStyleName ( '<STR_LIT>' ) <EOL> dt = event . dataTransfer <EOL> dt . effectAllowed = '<STR_LIT>' <EOL> target = DOM . eventGetTarget ( event ) <EOL> widget = None <EOL> for widget in self . children : <EOL> if widget . getElement ( ) == target : <EOL> self . movingWidget = widget <EOL> break <EOL> dt . setData ( '<STR_LIT>' , json . encode ( { '<STR_LIT:name>' : widget . student_name , <EOL> '<STR_LIT>' : widget . age , <EOL> '<STR_LIT>' : self . getID ( ) } ) ) <EOL> def onDrag ( self , event ) : <EOL> self . movingWidget . addStyleName ( '<STR_LIT>' ) <EOL> def onDragEnd ( self , event ) : <EOL> dt = event . dataTransfer <EOL> styles = self . getStyleName ( ) <EOL> if dt . dropEffect != '<STR_LIT:none>' and not '<STR_LIT>' in styles : <EOL> self . remove ( self . movingWidget ) <EOL> msg = '<STR_LIT>' <EOL> else : <EOL> self . movingWidget . removeStyleName ( '<STR_LIT>' ) <EOL> msg = '<STR_LIT>' <EOL> self . addMessage ( msg ) <EOL> def onDragEnter ( self , event ) : <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> DOM . eventPreventDefault ( event ) <EOL> def onDragLeave ( self , event ) : <EOL> self . removeStyleName ( '<STR_LIT>' ) <EOL> def onDragOver ( self , event ) : <EOL> DOM . eventPreventDefault ( event ) <EOL> def age_is_ok ( self , age ) : <EOL> return age >= self . min_age and age <= self . max_age <EOL> def onDrop ( self , event ) : <EOL> dt = event . dataTransfer <EOL> item = dt . getData ( "<STR_LIT>" ) <EOL> data = json . decode ( item ) <EOL> if '<STR_LIT:name>' in data and '<STR_LIT>' in data : <EOL> age = data [ '<STR_LIT>' ] <EOL> name = data [ '<STR_LIT:name>' ] <EOL> self . removeStyleName ( '<STR_LIT>' ) <EOL> if self . age_is_ok ( age ) : <EOL> self . addStudent ( name , age ) <EOL> dt . dropEffect = '<STR_LIT>' <EOL> self . addStyleName ( '<STR_LIT>' ) <EOL> def removeFlash ( timer ) : <EOL> self . removeStyleName ( '<STR_LIT>' ) <EOL> Timer ( <NUM_LIT> , notify = removeFlash ) <EOL> else : <EOL> dt . dropEffect = '<STR_LIT:none>' <EOL> self . addMessage ( '<STR_LIT>' ) <EOL> item_parent_id = data [ '<STR_LIT>' ] <EOL> item_parent = self . parent . containerFromId ( item_parent_id ) <EOL> item_parent . addStyleName ( '<STR_LIT>' ) <EOL> DOM . eventPreventDefault ( event ) <EOL> def addMessage ( self , message ) : <EOL> parent = self . getParent ( ) <EOL> while not hasattr ( parent , '<STR_LIT>' ) : <EOL> parent = parent . getParent ( ) <EOL> parent . addMessage ( message ) <EOL> class ClassContainer ( HorizontalPanel ) : <EOL> def __init__ ( self ) : <EOL> HorizontalPanel . __init__ ( self ) <EOL> pool = StudentContainer ( <NUM_LIT:1> , <NUM_LIT:20> , '<STR_LIT>' ) <EOL> for item in [ [ '<STR_LIT>' , <NUM_LIT:12> ] , [ '<STR_LIT>' , <NUM_LIT:10> ] , [ '<STR_LIT>' , <NUM_LIT> ] , <EOL> [ '<STR_LIT>' , <NUM_LIT:8> ] , [ '<STR_LIT>' , <NUM_LIT:4> ] ] : <EOL> pool . addStudent ( name = item [ <NUM_LIT:0> ] , age = item [ <NUM_LIT:1> ] ) <EOL> self . append ( pool ) <EOL> self . append ( StudentContainer ( <NUM_LIT:6> , <NUM_LIT> , '<STR_LIT>' ) ) <EOL> self . append ( StudentContainer ( <NUM_LIT:11> , <NUM_LIT:20> , '<STR_LIT>' ) ) <EOL> self . setSpacing ( '<STR_LIT>' ) <EOL> def containerFromId ( self , id ) : <EOL> for item in self . children : <EOL> if item . getID ( ) == id : <EOL> return item <EOL> class MultiTargetDemo ( DNDDemo ) : <EOL> def __init__ ( self ) : <EOL> self . drop_widget = ClassContainer ( ) <EOL> self . title = '<STR_LIT>' <EOL> self . id = '<STR_LIT>' <EOL> DNDDemo . __init__ ( self ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> pyjd . setup ( "<STR_LIT>" ) <EOL> j = RootPanel ( ) <EOL> j . add ( DNDDemos ( ) ) <EOL> pyjd . run ( ) </s>
