Пример #1
0
 def __init__(self,
              c,
              char,
              event,
              binding,
              w,
              x=None,
              y=None,
              x_root=None,
              y_root=None):
     '''Ctor for LeoKeyEvent class.'''
     if g.isStroke(binding):
         g.trace('***** (LeoKeyEvent) oops: already a stroke', binding,
                 g.callers())
         stroke = binding
     else:
         stroke = g.KeyStroke(binding) if binding else None
     assert g.isStrokeOrNone(stroke), '(LeoKeyEvent) %s %s' % (repr(stroke),
                                                               g.callers())
     if 'keys' in g.app.debug:
         print('LeoKeyEvent: binding: %s, stroke: %s, char: %r' %
               (binding, stroke, char))
     self.c = c
     self.char = char or ''
     self.event = event  # New in Leo 4.11.
     self.stroke = stroke
     self.w = self.widget = w
     # Optional ivars
     self.x = x
     self.y = y
     # Support for fastGotoNode plugin
     self.x_root = x_root
     self.y_root = y_root
Пример #2
0
    def __init__(self, c, char, event, shortcut, w, x, y, x_root, y_root):

        trace = False and not g.unitTesting

        if g.isStroke(shortcut):
            g.trace('***** (LeoKeyEvent) oops: already a stroke', shortcut,
                    g.callers())
            stroke = shortcut
        else:
            stroke = g.KeyStroke(shortcut) if shortcut else None

        assert g.isStrokeOrNone(stroke), '(LeoKeyEvent) %s %s' % (repr(stroke),
                                                                  g.callers())

        if trace: g.trace('(LeoKeyEvent) stroke', stroke)

        self.c = c
        self.char = char or ''
        self.event = event  # New in Leo 4.11.
        self.stroke = stroke
        self.w = self.widget = w

        # Optional ivars
        self.x = x
        self.y = y

        # Support for fastGotoNode plugin
        self.x_root = x_root
        self.y_root = y_root
Пример #3
0
 def put(self, ch, event):
     """
     Insert the given ch into w.
     ch must be valid as stroke.s
     """
     try:
         # Patch the event.
         event.char = ch
         event.stroke = g.KeyStroke(ch)
         self.old_handleDefaultChar(event, stroke=None)
     except Exception:
         g.es_exception()
         self.abort()
Пример #4
0
 def __init__(
     self,
     c: Cmdr,
     char: str,
     event: Event,
     binding: Any,
     w: Wrapper,
     x: int = None,
     y: int = None,
     x_root: int = None,
     y_root: int = None,
 ) -> None:
     """Ctor for LeoKeyEvent class."""
     stroke: Any
     if g.isStroke(binding):
         g.trace('***** (LeoKeyEvent) oops: already a stroke', binding,
                 g.callers())
         stroke = binding
     else:
         stroke = g.KeyStroke(binding) if binding else None
     assert g.isStrokeOrNone(
         stroke), f"(LeoKeyEvent) {stroke!r} {g.callers()}"
     if 0:  # Doesn't add much.
         if 'keys' in g.app.debug:
             print(
                 f"LeoKeyEvent: binding: {binding}, stroke: {stroke}, char: {char!r}"
             )
     self.c = c
     self.char = char or ''
     self.event = event  # New in Leo 4.11.
     self.stroke = stroke
     self.w = self.widget = w
     # Optional ivars
     self.x = x
     self.y = y
     # Support for fastGotoNode plugin
     self.x_root = x_root
     self.y_root = y_root
Пример #5
0
 def test_g_KeyStroke(self):
     table = [
         # Gang of four, unmodified)
         ('bksp', 'BackSpace'),
         ('backspace', 'BackSpace'),
         ('backtab', 'Tab'),
         ('linefeed', '\n'),
         ('\r', '\n'),
         ('return', '\n'),
         ('tab', 'Tab'),
         # Gang of four, with shift mod.
         ('Shift-bksp', 'Shift+BackSpace'),
         ('Shift-backspace', 'Shift+BackSpace'),
         ('Shift-backtab', 'Shift+Tab'),
         ('Shift-linefeed', 'Shift+Return'),
         ('Shift-\r', 'Shift+Return'),
         ('Shift-return', 'Shift+Return'),
         ('Shift-tab', 'Shift+Tab'),
         # Gang of four, with Alt mod.
         ('Alt-bksp', 'Alt+BackSpace'),
         ('Alt-backspace', 'Alt+BackSpace'),
         ('Alt-backtab', 'Alt+Tab'),
         ('Alt-linefeed', 'Alt+Return'),
         ('Alt-\r', 'Alt+Return'),
         ('Alt-return', 'Alt+Return'),
         ('Alt-tab', 'Alt+Tab'),
         #
         # #912: tilde.
         ('~', '~'),
         ('Shift-~', '~'),
         #
         # Alpha
         ('1', '1'),
         ('a', 'a'),
         ('A', 'A'),
         ('Alt-a', 'Alt+a'),
         ('Alt-A', 'Alt+a'),
         ('Alt-Shift-a', 'Alt+Shift+a'),
         # We can no longer ignore the shift.
         # ('Alt-Shift++','Alt+plus'), # Ignore the shift.
         ('Shift-a', 'A'),
         ('Shift-A', 'A'),
         ('RtArrow', 'Right'),
         ('Shift-RtArrow', 'Shift+Right'),
         ('PageUp', 'Prior'),
         ('Prior', 'Prior'),
         ('Shift-PageUp', 'Shift+Prior'),
         ('PageDn', 'Next'),
         ('Next', 'Next'),
         ('Shift-Next', 'Shift+Next'),
         ('Alt-=', 'Alt+='),
         ('Alt-+', 'Alt++'),
         ('Alt--', 'Alt+-'),
         ('Ctrl-RtArrow', 'Ctrl+Right'),
         ('Control-Right', 'Ctrl+Right'),
     ]
     for setting, result in table:
         stroke = g.KeyStroke(binding=setting)
         val = stroke.s
         assert val == result, 'For %r, expected %r, Got %r' % (setting,
                                                                result, val)