bindings.py from gzz at Krugle
Show bindings.py syntax highlighted
#
# Copyright (c) 2002, Benja Fallenstein
#
# This file is part of Gzz.
#
# Gzz is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Gzz is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
# Public License for more details.
#
# You should have received a copy of the GNU Lesser General
# Public License along with Gzz; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#
"""
Default bindings for the Gzz client.
Note: These bindings are only used with the PotionFallbackBinder,
not with gzz.view.DefaultBinder.
"""
import gzz, java
from gzz.potion.potions import *
from gzz.modules.email import *
def call(list, type=None):
if type is None: type = gzz.potion.CommandCall
if list is None: return None
if isinstance(list, gzz.potion.Expression): return list
#print list
head = list[0]
params = [call(l, gzz.potion.FunctionCall) for l in list[1:]]
return type(head(), params)
def action(list, win=1):
return gzz.client.PotionFallbackBinder.Action(call(list), win)
arr = gzz.client.PotionFallbackBinder.Arrow
def map(dict):
m = java.util.HashMap()
for k,v in dict.items(): m.put(k, v)
return m
def fn(fn):
return call(fn, gzz.potion.FunctionCall)
def const(i):
return ConstantExpression(i, str(i))
search_mode = {}
normal_mode = {
'Up': arr(1,1,-1), 'i': arr(1,1,-1), 'e': arr(0,1,-1),
'Down': arr(1,1,1), ',': arr(1,1,1), 'c': arr(0,1,1),
'Left': arr(1,0,-1), 'j': arr(1,0,-1), 's': arr(0,1,-1),
'Right': arr(1,0,1), 'l': arr(1,0,1), 'f': arr(0,0,1),
'k': arr(1,2,1), 'K': arr(1,2,-1),
'd': arr(0,2,1), 'D': arr(0,2,-1),
'n': action([NewCell, None]),
'-': action([Connect, [PrefixOrOther], None]),
'h': action([Hop2, None]),
'p': action([Put,[ThisWindow], [PrefixOrOther]], 1),
'P': action([Put,[ThisWindow], [PrefixOrOther]], 0),
'g': action([Go, [PrefixOrOther]], 1),
'G': action([Go, [PrefixOrOther]], 0),
't': action([Clone,[PrefixOrRight], None]),
'T': action([Clone,[PrefixOrLeft], None]),
'm': action([ToggleMark, [ThisWindow]], 1),
'M': action([ToggleMark, [ThisWindow]], 0),
'Alt-M': action([MarkHalfRank, [PrefixOrThis], None]),
'q': action(call([Quit])),
'Q': action(call([Quit])),
'x': action(call([ChangeDim, const(0), const(1)]), 1),
'y': action(call([ChangeDim, const(1), const(1)]), 1),
'z': action(call([ChangeDim, const(2), const(1)]), 1),
'X': action(call([ChangeDim, const(0), const(1)]), 0),
'Y': action(call([ChangeDim, const(1), const(1)]), 0),
'Z': action(call([ChangeDim, const(2), const(1)]), 0),
'Alt-X': action(call([ChangeDim, const(0), const(-1)]), 1),
'Alt-Y': action(call([ChangeDim, const(1), const(-1)]), 1),
'Alt-Z': action(call([ChangeDim, const(2), const(-1)]), 1),
'Alt-Shift-X': action(call([ChangeDim, const(0), const(-1)]), 0),
'Alt-Shift-Y': action(call([ChangeDim, const(1), const(-1)]), 0),
'Alt-Shift-Z': action(call([ChangeDim, const(2), const(-1)]), 0),
'v': action(call([ChangeView, const(1)])),
'Alt-V': action(call([ChangeView, const(-1)])),
'b': action(call([Break, None])),
'B': action(call([Break, None])),
'Delete': action(call([Delete, [PrefixOrThis]])),
'Alt-Backspace': action(call([Delete, [PrefixOrThis]])),
'Shift-Delete': action(call([Delete, [PrefixOrThis]])),
'Alt-Shift-Backspace': action(call([Delete, [PrefixOrThis]])),
'o': action(call([Go, [RootClone, [ThisWindow]]]), 1),
'O': action(call([Go, [RootClone, [ThisWindow]]]), 0),
'Tab': action(call([SwitchToTextMode])),
'Tabulator': action(call([SwitchToTextMode])),
'Ctrl-E': action(call([ExtEdit, [PrefixOrThis]]), 1),
'Ctrl-Shift-E': action(call([ExtEdit, [PrefixOrThis]]), 0),
'Ctrl-V': action(call([ViewContainedText, [PrefixOrThis]]), 1),
'Ctrl-Shift-V': action(call([ViewContainedText, [PrefixOrThis]]), 0),
'Ctrl-9': action(call([ChangeCellView, const(1)])),
'Ctrl-A': fn([AllEmailsThat, None]),
'Ctrl-F': fn([FromFilterFn, None]),
'Ctrl-T': fn([ToFilterFn, None]),
'Ctrl-O': fn([OlderFilterFn, None]),
'Ctrl-Alt-O': fn([NewerFilterFn, None]),
'Alt-S': fn([SubjectFilterFn, None]),
'&': fn([AndFilterFn, None, None]),
'|': fn([OrFilterFn, None, None]),
}
edit_mode = {
gzz.client.PotionFallbackBinder.CHAR_KEY:
action(call([InsertChar, [EventKey]])),
'Left': action(call([TextCursorLeft])),
'Right': action(call([TextCursorRight])),
'Tab': action(call([SwitchToNormalMode])),
'Tabulator': action(call([SwitchToNormalMode])),
'Backspace': action(call([DeleteChar])),
}
bindingsByMode = java.util.HashMap()
bindingsByMode.put(gzz.client.PotionFallbackBinder.NORMAL_MODE,
map(normal_mode))
bindingsByMode.put("text mode", map(text_mode))
See more files for this project here