def test_key_sequence_disabled(self): textbox = wx.TextCtrl(self.frame) textbox.SetEditable(False) with self.assertRaises(Disabled): _interaction_helpers.key_sequence_text_ctrl( textbox, command.KeySequence("abc"), 0)
def test_key_sequence_with_backspace_unsupported(self): textbox = wx.TextCtrl(self.frame) with self.assertRaises(ValueError) as exception_context: _interaction_helpers.key_sequence_text_ctrl( textbox, command.KeySequence("\b"), 0) self.assertIn( "is currently not supported.", str(exception_context.exception), )
def test_key_sequence(self): # The insertion point is moved to the end textbox = wx.TextCtrl(self.frame) textbox.SetValue("123") handler = mock.Mock() textbox.Bind(wx.EVT_TEXT, handler) _interaction_helpers.key_sequence_text_ctrl( textbox, command.KeySequence("abc"), 0) self.assertEqual(textbox.GetValue(), "123abc") self.assertEqual(handler.call_count, 3)
def register_editable_textbox_handlers(registry, target_class, widget_getter): """ Register common interactions for an editable textbox (in Wx) Parameters ---------- registry : TargetRegistry The registry being registered to. target_class : subclass of type The type of target being wrapped in a UIWrapper on which the interaction will be performed. widget_getter : callable(wrapper: UIWrapper) -> wx.TextCtrl A callable to return a wx.TextCtrl """ handlers = [ (KeySequence, (lambda wrapper, interaction: _interaction_helpers.key_sequence_text_ctrl( widget_getter(wrapper), interaction, wrapper.delay))), (KeyClick, (lambda wrapper, interaction: _interaction_helpers.key_click_text_entry( widget_getter(wrapper), interaction, wrapper.delay))), (MouseClick, (lambda wrapper, _: _interaction_helpers.mouse_click_object( control=widget_getter(wrapper), delay=wrapper.delay))), (DisplayedText, lambda wrapper, _: widget_getter(wrapper).GetValue()), ] for interaction_class, handler in handlers: registry.register_interaction( target_class=target_class, interaction_class=interaction_class, handler=handler, )
def test_key_sequence_with_unicode(self): handler = mock.Mock() textbox = wx.TextCtrl(self.frame) textbox.Bind(wx.EVT_TEXT, handler) # This range is supported by Qt for code in range(32, 127): with self.subTest(code=code, word=chr(code)): textbox.Clear() handler.reset_mock() # when _interaction_helpers.key_sequence_text_ctrl( textbox, command.KeySequence(chr(code) * 3), delay=0, ) # then self.assertEqual(textbox.Value, chr(code) * 3) self.assertEqual(handler.call_count, 3)
def register(registry): """ Registry location and interaction handlers for EnumEditor. Parameters ---------- registry : InteractionRegistry """ _IndexedListEditor.register(registry) _IndexedRadioEditor.register(registry) _IndexedSimpleEditor.register(registry) simple_editor_text_handlers = [ (KeyClick, (lambda wrapper, interaction: _interaction_helpers.key_click_combobox( control=wrapper._target.control, interaction=interaction, delay=wrapper.delay))), (KeySequence, (lambda wrapper, interaction: _interaction_helpers.key_sequence_text_ctrl( control=wrapper._target.control, interaction=interaction, delay=wrapper.delay))), (DisplayedText, simple_displayed_selected_text_handler), (SelectedText, simple_displayed_selected_text_handler) ] for interaction_class, handler in simple_editor_text_handlers: registry.register_interaction( target_class=SimpleEditor, interaction_class=interaction_class, handler=handler ) registry.register_interaction( target_class=RadioEditor, interaction_class=SelectedText, handler=radio_selected_text_handler, ) registry.register_interaction( target_class=ListEditor, interaction_class=SelectedText, handler=lambda wrapper, _: wrapper._target.control.GetString( wrapper._target.control.GetSelection()), )