1
我正在編程一個簡單的pyS60應用程序,並沒有真正做過任何事情與python或之前使用多個線程,所以這對我來說有點新。 爲了使應用程序保持打開狀態,我在應用程序主體初始化後設置了e32.Ao_lock wait(),然後在exit_key_handler上發出鎖定信號。如何解決缺少多個ao.lock的問題?
程序可能執行的任務之一是打開第三方應用程序UpCode。這將掃描條形碼並將條形碼字符串複製到剪貼板。當我關閉UpCode時,我的應用程序應該繼續並粘貼來自剪貼板的輸入。 我知道這可以使用Ao.lock來完成,但我已經調用了這個實例。理想情況下,我的應用程序會在注意到某些內容已粘貼到剪貼板後重新獲得焦點。 我可以通過睡眠或定時器功能完成所需的任務嗎?
你可以找到完整的腳本here,我已經將它簡稱爲下面的必要部分:
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()
任何和讚賞所有幫助。