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
def __init__(self, c, char, event, binding, w, x=None, y=None, x_root=None, y_root=None): '''Ctor for LeoKeyEvent class.''' trace = False and not g.unitTesting 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 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
def __init__(self, c, char, shortcut, w, x, y, x_root, y_root): trace = False and not g.unitTesting k = c.k 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.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
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
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
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), f"(LeoKeyEvent) {stroke!r} {g.callers()}" 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
def get_ch(self, event, stroke, w): '''Get the ch from the stroke.''' ch = g.toUnicode(event and event.char or '') if self.expanding: return None if w.hasSelection(): return None assert g.isStrokeOrNone(stroke), stroke if stroke in ('BackSpace', 'Delete'): return None d = {'Return': '\n', 'Tab': '\t', 'space': ' ', 'underscore': '_'} if stroke: ch = d.get(stroke.s, stroke.s) if len(ch) > 1: if (stroke.find('Ctrl+') > -1 or stroke.find('Alt+') > -1 or stroke.find('Meta+') > -1): ch = '' else: ch = event.char if event else '' else: ch = event.char return ch
def get_ch(self, event, stroke, w): '''Get the ch from the stroke.''' ch = g.toUnicode(event and event.char or '') if self.expanding: return None if w.hasSelection(): return None assert g.isStrokeOrNone(stroke), stroke if stroke in ('BackSpace', 'Delete'): return None d = {'Return': '\n', 'Tab': '\t', 'space': ' ', 'underscore': '_'} if stroke: ch = d.get(stroke.s, stroke.s) if len(ch) > 1: if (stroke.find('Ctrl+') > -1 or stroke.find('Alt+') > -1 or stroke.find('Meta+') > -1 ): ch = '' else: ch = event and event.char or '' else: ch = event.char return ch
def expandAbbrev(self, event, stroke): ''' Not a command. Called from k.masterCommand to expand abbreviations in event.widget. Words start with '@'. ''' trace = False and not g.unitTesting verbose = False c = self.c ch = event and event.char or '' w = self.editWidget(event, forceFocus=False) if not w: return False if self.expanding: return False if w.hasSelection(): return False assert g.isStrokeOrNone(stroke), stroke if stroke in ('BackSpace', 'Delete'): if trace and verbose: g.trace(stroke) return False d = {'Return': '\n', 'Tab': '\t', 'space': ' ', 'underscore': '_'} if stroke: ch = d.get(stroke.s, stroke.s) if len(ch) > 1: if (stroke.find('Ctrl+') > -1 or stroke.find('Alt+') > -1 or stroke.find('Meta+') > -1 ): ch = '' else: ch = event and event.char or '' else: ch = event.char if trace and verbose: g.trace('ch', repr(ch), 'stroke', repr(stroke)) # New code allows *any* sequence longer than 1 to be an abbreviation. # Any whitespace stops the search. s = w.getAllText() j = w.getInsertPoint() i, prefixes = j - 1, [] while i >= 0 and s[i] not in ' \t\n': prefixes.append(s[i: j]) i -= 1 prefixes = list(reversed(prefixes)) if '' not in prefixes: prefixes.append('') for prefix in prefixes: i = j - len(prefix) word = prefix + ch val, tag = self.tree_abbrevs_d.get(word), 'tree' # if val: g.trace('*****',word,'...\n\n',len(val)) if not val: val, tag = self.abbrevs.get(word, (None, None)) if val: if trace and verbose: g.trace(repr(word), 'val', val, 'tag', tag) # Require a word match if the abbreviation is itself a word. if ch in ' \t\n': word = word.rstrip() if word.isalnum() and word[0].isalpha(): if i == 0 or s[i - 1] in ' \t\n': break else: i -= 1 else: break else: i -= 1 else: return False c.abbrev_subst_env['_abr'] = word if tag == 'tree': self.last_hit = c.p.copy() self.expand_tree(w, i, j, val, word) c.frame.body.forceFullRecolor() c.bodyWantsFocusNow() else: # Never expand a search for text matches. place_holder = '__NEXT_PLACEHOLDER' in val if place_holder: expand_search = bool(self.last_hit) else: self.last_hit = None expand_search = False if trace: g.trace('expand_search', expand_search, 'last_hit', self.last_hit) self.expand_text(w, i, j, val, word, expand_search) c.frame.body.forceFullRecolor() c.bodyWantsFocusNow() # Restore the selection range. if self.save_ins: if trace: g.trace('sel', self.save_sel, 'ins', self.save_ins) ins = self.save_ins # pylint: disable=unpacking-non-sequence sel1, sel2 = self.save_sel if sel1 != sel2: # some abbreviations *set* the selection range # so only restore non-empty ranges w.setSelectionRange(sel1, sel2, insert=ins) return True