Ejemplo n.º 1
0
    def keydown(self, key, mod, ch):
        key = keybindings.get(key)
        modifiers = set()
        for mask, ident in modbindings:
            if mod & mask != 0:
                modifiers.add(ident)

        if self.hook('keyboard', self, key, modifiers, ch):
            return

        selection = self.selection
        shift = 'shift' in modifiers
        if 'ctrl' in modifiers:
            if key == "q":
                exit(0)
            if key == "t":
                print self.last_highlight
            if key == "a":
                selection.expand()
            if key == "s":
                selection.buffer.save()
#            if key == "h":
#                self.selection = selection.move(-1, shift)
#            if key == "l":
#                self.selection = selection.move(+1, shift)
#            if key == "j" and selection.descendable(selection.cursor):
#                self.selection = selection.descend(selection.cursor)
#            if key == "e":
#                self.selection = selection.build(shift)
#            if key == "c" and selection.ascendable:
#                self.selection = selection.collapse()
#            if key == "k" and selection.ascendable:
#                self.selection = selection.ascend
#            if key == "b":
#                self.selection = selection.move(selection.bounds[0], shift, relative=False)
#            if key == "w":
#                self.selection = selection.move(selection.bounds[1], shift, relative=False)
#            if key == "m":
#                start, stop = selection.textbounds
#                selection = selection.grasp(start, stop)
#                kw = dict(name=''.join(selection.yank))
#                self.selection = selection.splice([]).modify(kw)
#
#                #self.selection = selection.splice([]).modify({'name':name})
#        elif 'enter' == key:
#            if shift:
#                self.selection = selection.walk_backward()
#            else:
#                self.selection = selection.walk_forward()
        elif 'tab' == key:
            name = choice(['toy-object', 'reindeer', 'baaz', 'santa', 'foo', 'guux', 'lol'])
            holes = [choice([star, dot]) for _ in range(randint(0, 5))]
            selection.replace([empty_template(name, *holes)], branch_in=True)
        elif 'backspace' == key:
            if selection.empty: selection.move(-1, True)
            selection.remove()
        elif 'delete' == key:
            if selection.empty: selection.move(+1, True)
            selection.remove()
        elif 'left' == key:
            selection.move(-1, shift)
        elif 'right' == key:
            selection.move(+1, shift)
        elif 'enter' == key and shift:
            selection.walk_backwards()
        elif 'enter' == key:
            selection.walk()
        elif 'up' == key:
            selection.move(selection.bounds[0], shift, relative=False)
        elif 'down' == key:
            selection.move(selection.bounds[1], shift, relative=False)
        elif len(ch) == 1:
            selection.replace([ch])
Ejemplo n.º 2
0
    def keyboard(self, editor, key, modifiers, ch):
        selection = editor.selection
        if selection.parent.name in ('int', 'variable', 'string'):
            return
        structure = None

        shift = 'shift' in modifiers
        if ch == '*':
            structure = empty_template('mul', dot, dot)
        if ch == '+':
            structure = empty_template('add', dot, dot)
        if ch == '-':
            structure = empty_template('sub', dot, dot)
        if ch == '=':
            structure = empty_template('equal', dot, dot)
        if ch == 'L':
            structure = empty_template('let', dot, dot)
        if ch == 'S':
            structure = empty_template('set', dot, dot)
        if ch == 'C':
            structure = empty_template('call', dot, star)
        if ch == '"':
            structure = empty_template('string', star)
        if ch == 'F':
            structure = empty_template('function', star, star)
        if ch == 'I':
            structure = empty_template('if', dot, star, star)
        if ch == '[':
            structure = empty_template('list', star)
        if ch == 'Z':
            structure = empty_template('env')

        if structure:
            selection.replace([structure], branch_in=True)
            return True

        if ch.isdigit() and len(ch) == 1:
            selection.replace([empty_template('int', star)], branch_in=True)
            selection.replace([ch])
            return True
        if ch.isalnum() and len(ch) == 1:
            selection.replace([empty_template('variable', star)], branch_in=True)
            selection.replace([ch])
            return True