keytests: Add a small delay to each special key

keytest.py: This gives the os some time to update the status.
  All keys with modifier and all possible shortcuts are affected.

Shortcut use corrected in findadv-11-in.txt and findadv-17-in.txt
This commit is contained in:
Kornel Benko 2017-05-27 11:09:26 +02:00
parent 4feca4fb4a
commit ca40fdc569
5 changed files with 76 additions and 72 deletions

View File

@ -4,7 +4,10 @@
# is cleared after the next test starts. # is cleared after the next test starts.
Lang en_US.utf8 Lang en_US.utf8
CO: bug-8482.ctrl
TestBegin -dbg key test.lyx > bug-8482.loga.txt 2>&1 TestBegin -dbg key test.lyx > bug-8482.loga.txt 2>&1
KK: \Cm KK: \Cm
CP: Key (queried) [action=math-mode][Ctrl+M]
KK: \Ai KK: \Ai
TestEnd TestEnd
Assert searchPatterns.pl base=bug-8482

View File

@ -24,13 +24,13 @@ KK: \[Escape]\C\[Home]\C\[F21]
KK: o KK: o
KK: \C\[F20] KK: \C\[F20]
KK: [\\w]* a KK: [\\w]* a
KD: 100 #KD: 100
# select whole words # select whole words
KK: \Ae KK: \Ae
# search next # search next
KK: \Al KK: \Al
KK: \[Escape] KK: \[Escape]
KD: 1 #KD: 1
Cr: ^.*Putting Cr: ^.*Putting
CP: Putting selection at .*idx: 0 par: 1 pos: 26\n with len: 6 CP: Putting selection at .*idx: 0 par: 1 pos: 26\n with len: 6
# #

View File

@ -19,7 +19,7 @@ KK: \[Escape]\C\[Home]
KK: \CF KK: \CF
KK: \[Delete] KK: \[Delete]
# Uncheck ignore format # Uncheck ignore format
KK: \At\Ai\Ah KK: \Az\Ag\Ae
KK: \Cm KK: \Cm
KK: v\[Return] KK: v\[Return]
CP: Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n.*idx: 1 par: 0 pos: 0\n with len: 1 CP: Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 0\n.*idx: 1 par: 0 pos: 0\n with len: 1

View File

@ -17,7 +17,7 @@ CP: Key (queried) [action=buffer-begin][Ctrl+Home]
KK: \CF KK: \CF
KK: \[Delete] KK: \[Delete]
# Uncheck ignore format # Uncheck ignore format
KK: \At\Ai\Ah KK: \Az\Ag\Ae
KK: \Cm\\beta\\alpha \[Return] KK: \Cm\\beta\\alpha \[Return]
CP: Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 1\n with len: 2 CP: Putting selection at .*idx: 0 par: 0 pos: 0\n.*idx: 0 par: 0 pos: 1\n with len: 2
TestEnd TestEnd

View File

