<s> from pyjamas import DOM <EOL> from pyjamas import Factory <EOL> from pyjamas import log <EOL> from pyjamas . ui . UIObject import UIObject <EOL> from pyjamas . ui import Event <EOL> from pyjamas . ui . ClickListener import ClickHandler <EOL> from pyjamas . ui . FocusListener import FocusHandler <EOL> from pyjamas . ui . KeyboardListener import KeyboardHandler <EOL> from pyjamas . ui . MouseListener import MouseHandler , MouseWheelHandler <EOL> from pyjamas . ui . DragHandler import DragHandler <EOL> from pyjamas . ui . DropHandler import DropHandler <EOL> class Widget ( UIObject ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . attached = False <EOL> self . parent = None <EOL> self . layoutData = None <EOL> self . contextMenu = None <EOL> UIObject . __init__ ( self , ** kwargs ) <EOL> def getLayoutData ( self ) : <EOL> return self . layoutData <EOL> def getParent ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . parent <EOL> def isAttached ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . attached <EOL> def setContextMenu ( self , menu ) : <EOL> self . contextMenu = menu <EOL> if menu is not None : <EOL> self . sinkEvents ( Event . ONCONTEXTMENU ) <EOL> else : <EOL> self . unsinkEvents ( Event . ONCONTEXTMENU ) <EOL> def onBrowserEvent ( self , event ) : <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> ClickHandler . onBrowserEvent ( self , event ) <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> KeyboardHandler . onBrowserEvent ( self , event ) <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> MouseHandler . onBrowserEvent ( self , event ) <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> MouseWheelHandler . onBrowserEvent ( self , event ) <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> FocusHandler . onBrowserEvent ( self , event ) <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> DragHandler . onBrowserEvent ( self , event ) <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> DropHandler . onBrowserEvent ( self , event ) <EOL> if self . contextMenu is None : <EOL> return True <EOL> type = DOM . eventGetType ( event ) <EOL> if type == "<STR_LIT>" : <EOL> DOM . eventCancelBubble ( event , True ) <EOL> DOM . eventPreventDefault ( event ) <EOL> self . contextMenu . onContextMenu ( self ) <EOL> return False <EOL> return True <EOL> def onLoad ( self ) : <EOL> pass <EOL> def doDetachChildren ( self ) : <EOL> pass <EOL> def doAttachChildren ( self ) : <EOL> pass <EOL> def onAttach ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . isAttached ( ) : <EOL> return <EOL> self . attached = True <EOL> DOM . setEventListener ( self . getElement ( ) , self ) <EOL> self . doAttachChildren ( ) <EOL> self . onLoad ( ) <EOL> def onDetach ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . isAttached ( ) : <EOL> return <EOL> self . doDetachChildren ( ) <EOL> self . attached = False <EOL> DOM . setEventListener ( self . getElement ( ) , None ) <EOL> def setLayoutData ( self , layoutData ) : <EOL> self . layoutData = layoutData <EOL> def setParent ( self , parent ) : <EOL> """<STR_LIT>""" <EOL> oldparent = self . parent <EOL> self . parent = parent <EOL> if parent is None : <EOL> if oldparent is not None and oldparent . attached : <EOL> self . onDetach ( ) <EOL> elif parent . attached : <EOL> self . onAttach ( ) <EOL> def removeFromParent ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self . parent , "<STR_LIT>" ) : <EOL> self . parent . remove ( self ) <EOL> def getID ( self ) : <EOL> """<STR_LIT>""" <EOL> return DOM . getAttribute ( self . getElement ( ) , "<STR_LIT:id>" ) <EOL> def setID ( self , id ) : <EOL> """<STR_LIT>""" <EOL> DOM . setAttribute ( self . getElement ( ) , "<STR_LIT:id>" , id ) <EOL> Factory . registerClass ( '<STR_LIT>' , '<STR_LIT>' , Widget ) </s>
