<s> from pyjamas . ui . RootPanel import RootPanel , RootPanelCls <EOL> from pyjamas . ui . SimplePanel import SimplePanel <EOL> from pyjamas . ui . DockPanel import DockPanel <EOL> from pyjamas . ui . HorizontalPanel import HorizontalPanel <EOL> from pyjamas import DOM <EOL> from pyjamas . Timer import Timer <EOL> from pyjamas . ui . ListBox import ListBox <EOL> from pyjamas import Window <EOL> from pyjamas . gmaps . Map import Map , MapTypeId , MapOptions <EOL> from pyjamas . gmaps . Base import LatLng <EOL> from pyjamas . gmaps . DirectionsService import DirectionsService , DirectionsRequest , DirectionsTravelMode , DirectionsStatus <EOL> from pyjamas . gmaps . DirectionsRenderer import DirectionsRenderer <EOL> from __pyjamas__ import JS <EOL> class DirectionsSimple ( DockPanel ) : <EOL> def __init__ ( self ) : <EOL> DockPanel . __init__ ( self ) <EOL> self . setSize ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> topPanel = HorizontalPanel ( ) <EOL> self . add ( topPanel , DockPanel . NORTH ) <EOL> places = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } <EOL> self . start = ListBox ( ) <EOL> self . end = ListBox ( ) <EOL> for value in places : <EOL> self . start . addItem ( places [ value ] , value ) <EOL> self . end . addItem ( places [ value ] , value ) <EOL> self . start . addChangeListener ( self . calcRoute ) <EOL> self . end . addChangeListener ( self . calcRoute ) <EOL> topPanel . add ( self . start ) <EOL> topPanel . add ( self . end ) <EOL> mapPanel = SimplePanel ( ) <EOL> mapPanel . setSize ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . add ( mapPanel , DockPanel . CENTER ) <EOL> chigado = LatLng ( <NUM_LIT> , - <NUM_LIT> ) <EOL> options = MapOptions ( zoom = <NUM_LIT:7> , center = chigado , <EOL> mapTypeId = MapTypeId . ROADMAP ) <EOL> self . map = Map ( mapPanel . getElement ( ) , options ) <EOL> self . directionsDisplay = DirectionsRenderer ( ) <EOL> self . directionsDisplay . setMap ( self . map ) <EOL> self . directionsService = DirectionsService ( ) <EOL> def calcRoute ( self ) : <EOL> start = self . start . getValue ( self . start . getSelectedIndex ( ) ) <EOL> end = self . end . getValue ( self . end . getSelectedIndex ( ) ) <EOL> print "<STR_LIT>" , start , "<STR_LIT>" , end <EOL> request = DirectionsRequest ( origin = start , destination = end , travelMode = DirectionsTravelMode . DRIVING ) <EOL> self . directionsService . route ( request , self . directionsResult ) <EOL> def directionsResult ( self , response , status ) : <EOL> print "<STR_LIT>" <EOL> if status == DirectionsStatus . OK : <EOL> Hf = response . Hf <EOL> print Hf . origin , Hf . destination , Hf . travelMode <EOL> for route in response . routes : <EOL> attrs = dir ( route ) <EOL> attrs . sort ( ) <EOL> for attr in attrs : <EOL> print '<STR_LIT>' % ( attr , getattr ( route , attr ) ) <EOL> print "<STR_LIT:\n>" <EOL> self . directionsDisplay . setDirections ( response ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> root = RootPanel ( ) <EOL> root . add ( DirectionsSimple ( ) ) </s>