@ -384,73 +384,76 @@ def sendKeystringLocal(keystr, LYX_PID):
subprocess.call(xvpar, stdout = FNULL, stderr = FNULL) subprocess.call(xvpar, stdout = FNULL, stderr = FNULL)
sys.stdout.flush() sys.stdout.flush()
Axreg = re.compile(r'^(.*)\\Ax([^\\]*)(.*)$') def extractmultiple(line, regex):
returnreg = re.compile(r'(\\\[[A-Z][a-z0-9]+\])(.*)$') #print("extractmultiple " + line)
res = ["", ""]
# recursive wrapper around sendKeystringLocal() m = regex.match(line)
# handling \Ax-entries
def sendKeystringAx(line, LYX_PID):
global key_delay
saved_delay = key_delay
m = Axreg.match(line)
if m: if m:
prefix = m.group(1) chr = m.group(1)
content = m.group(2) if m.group(2) == "":
rest = m.group(3); res[0] = chr
if prefix != "": res[1] = ""
# since (.*) is greedy, check prefix for '\Ax' again
sendKeystringAx(prefix, LYX_PID)
sendKeystringLocal('\Ax', LYX_PID)
time.sleep(0.1)
m2 = returnreg.match(rest)
if m2:
line = m2.group(2)
ctrlk = m2.group(1)
key_delay = "1"
sendKeystringLocal(content + ctrlk, LYX_PID)
key_delay = saved_delay
time.sleep(controlkey_delay)
if line != "":
sendKeystringLocal(line, LYX_PID)
else: else:
if content != "": norm = extractmultiple(m.group(2), regex)
sendKeystringLocal(content, LYX_PID) res[0] = chr + norm[0]
if rest != "": res[1] = norm[1]
sendKeystringLocal(rest, LYX_PID)
else: else:
if line != "": res[0] = ""
sendKeystringLocal(line, LYX_PID) res[1] = line
return res
specialkeyreg = re.compile(r'(.+)(\\[AC]([a-zA-Z]|\\\[[A-Z][a-z0-9]+\]).*)$') normal_re = re.compile(r'^([^\\]|\\\\)(.*)$')
# Split line at start of each meta or controll char def extractnormal(line):
# collect non-special chars from start of line
return extractmultiple(line, normal_re)
def sendKeystringAC(line, LYX_PID): modifier_re = re.compile(r'^(\\[CAS])(.+)$')
m = specialkeyreg.match(line) def extractmodifiers(line):
# collect modifiers like '\\A' at start of line
return extractmultiple(line, modifier_re)
special_re = re.compile(r'^(\\\[[A-Z][a-z0-9]+\])(.*)$')
def extractsingle(line):
# check for single key following a modifier
# either ascii like 'a'
# or special like '\[Return]'
res = [False, "", ""]
m = normal_re.match(line)
if m: if m:
first = m.group(1) res[0] = False
second = m.group(2) res[1] = m.group(1)
sendKeystringAC(first, LYX_PID) res[2] = m.group(2)
sendKeystringAC(second, LYX_PID)
else: else:
sendKeystringAx(line, LYX_PID) m = special_re.match(line)
controlkeyreg = re.compile(r'^(.*\\\[[A-Z][a-z0-9]+\])(.*\\\[[A-Z][a-z0-9]+\])(.*)$')
# Make sure, only one of \[Return], \[Tab], \[Down], \[Home] etc are in one sent line
# e.g. split the input line on each keysym
def sendKeystringRT(line, LYX_PID):
m = controlkeyreg.match(line)
if m: if m:
first = m.group(1) res[0] = True
second = m.group(2) res[1] = m.group(1)
third = m.group(3) res[2] = m.group(2)
sendKeystringRT(first, LYX_PID)
time.sleep(controlkey_delay)
sendKeystringRT(second, LYX_PID)
time.sleep(controlkey_delay)
if third != "":
sendKeystringRT(third, LYX_PID)
else: else:
sendKeystringAC(line, LYX_PID) die(1, "Undecodable key for line \'" + line + "\"")
return res
def sendKeystring(line, LYX_PID):
if line == "":
return
normalchars = extractnormal(line)
line = normalchars[1]
if normalchars[0] != "":
sendKeystringLocal(normalchars[0], LYX_PID)
if line == "":
return
modchars = extractmodifiers(line)
line = modchars[1]
if line == "":
die(1, "Missing modified key")
modifiedchar = extractsingle(line)
line = modifiedchar[2]
special = modchars[0] != "" or modifiedchar[0]
sendKeystringLocal(modchars[0] + modifiedchar[1], LYX_PID)
if special:
# give the os time to update the status info (in /proc)
time.sleep(controlkey_delay)
sendKeystring(line, LYX_PID)
def system_retry(num_retry, cmd): def system_retry(num_retry, cmd):
i = 0 i = 0
@ -633,7 +636,7 @@ outfile = open(outfilename, 'w')
if not lyx_pid is None: if not lyx_pid is None:
RaiseWindow() RaiseWindow()
# Next command is language dependent # Next command is language dependent
#sendKeystringRT("\Afn", lyx_pid) #sendKeystring("\Afn", lyx_pid)
write_commands = True write_commands = True
failed = False failed = False
@ -698,8 +701,7 @@ while not failed:
print('lyx_pid: ' + lyx_pid) print('lyx_pid: ' + lyx_pid)
print('lyx_win: ' + lyx_window_name) print('lyx_win: ' + lyx_window_name)
dead_expected = False dead_expected = False
sendKeystringLocal("\C\[Home]", lyx_pid) sendKeystring("\C\[Home]", lyx_pid)
time.sleep(controlkey_delay)
elif c[0:5] == 'Sleep': elif c[0:5] == 'Sleep':
print("Sleeping for " + c[6:] + " seconds") print("Sleeping for " + c[6:] + " seconds")
time.sleep(float(c[6:])) time.sleep(float(c[6:]))
@ -715,7 +717,7 @@ while not failed:
RaiseWindow() RaiseWindow()
elif c[0:4] == 'KK: ': elif c[0:4] == 'KK: ':
if lyx_exists(): if lyx_exists():
sendKeystringRT(c[4:], lyx_pid) sendKeystring(c[4:], lyx_pid)
else: else:
##intr_system('killall lyx; sleep 2 ; killall -9 lyx') ##intr_system('killall lyx; sleep 2 ; killall -9 lyx')
if lyx_pid is None: if lyx_pid is None:
@ -727,7 +729,7 @@ while not failed:
print('Setting DELAY to ' + key_delay) print('Setting DELAY to ' + key_delay)
elif c == 'Loop': elif c == 'Loop':
RaiseWindow() RaiseWindow()
sendKeystringRT(ResetCommand, lyx_pid) sendKeystring(ResetCommand, lyx_pid)
elif c[0:6] == 'Assert': elif c[0:6] == 'Assert':
cmd = c[7:].rstrip() cmd = c[7:].rstrip()
result = intr_system(cmd, True) result = intr_system(cmd, True)
@ -742,7 +744,7 @@ while not failed:
else: else:
print(" ------------ Forcing kill of lyx instance: " + str(lyx_pid) + " ------------") print(" ------------ Forcing kill of lyx instance: " + str(lyx_pid) + " ------------")
# This line below is there only to allow lyx to update its log-file # This line below is there only to allow lyx to update its log-file
sendKeystringLocal("\[Escape]", lyx_pid) sendKeystring("\[Escape]", lyx_pid)
dead_expected = True dead_expected = True
while not lyx_dead(lyx_pid): while not lyx_dead(lyx_pid):
intr_system("kill -9 " + str(lyx_pid), True); intr_system("kill -9 " + str(lyx_pid), True);
@ -763,11 +765,10 @@ while not failed:
else: else:
print(" ------------ Forcing quit of lyx instance: " + str(lyx_pid) + " ------------") print(" ------------ Forcing quit of lyx instance: " + str(lyx_pid) + " ------------")
# \[Escape]+ should work as RESET focus to main window # \[Escape]+ should work as RESET focus to main window
sendKeystringAx("\[Escape]\[Escape]\[Escape]\[Escape]", lyx_pid) sendKeystring("\[Escape]\[Escape]\[Escape]\[Escape]", lyx_pid)
time.sleep(controlkey_delay)
# now we should be outside any dialog # now we should be outside any dialog
# and so the function lyx-quit should work # and so the function lyx-quit should work
sendKeystringLocal("\Cq", lyx_pid) sendKeystring("\Cq", lyx_pid)
marked.dispatch('CP: action=lyx-quit') marked.dispatch('CP: action=lyx-quit')
marked.close() marked.close()
time.sleep(0.5) time.sleep(0.5)
@ -780,7 +781,7 @@ while not failed:
# causing a 'beep' # causing a 'beep'
time.sleep(0.5) time.sleep(0.5)
# probably waiting for Save/Discard/Abort, we select 'Discard' # probably waiting for Save/Discard/Abort, we select 'Discard'
sendKeystringRT("\[Tab]\[Return]", lyx_pid) sendKeystring("\[Tab]\[Return]", lyx_pid)
lcount = 0 lcount = 0
else: else:
lcount = 1 lcount = 1