Commit 6c8b3c18 authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

Horrible hacks to get autotextctrl tests running on docker/gtk

parent 8f84f99c
......@@ -13,6 +13,8 @@ import numpy as np
import wx
from fsl.utils.platform import platform as fslplatform
def compare_images(img1, img2, threshold):
"""Compares two images using the euclidean distance in RGB space
between pixels. Returns a tuple containing:
......@@ -89,6 +91,16 @@ def run_with_wx(func, *args, **kwargs):
return result[0]
def addall(parent, widgets):
sizer = wx.BoxSizer(wx.VERTICAL)
for w in widgets:
sizer.Add(w, flag=wx.EXPAND, proportion=1)
parent.Layout()
parent.Refresh()
realYield()
# Under GTK, a single call to
# yield just doesn't cut it
def realYield(centis=10):
......@@ -125,12 +137,52 @@ def simclick(sim, target, btn=wx.MOUSE_BTN_LEFT, pos=None, stype=0):
def simtext(sim, target, text, enter=True):
target.SetFocus()
target.SetValue(text)
if enter: sim.KeyDown(wx.WXK_RETURN)
# KeyDown doesn't seem to work
# under docker/GTK so we have
# to hack
if enter and fslplatform.wxPlatform == fslplatform.WX_GTK:
parent = target.GetParent()
if type(parent).__name__ == 'FloatSpinCtrl':
parent._FloatSpinCtrl__onText(None)
elif type(parent).__name__ == 'AutoTextCtrl':
parent._AutoTextCtrl__onEnter(None)
else:
sim.KeyDown(wx.WXK_RETURN)
elif enter:
sim.KeyDown(wx.WXK_RETURN)
realYield()
def simkey(sim, target, key, down=True, up=False):
if target is not None: target.SetFocus()
if down: sim.KeyDown(key)
if up: sim.KeyUp(key)
class FakeEv(object):
def __init__(self, key):
self.key = key
def GetKeyCode(self):
return self.key
def Skip(self):
pass
def ResumePropagation(self, *a):
pass
parent = None
if target is not None:
target.SetFocus()
parent = target.GetParent()
if down and type(parent).__name__ == 'AutoTextCtrl':
parent._AutoTextCtrl__onKeyDown(FakeEv(key))
elif down and type(parent).__name__ == 'AutoCompletePopup':
if type(target).__name__ == 'TextCtrl':
parent._AutoCompletePopup__onKeyDown(FakeEv(key))
elif type(target).__name__ == 'ListBox':
parent._AutoCompletePopup__onListKeyDown(FakeEv(key))
elif down:
sim.KeyDown(key)
if up:
sim.KeyUp(key)
realYield()
......@@ -6,7 +6,7 @@
#
from . import run_with_wx, simclick, realYield
from . import run_with_wx, simclick, simtext, simkey, realYield, addall
import wx
import fsleyes_widgets.autotextctrl as autott
......@@ -50,13 +50,10 @@ def _test_event():
atc = autott.AutoTextCtrl(parent)
atc.Bind(autott.EVT_ATC_TEXT_ENTER, handler)
atc.SetFocus()
realYield()
sim.Char(ord('a'))
sim.Char(ord('b'))
sim.Char(ord('c'))
sim.KeyDown(wx.WXK_RETURN)
realYield()
addall(parent, [atc])
simtext(sim, atc.textCtrl, 'abc')
assert atc.GetValue() == 'abc'
assert called[0] == 'abc'
......@@ -94,14 +91,14 @@ def _test_popup_select1():
parent = wx.GetApp().GetTopWindow()
atc = autott.AutoTextCtrl(parent)
addall(parent, [atc])
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
atc.SetFocus()
sim.KeyDown(wx.WXK_RETURN)
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_RETURN)
realYield()
simkey(sim, atc.textCtrl, wx.WXK_RETURN)
simkey(sim, atc.popup.textCtrl, wx.WXK_DOWN)
atc.popup.listBox.SetSelection(1)
simkey(sim, atc.popup.listBox, wx.WXK_RETURN)
assert atc.GetValue() == 'aab'
......@@ -115,14 +112,12 @@ def _test_popup_select2():
parent = wx.GetApp().GetTopWindow()
atc = autott.AutoTextCtrl(parent)
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
addall(parent, [atc])
atc.SetFocus()
sim.Char(ord('b'))
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_RETURN)
realYield()
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
simtext(sim, atc.textCtrl, 'b', enter=False)
simkey( sim, atc.popup.textCtrl, wx.WXK_DOWN)
simkey( sim, atc.popup.listBox, wx.WXK_RETURN)
assert atc.GetValue() == 'bcc'
......@@ -132,19 +127,17 @@ def test_popup_select3():
def _test_popup_select3():
sim = wx.UIActionSimulator()
parent = wx.GetApp().GetTopWindow()
atc = autott.AutoTextCtrl(parent)
addall(parent, [atc])
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
atc.SetFocus()
sim.Char(ord('a'))
sim.Char(ord('b'))
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_RETURN)
realYield()
simtext(sim, atc, 'ab', enter=False)
simkey(sim, atc.popup.textCtrl, wx.WXK_DOWN)
simkey(sim, atc.popup.listBox, wx.WXK_RETURN)
assert atc.GetValue() == 'aba'
......@@ -158,14 +151,14 @@ def _test_popup_cancel():
parent = wx.GetApp().GetTopWindow()
atc = autott.AutoTextCtrl(parent)
addall(parent, [atc])
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
atc.SetFocus()
sim.KeyDown(wx.WXK_RETURN)
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_ESCAPE)
realYield()
simkey(sim, atc.textCtrl, wx.WXK_RETURN)
simkey(sim, atc.popup.textCtrl, wx.WXK_DOWN)
simkey(sim, atc.popup.listBox, wx.WXK_DOWN)
simkey(sim, atc.popup.listBox, wx.WXK_ESCAPE)
assert atc.GetValue() == ''
......@@ -179,18 +172,14 @@ def _test_popup_focusback():
parent = wx.GetApp().GetTopWindow()
atc = autott.AutoTextCtrl(parent)
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
addall(parent, [atc])
atc.SetFocus()
sim.KeyDown(wx.WXK_RETURN)
realYield()
sim.KeyDown(wx.WXK_DOWN)
sim.KeyDown(wx.WXK_UP)
realYield()
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
sim.Text('abc')
sim.KeyDown(wx.WXK_RETURN)
realYield()
simkey(sim, atc.textCtrl, wx.WXK_RETURN)
simkey(sim, atc.popup.textCtrl, wx.WXK_DOWN)
simkey(sim, atc.popup.listBox, wx.WXK_UP)
simtext(sim, atc.popup.textCtrl, 'abc')
assert atc.GetValue() == 'abc'
......@@ -204,23 +193,9 @@ def _test_popup_dblclick():
atc.AutoComplete(['aaa', 'aab', 'aba', 'bcc'])
atc.SetFocus()
sim.KeyDown(wx.WXK_RETURN)
realYield()
# Sneakily get a ref to the listbox
# in the AutoCompletePopup
realYield()
listbox = None
for c in atc.GetChildren():
if isinstance(c, autott.AutoCompletePopup):
for pc in c.GetChildren():
if isinstance(pc, wx.ListBox):
listbox = pc
break
addall(parent, [atc])
simclick(sim, listbox, stype=1, pos=[0.5, 0.05])
realYield()
simkey( sim, atc.textCtrl, wx.WXK_RETURN)
simclick(sim, atc.popup.listBox, stype=1, pos=[0.5, 0.05])
assert atc.GetValue() == 'aaa'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment