Beispiel #1
0
 def on_text_motion_select(self, motion):
     if motion != self.chosen_key:
         self.fail_test('Expected "{}", received "{}"'.format(
             key.motion_string(self.chosen_key), key.motion_string(motion)))
     else:
         self.checks_passed += 1
         if self.checks_passed >= self.number_of_checks:
             self.pass_test()
         else:
             self._select_next_key()
def on_text_motion_select(widget, motion):
    pos = widget.ti.cursor_index
    if widget.ti.highlight is None:
        start = end = pos
        widget.getGUI().setSelection(widget.ti)
    else:
        start, end = widget.ti.highlight

    # regular motion
    if motion == key.MOTION_LEFT:
        if pos != 0: widget.ti.setCursorPosition(pos-1)
    elif motion == key.MOTION_RIGHT:
        if pos != len(widget.ti.text): widget.ti.setCursorPosition(pos+1)
    elif motion in (key.MOTION_UP, key.MOTION_BEGINNING_OF_LINE,
            key.MOTION_BEGINNING_OF_FILE):
        widget.ti.setCursorPosition(0)
    elif motion in (key.MOTION_DOWN, key.MOTION_END_OF_LINE,
            key.MOTION_END_OF_FILE):
        widget.ti.setCursorPosition(len(widget.ti.text))
    else:
        print 'Unhandled MOTION SELECT', key.motion_string(motion)

    if widget.ti.cursor_index < start:
        start = widget.ti.cursor_index
    elif widget.ti.cursor_index > end:
        end = widget.ti.cursor_index
    if start < end: widget.ti.highlight = (start, end)
    else: widget.ti.highlight = (end, start)

    return event.EVENT_HANDLED
Beispiel #3
0
    def _update_question(self):
        self.question = """Please hold <Shift> and press:

{} ({})


Press Esc if test does not pass.""".format(key.motion_string(self.chosen_key),
                                           key.symbol_string(self.chosen_key))
        self._render_question()
Beispiel #4
0
    def _update_question(self):
        self.question = """Please press:

{} ({})


Press the X key if you do not have this motion key.
Press Esc if test does not pass.""".format(key.motion_string(self.chosen_key),
                                           key.symbol_string(self.chosen_key))
        self._render_question()
Beispiel #5
0
def on_text_motion(widget, motion):
    pos = widget.ti.cursor_index
    if motion == key.MOTION_LEFT:
        if pos != 0:
            widget.ti.setCursorPosition(pos - 1)
    elif motion == key.MOTION_RIGHT:
        if pos != len(widget.ti.text):
            widget.ti.setCursorPosition(pos + 1)
    elif motion in (key.MOTION_UP, key.MOTION_BEGINNING_OF_LINE,
                    key.MOTION_BEGINNING_OF_FILE):
        widget.ti.setCursorPosition(0)
    elif motion in (key.MOTION_DOWN, key.MOTION_END_OF_LINE,
                    key.MOTION_END_OF_FILE):
        widget.ti.setCursorPosition(len(widget.ti.text))
    elif motion == key.MOTION_BACKSPACE:
        text = widget.ti.text
        if widget.ti.highlight is not None:
            start, end = widget.ti.highlight
            text = text[:start] + text[end:]
            widget.ti.highlight = None
            widget.ti.cursor_index = start
        if pos != 0:
            n = pos
            widget.ti.cursor_index -= 1
            text = text[0:n - 1] + text[n:]
        if text != widget.ti.text:
            widget.ti.text = text
            widget.getGUI().dispatch_event(widget, 'on_change', text)
    elif motion == key.MOTION_DELETE:
        text = widget.ti.text
        if widget.ti.highlight is not None:
            start, end = widget.ti.highlight
            text = text[:start] + text[end:]
            widget.ti.highlight = None
            widget.ti.cursor_index = start
        elif pos != len(text):
            n = pos
            text = text[0:n] + text[n + 1:]
        if text != widget.ti.text:
            widget.ti.text = text
            widget.getGUI().dispatch_event(widget, 'on_change', text)
    else:
        print('Unhandled MOTION', key.motion_string(motion))

    # hide mouse highlight, show caret
    widget.ti.highlight = None
    widget.ti.cursor.enable()
    widget.ti.cursor.animation.pause()

    return event.EVENT_HANDLED
Beispiel #6
0
def on_text_motion(widget, motion):
    pos = widget.ti.cursor_index
    if motion == key.MOTION_LEFT:
        if pos != 0:
            widget.ti.setCursorPosition(pos - 1)
    elif motion == key.MOTION_RIGHT:
        if pos != len(widget.ti.text):
            widget.ti.setCursorPosition(pos + 1)
    elif motion in (key.MOTION_UP, key.MOTION_BEGINNING_OF_LINE,
                    key.MOTION_BEGINNING_OF_FILE):
        widget.ti.setCursorPosition(0)
    elif motion in (key.MOTION_DOWN, key.MOTION_END_OF_LINE,
                    key.MOTION_END_OF_FILE):
        widget.ti.setCursorPosition(len(widget.ti.text))
    elif motion == key.MOTION_BACKSPACE:
        text = widget.ti.text
        if widget.ti.highlight is not None:
            start, end = widget.ti.highlight
            text = text[:start] + text[end:]
            widget.ti.highlight = None
            widget.ti.cursor_index = start
        if pos != 0:
            n = pos
            widget.ti.cursor_index -= 1
            text = text[0:n - 1] + text[n:]
        if text != widget.ti.text:
            widget.ti.text = text
            widget.getGUI().dispatch_event(widget, 'on_change', text)
    elif motion == key.MOTION_DELETE:
        text = widget.ti.text
        if widget.ti.highlight is not None:
            start, end = widget.ti.highlight
            text = text[:start] + text[end:]
            widget.ti.highlight = None
            widget.ti.cursor_index = start
        elif pos != len(text):
            n = pos
            text = text[0:n] + text[n + 1:]
        if text != widget.ti.text:
            widget.ti.text = text
            widget.getGUI().dispatch_event(widget, 'on_change', text)
    else:
        print('Unhandled MOTION', key.motion_string(motion))

    # hide mouse highlight, show caret
    widget.ti.highlight = None
    widget.ti.cursor.enable()
    widget.ti.cursor.animation.pause()

    return event.EVENT_HANDLED
Beispiel #7
0
 def on_text_motion_select(self, motion):
     print('on_text_motion_select(motion=%s)' % (key.motion_string(motion)),
           file=self.file)
Beispiel #8
0
 def on_text_motion_select(self, motion):
     print('on_text_motion_select(motion=%s)' % (
         key.motion_string(motion)), file=self.file)
Beispiel #9
0
 def on_text_motion_select(self, motion):
     print >> self.file, 'on_text_motion_select(motion=%s)' % (
         key.motion_string(motion))
Beispiel #10
0
 def on_text_motion(self, motion):
     print 'text motion: {}'.format(key.motion_string(motion))
Beispiel #11
0
 def on_text_motion_select(self, motion):
     print('Select %s' % key.motion_string(motion))
Beispiel #12
0
 def on_text_motion(self, motion):
     print('Motion %s' % key.motion_string(motion))
Beispiel #13
0
 def on_text_motion_select(self, motion):
     print >> self.file, 'on_text_motion_select(motion=%s)' % (
         key.motion_string(motion))