<s> from pyjamas import DOM <EOL> from pyjamas import Factory <EOL> from __pyjamas__ import console , JS <EOL> from pyjamas . ui . FocusWidget import FocusWidget <EOL> from pyjamas . ui . ChangeListener import ChangeHandler <EOL> from pyjamas . ui . InputListener import InputHandler <EOL> from pyjamas . ui import Event <EOL> class TextBoxBase ( FocusWidget , ChangeHandler , InputHandler ) : <EOL> ALIGN_CENTER = "<STR_LIT>" <EOL> ALIGN_JUSTIFY = "<STR_LIT>" <EOL> ALIGN_LEFT = "<STR_LIT:left>" <EOL> ALIGN_RIGHT = "<STR_LIT:right>" <EOL> _props = [ ( "<STR_LIT:name>" , "<STR_LIT:Name>" , "<STR_LIT:Name>" , None ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , None ) , <EOL> ] <EOL> def __init__ ( self , element , ** kwargs ) : <EOL> self . currentEvent = None <EOL> FocusWidget . __init__ ( self , element , ** kwargs ) <EOL> ChangeHandler . __init__ ( self ) <EOL> InputHandler . __init__ ( self ) <EOL> @ classmethod <EOL> def _getProps ( self ) : <EOL> return FocusWidget . _getProps ( ) + self . _props <EOL> def cancelKey ( self ) : <EOL> if self . currentEvent is not None : <EOL> DOM . eventPreventDefault ( self . currentEvent ) <EOL> def getCursorPos ( self ) : <EOL> element = self . getElement ( ) <EOL> try : <EOL> return element . selectionStart <EOL> except : <EOL> return <NUM_LIT:0> <EOL> def getName ( self ) : <EOL> return DOM . getAttribute ( self . getElement ( ) , "<STR_LIT:name>" ) <EOL> def getSelectedText ( self ) : <EOL> start = self . getCursorPos ( ) <EOL> length = self . getSelectionLength ( ) <EOL> text = self . getText ( ) <EOL> return text [ start : start + length ] <EOL> def getSelectionLength ( self ) : <EOL> element = self . getElement ( ) <EOL> try : <EOL> return element . selectionEnd - element . selectionStart <EOL> except : <EOL> return <NUM_LIT:0> <EOL> def setFocus ( self , focused ) : <EOL> if ( focused ) : <EOL> self . getElement ( ) . focus ( ) <EOL> else : <EOL> self . getElement ( ) . blur ( ) <EOL> def getText ( self ) : <EOL> return DOM . getAttribute ( self . getElement ( ) , "<STR_LIT:value>" ) <EOL> def selectAll ( self ) : <EOL> length = len ( self . getText ( ) ) <EOL> if length > <NUM_LIT:0> : <EOL> self . setSelectionRange ( <NUM_LIT:0> , length ) <EOL> def setCursorPos ( self , pos ) : <EOL> self . setSelectionRange ( pos , <NUM_LIT:0> ) <EOL> def setKey ( self , key ) : <EOL> if self . currentEvent is not None : <EOL> DOM . eventSetKeyCode ( self . currentEvent , key ) <EOL> def setName ( self , name ) : <EOL> DOM . setAttribute ( self . getElement ( ) , "<STR_LIT:name>" , name ) <EOL> def setSelectionRange ( self , pos , length ) : <EOL> if length < <NUM_LIT:0> : <EOL> console . error ( "<STR_LIT>" + length ) <EOL> if ( pos < <NUM_LIT:0> ) or ( length + pos > len ( self . getText ( ) ) ) : <EOL> console . error ( "<STR_LIT>" % pos + "<STR_LIT>" % ( pos + length ) + "<STR_LIT>" % len ( self . getText ( ) ) ) <EOL> element = self . getElement ( ) <EOL> element . setSelectionRange ( pos , pos + length ) <EOL> def setText ( self , text ) : <EOL> DOM . setAttribute ( self . getElement ( ) , "<STR_LIT:value>" , text ) <EOL> def setTextAlignment ( self , align ) : <EOL> DOM . setStyleAttribute ( self . getElement ( ) , "<STR_LIT>" , align ) <EOL> def getTextAlignment ( self , align ) : <EOL> return DOM . getStyleAttribute ( self . getElement ( ) , "<STR_LIT>" ) </s>
