try to ensure that the GVIM window is open before sending keys to it
This commit is contained in:
parent
da3f4077ee
commit
45bad8667c
17
test.py
17
test.py
@ -65,7 +65,7 @@ COMPL_ACCEPT = chr(25)
|
|||||||
|
|
||||||
if WIN:
|
if WIN:
|
||||||
# import windows specific modules
|
# import windows specific modules
|
||||||
import win32api, win32com, win32con, win32com.client
|
import win32com.client, win32gui
|
||||||
shell = win32com.client.Dispatch("WScript.Shell")
|
shell = win32com.client.Dispatch("WScript.Shell")
|
||||||
|
|
||||||
def focus_win(title=None):
|
def focus_win(title=None):
|
||||||
@ -73,6 +73,12 @@ def focus_win(title=None):
|
|||||||
raise Exception("Failed to switch to GVim window")
|
raise Exception("Failed to switch to GVim window")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
def is_focused(title=None):
|
||||||
|
cur_title = win32gui.GetWindowText(win32gui.GetForegroundWindow())
|
||||||
|
if (title or "- GVIM") in cur_title:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
BRACES = re.compile("([}{])")
|
BRACES = re.compile("([}{])")
|
||||||
WIN_ESCAPES = ["+", "^", "%", "~", "[", "]", "<", ">", "(", ")"]
|
WIN_ESCAPES = ["+", "^", "%", "~", "[", "]", "<", ">", "(", ")"]
|
||||||
WIN_REPLACES = [
|
WIN_REPLACES = [
|
||||||
@ -106,7 +112,14 @@ def send_win(keys, session):
|
|||||||
|
|
||||||
seq_o = seq
|
seq_o = seq
|
||||||
seq = convert_keys(seq)
|
seq = convert_keys(seq)
|
||||||
print "keys: '%s' -> '%s'" % (seq_o, seq.replace("~", "\n"))
|
|
||||||
|
if not is_focused():
|
||||||
|
time.sleep(2)
|
||||||
|
focus()
|
||||||
|
if not is_focused():
|
||||||
|
# This is the only way I can find to stop test execution
|
||||||
|
raise KeyboardInterrupt("Failed to focus GVIM")
|
||||||
|
|
||||||
shell.SendKeys(seq)
|
shell.SendKeys(seq)
|
||||||
|
|
||||||
################ end windows ################
|
################ end windows ################
|
||||||
|
Loading…
Reference in New Issue
Block a user