<s> from pyjamas import Factory <EOL> from pyjamas import DOM <EOL> from pyjamas . ui . Widget import Widget <EOL> class PanelBase ( object ) : <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> children = [ ] <EOL> for child in self . __iter__ ( ) : <EOL> children . append ( child ) <EOL> for child in children : <EOL> self . remove ( child ) <EOL> def doAttachChildren ( self ) : <EOL> for child in self : <EOL> child . onAttach ( ) <EOL> def doDetachChildren ( self ) : <EOL> for child in self : <EOL> child . onDetach ( ) <EOL> def getWidgetCount ( self ) : <EOL> return len ( self . getChildren ( ) ) <EOL> def getWidget ( self , index ) : <EOL> return self . getChildren ( ) [ index ] <EOL> def getIndexedChild ( self , index ) : <EOL> return self . getWidget ( index ) <EOL> def addIndexedItem ( self , index , child ) : <EOL> self . add ( child ) <EOL> def getWidgetIndex ( self , child ) : <EOL> return self . getChildren ( ) . index ( child ) <EOL> def getChildren ( self ) : <EOL> return self . children <EOL> def setWidget ( self , index , widget ) : <EOL> """<STR_LIT>""" <EOL> existing = self . getWidget ( index ) <EOL> if existing is not None : <EOL> self . remove ( existing ) <EOL> self . insert ( widget , index ) <EOL> def append ( self , widget ) : <EOL> return self . add ( widget ) <EOL> def __setitem__ ( self , index ) : <EOL> return self . setWidget ( index , widget ) <EOL> def __getitem__ ( self , index ) : <EOL> return self . getWidget ( index ) <EOL> def __len__ ( self ) : <EOL> return len ( self . getChildren ( ) ) <EOL> def __nonzero__ ( self ) : <EOL> return self is not None <EOL> def __iter__ ( self ) : <EOL> return self . getChildren ( ) . __iter__ ( ) <EOL> class Panel ( PanelBase , Widget ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . children = [ ] <EOL> PanelBase . __init__ ( self ) <EOL> Widget . __init__ ( self , ** kwargs ) <EOL> def disown ( self , widget ) : <EOL> if widget . getParent ( ) is not self : <EOL> raise Exception ( "<STR_LIT>" % ( str ( widget ) , str ( self ) ) ) <EOL> element = widget . getElement ( ) <EOL> widget . setParent ( None ) <EOL> parentElement = DOM . getParent ( element ) <EOL> if parentElement is not None : <EOL> DOM . removeChild ( parentElement , element ) <EOL> def adopt ( self , widget , container ) : <EOL> if container is not None : <EOL> widget . removeFromParent ( ) <EOL> DOM . appendChild ( container , widget . getElement ( ) ) <EOL> widget . setParent ( self ) <EOL> Factory . registerClass ( '<STR_LIT>' , '<STR_LIT>' , Panel ) </s>
