from ldtp import *
import threading
launchapp('gedit')
waittillguiexist('*-gedit')
callbackRunning = threading.Event()
callbackRunning.set()
def cb():
if waittillguiexist('dlgReplace', guiTimeOut = 5):
wait(0.5)
click('dlgReplace', 'btnClose')
waittillguinotexist('dlgReplace')
callbackRunning.set()
print 'cb callbackend'
def cbwithvarargs(*args):
for arg in args:
print arg
if waittillguiexist('dlgOpenFiles', guiTimeOut = 5):
wait(0.5)
click('dlgOpenFiles', 'btnCancel')
waittillguinotexist('dlgOpenFiles')
callbackRunning.set()
print 'cbwithvarargs callbackend'
registerevent('window:create', cb)
click('*gedit', 'btnReplace')
if callbackRunning.isSet():
callbackRunning.clear()
print 'Waiting for callback to complete'
callbackRunning.wait()
print 'callbackset'
deregisterevent('window:create')
print 'wait'
callbackRunning.set()
registerevent('window:create', cbwithvarargs, 'test', 'var', 'args')
click('*gedit', 'btnOpen')
if callbackRunning.isSet():
callbackRunning.clear()
print 'Waiting for callback to complete'
callbackRunning.wait()
print 'callbackset'
print 'test end'
deregisterevent('window:create')
selectmenuitem('*-gedit', 'mnuFile;mnuQuit')
waittillguinotexist('*-gedit')