@ -26,7 +26,7 @@ import time
from util import *
from util import *
from i18n import _
from i18n import _
from util import profiler , PrintError , DaemonThread
from util import profiler , PrintError , DaemonThread , UserCancelled
import wallet
import wallet
class Plugins ( DaemonThread ) :
class Plugins ( DaemonThread ) :
@ -386,7 +386,7 @@ class DeviceMgr(PrintError):
# The wallet has not been previously paired, so let the user
# The wallet has not been previously paired, so let the user
# choose an unpaired device and compare its first address.
# choose an unpaired device and compare its first address.
info = self . select_device ( wallet , plugin , devices )
info = self . select_device ( wallet , plugin , devices )
if info :
client = self . client_lookup ( info . device . id_ )
client = self . client_lookup ( info . device . id_ )
if client and client . is_pairable ( ) :
if client and client . is_pairable ( ) :
# See comment above for same code
# See comment above for same code
@ -397,16 +397,10 @@ class DeviceMgr(PrintError):
self . pair_wallet ( wallet , info . device . id_ )
self . pair_wallet ( wallet , info . device . id_ )
return client
return client
if info and client :
# The user input has wrong PIN or passphrase, or it is not pairable
# The user input has wrong PIN or passphrase
raise DeviceUnpairableError (
raise DeviceUnpairableError (
_ ( ' Unable to pair with your %s . ' ) % plugin . device )
_ ( ' Unable to pair with your %s . ' ) % plugin . device )
raise DeviceNotFoundError (
_ ( ' Could not connect to your %s . Verify the cable is '
' connected and that no other application is using it. ' )
% plugin . device )
def unpaired_device_infos ( self , handler , plugin , devices = None ) :
def unpaired_device_infos ( self , handler , plugin , devices = None ) :
''' Returns a list of DeviceInfo objects: one for each connected,
''' Returns a list of DeviceInfo objects: one for each connected,
unpaired device accepted by the plugin . '''
unpaired device accepted by the plugin . '''
@ -432,9 +426,17 @@ class DeviceMgr(PrintError):
def select_device ( self , wallet , plugin , devices = None ) :
def select_device ( self , wallet , plugin , devices = None ) :
''' Ask the user to select a device to use if there is more than one,
''' Ask the user to select a device to use if there is more than one,
and return the DeviceInfo for the device . '''
and return the DeviceInfo for the device . '''
while True :
infos = self . unpaired_device_infos ( wallet . handler , plugin , devices )
infos = self . unpaired_device_infos ( wallet . handler , plugin , devices )
if not infos :
if infos :
return None
break
msg = _ ( ' Could not connect to your %s . Verify the cable is '
' connected and that no other application is using it. \n \n '
' Try to connect again? ' ) % plugin . device
if not wallet . handler . yes_no_question ( msg ) :
raise UserCancelled ( )
devices = None
if len ( infos ) == 1 :
if len ( infos ) == 1 :
return infos [ 0 ]
return infos [ 0 ]
msg = _ ( " Please select which %s device to use: " ) % plugin . device
msg = _ ( " Please select which %s device to use: " ) % plugin . device