예제 #1
0
    def createKeyEvent(self, event, c, w, ch, binding):

        return leoGui.LeoKeyEvent(
            c=self.c,
            char=ch,
            # char = None doesn't work at present.
            # But really, the binding should suffice.
            event=event,
            binding=binding,
            w=w,
            x=getattr(event, 'x', None) or 0,
            y=getattr(event, 'y', None) or 0,
            x_root=getattr(event, 'x_root', None) or 0,
            y_root=getattr(event, 'y_root', None) or 0,
        )
예제 #2
0
 def create_key_event(self, event, c, w, ch, tkKey, shortcut):
     trace = False and not g.unitTesting
     verbose = False
     if trace and verbose:
         g.trace('ch: %s, tkKey: %s, shortcut: %s' %
                 (repr(ch), repr(tkKey), repr(shortcut)))
     # Last-minute adjustments...
     if shortcut == 'Return':
         ch = '\n'  # Somehow Qt wants to return '\r'.
     elif shortcut == 'Escape':
         ch = 'Escape'
     # Switch the Shift modifier to handle the cap-lock key.
     if len(ch) == 1 and len(
             shortcut) == 1 and ch.isalpha() and shortcut.isalpha():
         if ch != shortcut:
             if trace and verbose: g.trace('caps-lock')
             shortcut = ch
     # Patch provided by resi147.
     # See the thread: special characters in MacOSX, like '@'.
     if sys.platform.startswith('darwin'):
         darwinmap = {
             'Alt-Key-5': '[',
             'Alt-Key-6': ']',
             'Alt-Key-7': '|',
             'Alt-slash': '\\',
             'Alt-Key-8': '{',
             'Alt-Key-9': '}',
             'Alt-e': '€',
             'Alt-l': '@',
         }
         if tkKey in darwinmap:
             shortcut = darwinmap[tkKey]
     char = ch
     # Auxiliary info.
     x = hasattr(event, 'x') and event.x or 0
     y = hasattr(event, 'y') and event.y or 0
     # Support for fastGotoNode plugin
     x_root = hasattr(event, 'x_root') and event.x_root or 0
     y_root = hasattr(event, 'y_root') and event.y_root or 0
     if trace and verbose:
         g.trace('ch: %s, shortcut: %s printable: %s' %
                 (repr(ch), repr(shortcut), ch in string.printable))
     return leoGui.LeoKeyEvent(c, char, event, shortcut, w, x, y, x_root,
                               y_root)
예제 #3
0
 def get_key_event(self, ch, w):
     m = self
     c = m.c
     k = c.k
     m.key_w = w
     if len(ch) > 1:
         key = None
         stroke = k.strokeFromSetting(ch).s
     else:
         stroke = key = ch
     return leoGui.LeoKeyEvent(c,
                               key,
                               stroke,
                               binding=None,
                               w=w,
                               x=0,
                               y=0,
                               x_root=0,
                               y_root=0)