Domanda

Sto programmando una semplice app pyS60, in realtà non ho fatto nulla con Python o usando più thread prima, quindi questo è tutto un po 'nuovo per me. Per mantenere aperta l'app, ho impostato un e32.Ao_lock su wait () dopo che il corpo dell'applicazione è stato inizializzato, quindi segnala il blocco su exit_key_handler.

Una delle attività che il programma può svolgere è aprire un'app di terze parti, UpCode. Questo esegue la scansione di un codice a barre e copia la stringa del codice a barre negli Appunti. Quando chiudo UpCode, la mia applicazione dovrebbe riprendere e incollare l'input dagli Appunti. So che questo può essere realizzato utilizzando Ao.lock, ma ho già chiamato un'istanza di questo. Idealmente, la mia applicazione riacquisterebbe attenzione dopo aver notato che qualcosa era stato incollato negli appunti. Posso realizzare ciò di cui ho bisogno con una delle funzioni di sospensione o timer?

Puoi trovare lo script completo qui e l'ho abbreviato in le parti necessarie di seguito:

lock=e32.Ao_lock()

# Quit the script
def quit():
    lock.signal()

# Callback function will be called when the requested service is complete. 
def launch_app_callback(trans_id, event_id, input_params):
    if trans_id != appmanager_id and event_id != scriptext.EventCompleted:
        print "Error in servicing the request"
        print "Error code is: " + str(input_params["ReturnValue"]["ErrorCode"])
        if "ErrorMessage" in input_params["ReturnValue"]:
            print "Error message is: " + input_params["ReturnValue"]["ErrorMessage"]
    else:
        print "\nWaiting for UpCode to close"
    #lock.signal()

# launch UpCode to scan barcode and get barcode from clipboard
def scan_barcode():
    msg('Launching UpCode to scan barcode.\nPlease exit UpCode after the barcode has been copied to the clipboard')
    # Load appmanage service
    appmanager_handle = scriptext.load('Service.AppManager', 'IAppManager')
    # Make a request to query the required information in asynchronous mode
    appmanager_id = appmanager_handle.call('LaunchApp', {'ApplicationID': u's60uid://0x2000c83e'}, callback=launch_app_callback)
    #lock.wait()
    #print "Request complete!"
    barcode = clipboard.Get()
    return barcode

# handle the selection made from the main body listbox
def handle_selection():
    if (lb.current() == 0):
        barcode = scan_barcode()
    elif (lb.current() ==1):
        barcode = clipboard.Get()
    elif (lb.current() ==2):
        barcode = input_barcode()

    found = False
    if is_barcode(barcode):
        found, mbid, album, artist = identify_release(barcode)
    else:
        msg('Valid barcode not found. Please try again/ another method/ another CD')
        return

    if found:
        go = appuifw.query(unicode('Found: ' + artist + ' - ' + album + '\nScrobble it?'), 'query')
        if (go == 1):
            now = datetime.datetime.utcnow()
            scrobble_tracks(mbid, album, artist, now)
        else:
            appuifw.note(u'Scrobbling cancelled', 'info')
    else:
        appuifw.note(u'No match found for this barcode.', 'info')

# Set the application body up
appuifw.app.exit_key_handler = quit
appuifw.app.title = u"ScanScrobbler"
entries = [(u"Scan a barcode", u"Opens UpCode for scanning"),
           (u"Submit barcode from clipboard", u"If you've already copied a barcode there"),
           (u"Enter barcode by hand", u"Using numeric keypad")
          ]

lb = appuifw.Listbox(entries, handle_selection)
appuifw.app.body = lb

lock.wait()

Qualsiasi aiuto è stato apprezzato.

È stato utile?

Soluzione

Ho risolto questo problema definendo un secondo blocco separato e assicurandomi che solo uno fosse in attesa alla volta. Sembra funzionare senza alcun problema. È possibile trovare il codice corrente ospitato sul codice google

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top