summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2011-10-08 19:40:37 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2011-10-08 19:40:37 +0100
commitb432ba5bab15983564ed2f25ad2b4ce72076fd0e (patch)
tree620e1d075192241db90852ddab43fd366868f966
parentb2465ffc82e8f2337d01d0d06eb9fd8ae345487a (diff)
parent53748dc7364851cc799bc6dd979a60ffbc7631e8 (diff)
Merge branch 'helpdialogs'
Conflicts: alot/command.py alot/ui.py
-rw-r--r--alot/command.py60
-rw-r--r--alot/completion.py2
-rw-r--r--alot/defaults/alot.rc16
-rw-r--r--alot/ui.py6
-rw-r--r--alot/widgets.py40
5 files changed, 124 insertions, 0 deletions
diff --git a/alot/command.py b/alot/command.py
index 0744a19f..ea32be45 100644
--- a/alot/command.py
+++ b/alot/command.py
@@ -1066,6 +1066,63 @@ class SendKeypressCommand(Command):
ui.keypress(self.key)
+class HelpCommand(Command):
+ def __init__(self, commandline='', **kwargs):
+ Command.__init__(self, **kwargs)
+ self.commandline = commandline.strip()
+
+ def apply(self, ui):
+ if self.commandline:
+ cmd = self.commandline.split(' ', 1)[0]
+ # TODO: how to I access COMMANDS from below?
+ ui.notify('no help for \'%s\'' % cmd, priority='error')
+ titletext = 'help for %s' % cmd
+ body = urwid.Text('helpstring')
+ return
+ else:
+ # get mappings
+ modemaps = dict(settings.config.items('%s-maps' % ui.mode))
+ globalmaps = dict(settings.config.items('global-maps'))
+
+ # build table
+ maxkeylength = len(max((modemaps).keys() + globalmaps.keys(),
+ key=len))
+ keycolumnwidth = maxkeylength + 2
+
+ linewidgets = []
+ # mode specific maps
+ linewidgets.append(urwid.Text(('helptexth1',
+ '\n%s-mode specific maps' % ui.mode)))
+ for (k, v) in modemaps.items():
+ line = urwid.Columns([('fixed', keycolumnwidth, urwid.Text(k)),
+ urwid.Text(v)])
+ linewidgets.append(line)
+
+ # global maps
+ linewidgets.append(urwid.Text(('helptexth1',
+ '\nglobal maps')))
+ for (k, v) in globalmaps.items():
+ if k not in modemaps:
+ line = urwid.Columns(
+ [('fixed', keycolumnwidth, urwid.Text(k)),
+ urwid.Text(v)])
+ linewidgets.append(line)
+
+ body = urwid.ListBox(linewidgets)
+ ckey = 'cancel'
+ titletext = 'Bindings Help (%s cancels)' % ckey
+
+ box = widgets.DialogBox(body, titletext,
+ bodyattr='helptext',
+ titleattr='helptitle')
+
+ # put promptwidget as overlay on main widget
+ overlay = urwid.Overlay(box, ui.mainframe, 'center',
+ ('relative', 70), 'middle',
+ ('relative', 70))
+ ui.show_as_root_until_keypress(overlay, 'cancel')
+
+
COMMANDS = {
'search': {
'refine': (RefineCommand, {}),
@@ -1120,6 +1177,7 @@ COMMANDS = {
'search': (SearchCommand, {}),
'shellescape': (ExternalCommand, {}),
'taglist': (TagListCommand, {}),
+ 'help': (HelpCommand, {}),
}
}
@@ -1183,6 +1241,8 @@ def interpret_commandline(cmdline, mode):
return commandfactory(cmd, mode=mode, headers=h)
elif cmd == 'attach':
return commandfactory(cmd, mode=mode, path=params)
+ elif cmd == 'help':
+ return commandfactory(cmd, mode=mode, commandline=params)
elif cmd == 'forward':
return commandfactory(cmd, mode=mode, inline=(params == '--inline'))
elif cmd == 'prompt':
diff --git a/alot/completion.py b/alot/completion.py
index 38d1eade..b5d75119 100644
--- a/alot/completion.py
+++ b/alot/completion.py
@@ -196,6 +196,8 @@ class CommandLineCompleter(Completer):
single_tag=False)
if cmd == 'toggletag':
res = self._tagscompleter.complete(params, localpos)
+ if cmd == 'help':
+ res = self._commandcompleter.complete(params, localpos)
if cmd in ['to', 'compose']:
res = self._contactscompleter.complete(params, localpos)
if cmd in ['attach', 'edit', 'save']:
diff --git a/alot/defaults/alot.rc b/alot/defaults/alot.rc
index 93018cc2..61e9ef76 100644
--- a/alot/defaults/alot.rc
+++ b/alot/defaults/alot.rc
@@ -70,6 +70,7 @@ esc = cancel
enter = select
@ = refresh
+? = help
I = search tag:inbox AND NOT tag:killed
L = taglist
shift tab = bprevious
@@ -195,6 +196,12 @@ notify_normal_bg = default
message_attachment_focussed_fg = light gray
threadline_authors_fg = dark green
message_header_bg = dark gray
+helptitle_bg = dark blue
+helptitle_fg = white
+helptext_bg = dark gray
+helptext_fg = default
+helptexth1_bg = dark gray
+helptexth1_fg = bold,underline
[256c-theme]
bufferlist_focus_fg = #ffa
@@ -263,6 +270,12 @@ notify_normal_bg = default
message_attachment_focussed_fg = light gray
threadline_authors_fg = #6d6
message_header_bg = dark gray
+helptitle_bg = g35
+helptitle_fg = white,bold,underline
+helptext_bg = g35
+helptext_fg = default
+helptexth1_bg = g35
+helptexth1_fg = bold,underline
[1c-theme]
message_body = default
@@ -298,3 +311,6 @@ threadline_mailcount = default
threadline_focus = standout
threadline_tags = bold
bufferlist_focus = standout
+helptitle = standout
+helptext = default
+helptexth1 = underline
diff --git a/alot/ui.py b/alot/ui.py
index 67f9b7b8..8039b037 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -100,6 +100,12 @@ class UI(object):
def keypress(self, key):
self.inputwrap.keypress((150, 20), key, interpret=False)
+ def show_as_root_until_keypress(self, w, key):
+ def oe():
+ self.inputwrap.set_root(self.mainframe)
+ helpwrap = widgets.CatchKeyWidgetWrap(w, key, on_catch=oe)
+ self.inputwrap.set_root(helpwrap)
+
def prompt(self, prefix='>', text=u'', completer=None, tab=0, history=[]):
"""prompt for text input
diff --git a/alot/widgets.py b/alot/widgets.py
index 962706aa..791c5419 100644
--- a/alot/widgets.py
+++ b/alot/widgets.py
@@ -27,6 +27,46 @@ from helper import tag_cmp
import message
+class DialogBox(urwid.WidgetWrap):
+ def __init__(self, body, title, bodyattr=None, titleattr=None):
+ self.body = urwid.LineBox(body)
+ self.title = urwid.Text(title)
+ if titleattr is not None:
+ self.title = urwid.AttrMap(self.title, titleattr)
+ if bodyattr is not None:
+ self.body = urwid.AttrMap(self.body, bodyattr)
+
+ box = urwid.Overlay(self.title, self.body,
+ align='center',
+ valign='top',
+ width=len(title),
+ height=None,
+ )
+ urwid.WidgetWrap.__init__(self, box)
+
+ def selectable(self):
+ return self.body.selectable()
+
+ def keypress(self, size, key):
+ return self.body.keypress(size, key)
+
+
+class CatchKeyWidgetWrap(urwid.WidgetWrap):
+ def __init__(self, widget, key, on_catch):
+ urwid.WidgetWrap.__init__(self, widget)
+ self.key = key
+ self.on_catch = on_catch
+
+ def selectable(self):
+ return True
+
+ def keypress(self, size, key):
+ if key == self.key:
+ self.on_catch()
+ elif self._w.selectable():
+ return self._w.keypress(size, key)
+
+
class ThreadlineWidget(urwid.AttrMap):
def __init__(self, tid, dbman):
self.dbman = dbman