<s> from pyjamas import DOM <EOL> from pyjamas import Factory <EOL> from pyjamas import Window <EOL> from pyjamas . ui import Applier <EOL> def findStyleName ( element , style ) : <EOL> oldStyle = DOM . getAttribute ( element , "<STR_LIT>" ) <EOL> if oldStyle is None : <EOL> return - <NUM_LIT:1> <EOL> idx = oldStyle . find ( style ) <EOL> lastPos = len ( oldStyle ) <EOL> while idx != - <NUM_LIT:1> : <EOL> if idx == <NUM_LIT:0> or ( oldStyle [ idx - <NUM_LIT:1> ] == "<STR_LIT:U+0020>" ) : <EOL> last = idx + len ( style ) <EOL> if ( last == lastPos ) or ( ( last < lastPos ) and ( oldStyle [ last ] == "<STR_LIT:U+0020>" ) ) : <EOL> break <EOL> idx = oldStyle . find ( style , idx + <NUM_LIT:1> ) <EOL> return idx <EOL> def setStyleName ( element , style , add ) : <EOL> oldStyle = DOM . getAttribute ( element , "<STR_LIT>" ) <EOL> if oldStyle is None : <EOL> oldStyle = "<STR_LIT>" <EOL> idx = findStyleName ( element , style ) <EOL> if add : <EOL> if idx == - <NUM_LIT:1> : <EOL> DOM . setAttribute ( element , "<STR_LIT>" , oldStyle + "<STR_LIT:U+0020>" + style ) <EOL> return <EOL> if idx == - <NUM_LIT:1> : <EOL> return <EOL> if idx == <NUM_LIT:0> : <EOL> begin = '<STR_LIT>' <EOL> else : <EOL> begin = oldStyle [ : idx - <NUM_LIT:1> ] <EOL> end = oldStyle [ idx + len ( style ) : ] <EOL> DOM . setAttribute ( element , "<STR_LIT>" , begin + end ) <EOL> class UIObject ( Applier ) : <EOL> _props = [ ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT:width>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT:size>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT:title>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ] <EOL> @ classmethod <EOL> def _getProps ( self ) : <EOL> return Applier . _getProps ( ) + self . _props <EOL> def __init__ ( self , ** kwargs ) : <EOL> Applier . __init__ ( self , ** kwargs ) <EOL> def getAbsoluteLeft ( self ) : <EOL> return DOM . getAbsoluteLeft ( self . getElement ( ) ) <EOL> def getAbsoluteTop ( self ) : <EOL> return DOM . getAbsoluteTop ( self . getElement ( ) ) <EOL> def getClientHeight ( self ) : <EOL> return DOM . getIntAttribute ( self . getElement ( ) , "<STR_LIT>" ) <EOL> def getClientWidth ( self ) : <EOL> return DOM . getIntAttribute ( self . getElement ( ) , "<STR_LIT>" ) <EOL> def getElement ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . element <EOL> def getOffsetHeight ( self ) : <EOL> return DOM . getIntAttribute ( self . element , "<STR_LIT>" ) <EOL> def getOffsetWidth ( self ) : <EOL> return DOM . getIntAttribute ( self . element , "<STR_LIT>" ) <EOL> def getStyleName ( self ) : <EOL> return DOM . getAttribute ( self . element , "<STR_LIT>" ) <EOL> def getStylePrimaryName ( self ) : <EOL> """<STR_LIT>""" <EOL> fullClassName = self . getStyleName ( ) <EOL> if fullClassName : return fullClassName . split ( ) [ <NUM_LIT:0> ] <EOL> def getStyleAttribute ( self , attribute ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( attribute , basestring ) : <EOL> return DOM . getStyleAttribute ( self . getElement ( ) , attribute ) <EOL> el = self . getElement ( ) <EOL> result = { } <EOL> for attr in attribute : <EOL> result [ attr ] = DOM . getStyleAttribute ( el , attr ) <EOL> return result <EOL> def getTitle ( self ) : <EOL> return DOM . getAttribute ( self . element , "<STR_LIT:title>" ) <EOL> def setElement ( self , element ) : <EOL> """<STR_LIT>""" <EOL> self . element = element <EOL> def setHeight ( self , height ) : <EOL> """<STR_LIT>""" <EOL> if height is None : <EOL> height = "<STR_LIT>" <EOL> DOM . setStyleAttribute ( self . element , "<STR_LIT>" , str ( height ) ) <EOL> def getHeight ( self ) : <EOL> return DOM . getStyleAttribute ( self . element , "<STR_LIT>" ) <EOL> def setPixelSize ( self , width , height ) : <EOL> """<STR_LIT>""" <EOL> if width >= <NUM_LIT:0> : <EOL> self . setWidth ( "<STR_LIT>" % width ) <EOL> if height >= <NUM_LIT:0> : <EOL> self . setHeight ( "<STR_LIT>" % height ) <EOL> def setSize ( self , width , height ) : <EOL> """<STR_LIT>""" <EOL> self . setWidth ( width ) <EOL> self . setHeight ( height ) <EOL> def addStyleName ( self , style ) : <EOL> """<STR_LIT>""" <EOL> self . setStyleName ( self . element , style , True ) <EOL> def addStyleDependentName ( self , styleSuffix ) : <EOL> """<STR_LIT>""" <EOL> self . addStyleName ( self . getStylePrimaryName ( ) + "<STR_LIT:->" + styleSuffix ) <EOL> def removeStyleName ( self , style ) : <EOL> """<STR_LIT>""" <EOL> self . setStyleName ( self . element , style , False ) <EOL> def removeStyleDependentName ( self , styleSuffix ) : <EOL> """<STR_LIT>""" <EOL> self . removeStyleName ( self . getStylePrimaryName ( ) + "<STR_LIT:->" + styleSuffix ) <EOL> def setStyleName ( self , element , style = None , add = True ) : <EOL> """<STR_LIT>""" <EOL> if style is not None : <EOL> setStyleName ( element , style , add ) <EOL> return <EOL> style = element <EOL> DOM . setAttribute ( self . element , "<STR_LIT>" , style ) <EOL> def setStyleAttribute ( self , attribute , value = None ) : <EOL> """<STR_LIT>""" <EOL> if value is not None : <EOL> DOM . setStyleAttribute ( self . getElement ( ) , attribute , value ) <EOL> return <EOL> el = self . getElement ( ) <EOL> for attr , val in attribute . items ( ) : <EOL> DOM . setStyleAttribute ( el , attr , val ) <EOL> def setTitle ( self , title ) : <EOL> DOM . setAttribute ( self . element , "<STR_LIT:title>" , title ) <EOL> def setWidth ( self , width ) : <EOL> """<STR_LIT>""" <EOL> if width is None : <EOL> width = "<STR_LIT>" <EOL> DOM . setStyleAttribute ( self . element , "<STR_LIT:width>" , str ( width ) ) <EOL> def getWidth ( self ) : <EOL> return DOM . getStyleAttribute ( self . element , "<STR_LIT:width>" ) <EOL> def sinkEvents ( self , eventBitsToAdd ) : <EOL> """<STR_LIT>""" <EOL> if self . element : <EOL> DOM . sinkEvents ( self . getElement ( ) , <EOL> eventBitsToAdd | DOM . getEventsSunk ( self . getElement ( ) ) ) <EOL> def setzIndex ( self , index ) : <EOL> DOM . setIntStyleAttribute ( self . element , "<STR_LIT>" , index ) <EOL> def isVisible ( self , element = None ) : <EOL> """<STR_LIT>""" <EOL> return self . getVisible ( element ) <EOL> def getVisible ( self , element = None ) : <EOL> """<STR_LIT>""" <EOL> if not element : <EOL> element = self . element <EOL> try : <EOL> return element . style . display != "<STR_LIT:none>" <EOL> except AttributeError : <EOL> return True <EOL> def setVisible ( self , element , visible = None ) : <EOL> """<STR_LIT>""" <EOL> if visible is None : <EOL> visible = element <EOL> element = self . element <EOL> if visible : <EOL> DOM . setStyleAttribute ( element , '<STR_LIT>' , "<STR_LIT>" ) <EOL> else : <EOL> DOM . setStyleAttribute ( element , '<STR_LIT>' , "<STR_LIT:none>" ) <EOL> def unsinkEvents ( self , eventBitsToRemove ) : <EOL> """<STR_LIT>""" <EOL> DOM . sinkEvents ( self . getElement ( ) , <EOL> ~ eventBitsToRemove & DOM . getEventsSunk ( self . getElement ( ) ) ) <EOL> Factory . registerClass ( '<STR_LIT>' , '<STR_LIT>' , UIObject ) </s>
