여러 ao.lock의 해결 방법은 어떻게됩니까?
-
05-07-2019 - |
문제
나는 간단한 pys60 앱을 프로그래밍하고 있습니다. 실제로 Python으로 실제로 아무 것도하지 않았거나 이전에 여러 스레드를 사용하지 않으므로 이것은 모두 새로운 것입니다. 앱을 열어두기 위해 응용 프로그램 본문이 초기화 된 후 e32.ao_lock을 대기하기 ()로 설정 한 다음 exit_key_handler의 잠금을 신호합니다.
프로그램이 할 수있는 작업 중 하나는 타사 앱인 업 코드를 열 수 있습니다. 이것은 바코드를 스캔하고 바코드 문자열을 클립 보드에 복사합니다. 업 코드를 닫으면 응용 프로그램이 클립 보드에서 입력을 재개하고 붙여 넣어야합니다. 나는 이것이 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()
모든 도움이 감사했습니다.
해결책
별도의 두 번째 잠금 장치를 정의하고 한 번에 하나만 기다리고 있는지 확인 하여이 문제를 해결했습니다. 아무런 문제없이 작동하는 것 같습니다. 현재 코드를 찾을 수 있습니다 Google 코드에서 호스팅됩니다
제휴하지 않습니다 StackOverflow