<s> """<STR_LIT>""" <EOL> from pyjamas import Factory <EOL> from pyjamas import DOM <EOL> from pyjamas . ui import Focus <EOL> from pyjamas . ui . DoubleControl import DoubleControl <EOL> class AreaSlider ( DoubleControl ) : <EOL> def __init__ ( self , min_value , max_value , <EOL> start_value = None , step = None , <EOL> ** kwargs ) : <EOL> if not kwargs . has_key ( "<STR_LIT>" ) : <EOL> kwargs [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> if kwargs . has_key ( '<STR_LIT>' ) : <EOL> element = kwargs . pop ( '<STR_LIT>' ) <EOL> else : <EOL> element = Focus . createFocusable ( ) <EOL> DOM . setStyleAttribute ( element , "<STR_LIT>" , "<STR_LIT>" ) <EOL> DOM . setStyleAttribute ( element , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . handle = DOM . createDiv ( ) <EOL> DOM . appendChild ( element , self . handle ) <EOL> self . setHandleStyle ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> DoubleControl . __init__ ( self , element , min_value , max_value , <EOL> start_value , step , <EOL> ** kwargs ) <EOL> self . addClickListener ( self ) <EOL> self . addFocusListener ( self ) <EOL> self . addMouseListener ( self ) <EOL> self . setHandleStyle ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def setHandleStyle ( self , border , width , height , backgroundColor ) : <EOL> if border is not None : <EOL> DOM . setStyleAttribute ( self . handle , "<STR_LIT>" , border ) <EOL> if width is not None : <EOL> DOM . setStyleAttribute ( self . handle , "<STR_LIT:width>" , width ) <EOL> if height is not None : <EOL> DOM . setStyleAttribute ( self . handle , "<STR_LIT>" , height ) <EOL> if backgroundColor is not None : <EOL> DOM . setStyleAttribute ( self . handle , "<STR_LIT>" , backgroundColor ) <EOL> def setValue ( self , new_value , notify = <NUM_LIT:1> ) : <EOL> old_value = [ self . value_x , self . value_y ] <EOL> self . value_x = new_value [ <NUM_LIT:0> ] <EOL> self . value_y = new_value [ <NUM_LIT:1> ] <EOL> if not notify : <EOL> return <EOL> for listener in self . valuechange_listeners : <EOL> listener . onControlValueChanged ( self , old_value , new_value ) <EOL> def onFocus ( self , sender ) : <EOL> self . addStyleName ( "<STR_LIT>" ) <EOL> def onLostFocus ( self , sender ) : <EOL> self . removeStyleName ( "<STR_LIT>" ) <EOL> self . dragging = False <EOL> DOM . releaseCapture ( self . getElement ( ) ) <EOL> def moveControl ( self , mouse_x , mouse_y , first_move = False ) : <EOL> handle_height = DOM . getIntAttribute ( self . handle , "<STR_LIT>" ) <EOL> widget_height = self . getOffsetHeight ( ) <EOL> height_range = widget_height - <NUM_LIT:10> <EOL> relative_y = mouse_y - ( handle_height / <NUM_LIT:2> ) <EOL> if relative_y < <NUM_LIT:0> : <EOL> relative_y = <NUM_LIT:0> <EOL> if relative_y >= height_range : <EOL> relative_y = height_range <EOL> relative_y = height_range - relative_y <EOL> handle_width = DOM . getIntAttribute ( self . handle , "<STR_LIT>" ) <EOL> widget_width = self . getOffsetWidth ( ) <EOL> length_range = widget_width - <NUM_LIT:10> <EOL> relative_x = mouse_x - ( handle_width / <NUM_LIT:2> ) <EOL> if relative_x < <NUM_LIT:0> : <EOL> relative_x = <NUM_LIT:0> <EOL> if relative_x >= length_range : <EOL> relative_x = length_range <EOL> val_diff_x = self . max_value_x - self . min_value_x <EOL> new_value_x = ( ( val_diff_x * relative_x ) / length_range ) + self . min_value_x <EOL> val_diff_y = self . max_value_y - self . min_value_y <EOL> new_value_y = ( ( val_diff_y * relative_y ) / height_range ) + self . min_value_y <EOL> new_value = [ new_value_x , new_value_y ] <EOL> new_value = self . processValue ( new_value ) <EOL> self . setControlPos ( new_value ) <EOL> self . setValue ( new_value ) <EOL> def setControlPos ( self , value ) : <EOL> value_x = value [ <NUM_LIT:0> ] <EOL> value_y = value [ <NUM_LIT:1> ] <EOL> widget_width = self . getOffsetWidth ( ) <EOL> length_range = widget_width - <NUM_LIT:10> <EOL> val_diff_x = self . max_value_x - self . min_value_x <EOL> relative_x = length_range * ( value_x - self . min_value_x ) / val_diff_x <EOL> if relative_x < <NUM_LIT:0> : <EOL> relative_x = <NUM_LIT:0> <EOL> if relative_x >= length_range : <EOL> relative_x = length_range <EOL> widget_height = self . getOffsetHeight ( ) <EOL> height_range = widget_height - <NUM_LIT:10> <EOL> val_diff_y = self . max_value_y - self . min_value_y <EOL> relative_y = height_range * ( value_y - self . min_value_y ) / val_diff_y <EOL> if relative_y < <NUM_LIT:0> : <EOL> relative_y = <NUM_LIT:0> <EOL> if relative_y >= height_range : <EOL> relative_y = height_range <EOL> relative_y = height_range - relative_y <EOL> DOM . setStyleAttribute ( self . handle , "<STR_LIT>" , "<STR_LIT>" % relative_y ) <EOL> DOM . setStyleAttribute ( self . handle , "<STR_LIT:left>" , "<STR_LIT>" % relative_x ) <EOL> DOM . setStyleAttribute ( self . handle , "<STR_LIT>" , "<STR_LIT>" ) <EOL> Factory . registerClass ( '<STR_LIT>' , '<STR_LIT>' , AreaSlider ) </s>
