(withcancelbutton)
return result
Attempt to connect to a network.

  If one of |GUEST_NETWORKS| is available nearby, will connect to that.
  Otherwise, will offer a list of networks to connect to.
  Args:
    withcancelbutton: True to add a Cancel button to the Wi-Fi picker dialog.
  Returns:
    True if network connected, False if not or user canceled.
Attempt to connect to a network.
Attempt to connect to a network .
def ConnectToNetwork(withcancelbutton):
  """Attempt to connect to a network.

  If one of |GUEST_NETWORKS| is available nearby, will connect to that.
  Otherwise, will offer a list of networks to connect to.
  Args:
    withcancelbutton: True to add a Cancel button to the Wi-Fi picker dialog.
  Returns:
    True if network connected, False if not or user canceled.
  """
  logging.info('Searching for network to connect to, please wait')
  networks = ScanForNetworks(None)
  logging.info('Found these networks: %s', networks.keys())

  guest_net = _FindGuestNetwork(GUEST_NETWORKS, networks)
  if guest_net:
    network = guest_net
  else:
    action = 'Refresh'
    while action != 'OK':
      dialog = cocoadialog.DropDown()
      dialog.SetTitle('Select Wireless Network')
      items = networks.keys()
      items.sort()
      dialog.SetItems(items)
      dialog.SetButton1('OK')
      dialog.SetButton2('Refresh')
      if withcancelbutton:
        dialog.SetButton3('Cancel')
      action, network, _ = dialog.Show().split('\n')
      if action == 'Refresh':
        networks = ScanForNetworks(None)
      elif action == 'Cancel':
        return False
  logging.info('Connecting to %s', network)

  # Does network need a password?
  password = None
  if networks[network].securityMode():
    if network in GUEST_NETWORKS:
      for psk in GUEST_PSKS:
        result = AssociateToNetwork(networks[network], password=psk)
        logging.info('Attempted to connect to %s. Success: %s', network, result)
        if result:
          return True
      logging.error('Password protected guest network detected, but known '
                    'passwords are not accepted.')
    dialog = cocoadialog.Standard_InputBox()
    dialog.SetPasswordBox()
    dialog.SetTitle('Password Required')
    dialog.SetInformativeText('The requested network (%s) requires a '
                              'password:' % network)
    (_, password, _) = dialog.Show().split('\n')
  result = AssociateToNetwork(networks[network], password=password)
  logging.info('Attempted to connect to %s. Success: %s', network, result)
  return result
def ConnectToNetwork ( withcancelbutton ) : logging . info ( 'Searching for network to connect to, please wait' ) networks = ScanForNetworks ( None ) logging . info ( 'Found these networks: %s' , networks . keys ( ) ) guest_net = _FindGuestNetwork ( GUEST_NETWORKS , networks ) if guest_net : network = guest_net else : action = 'Refresh' while action != 'OK' : dialog = cocoadialog . DropDown ( ) dialog . SetTitle ( 'Select Wireless Network' ) items = networks . keys ( ) items . sort ( ) dialog . SetItems ( items ) dialog . SetButton1 ( 'OK' ) dialog . SetButton2 ( 'Refresh' ) if withcancelbutton : dialog . SetButton3 ( 'Cancel' ) action , network , _ = dialog . Show ( ) . split ( '\n' ) if action == 'Refresh' : networks = ScanForNetworks ( None ) elif action == 'Cancel' : return False logging . info ( 'Connecting to %s' , network ) # Does network need a password? password = None if networks [ network ] . securityMode ( ) : if network in GUEST_NETWORKS : for psk in GUEST_PSKS : result = AssociateToNetwork ( networks [ network ] , password = psk ) logging . info ( 'Attempted to connect to %s. Success: %s' , network , result ) if result : return True logging . error ( 'Password protected guest network detected, but known ' 'passwords are not accepted.' ) dialog = cocoadialog . Standard_InputBox ( ) dialog . SetPasswordBox ( ) dialog . SetTitle ( 'Password Required' ) dialog . SetInformativeText ( 'The requested network (%s) requires a ' 'password:' % network ) ( _ , password , _ ) = dialog . Show ( ) . split ( '\n' ) result = AssociateToNetwork ( networks [ network ] , password = password ) logging . info ( 'Attempted to connect to %s. Success: %s' , network , result ) return result