1

私は単純なpyS60アプリをプログラミングしていますが、以前はpythonや複数のスレッドを使用したことはまったくなかったので、これは私にとって少し新しいことです。アプリを開いたままにするために、アプリケーションの本体が初期化された後に e32.Ao_lock を wait() に設定し、exit_key_handler でロックを通知します。

プログラムが実行できるタスクの 1 つは、サードパーティのアプリ UpCode を開くことです。これにより、バーコードがスキャンされ、バーコード文字列がクリップボードにコピーされます。UpCode を閉じると、アプリケーションが再開され、クリップボードからの入力が貼り付けられるはずです。これは Ao.lock を使用して実現できることはわかっていますが、既にこのインスタンスを呼び出しています。何かがクリップボードに貼り付けられたことに気付いた後、私のアプリケーションがフォーカスを取り戻すことが理想的です。スリープ機能またはタイマー機能のいずれかを使用して、必要なことを達成できますか?

ここで完全なスクリプトを見つけることができます。以下の必要な部分に簡略化しています。

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()

ありとあらゆる助けをいただければ幸いです。

4

1 に答える 1

0

この問題は、別の2番目のロックを定義し、一度に1つだけが待機していることを確認することで解決しました。問題なく動作しているようです。現在のコードはグーグルコードでホストされているのを見つけることができます

于 2010-06-21T13:41:24.153 に答える