From d564086377db72f5d8f0cf9083d0b34b25d76016 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 9 Feb 2012 11:30:35 +1300 Subject: KVEditor: show a msg when editing an empty set of values Just having nothing on screen can be confusing to users. --- libmproxy/console/kveditor.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'libmproxy/console/kveditor.py') diff --git a/libmproxy/console/kveditor.py b/libmproxy/console/kveditor.py index e74895bb..ee1daaa9 100644 --- a/libmproxy/console/kveditor.py +++ b/libmproxy/console/kveditor.py @@ -88,8 +88,8 @@ class KVItem(common.WWrap): class KVWalker(urwid.ListWalker): - def __init__(self, lst): - self.lst = lst + def __init__(self, lst, editor): + self.lst, self.editor = lst, editor self.maxk = max(len(v[0]) for v in lst) if lst else 20 if self.maxk < 20: self.maxk = 20 @@ -97,6 +97,10 @@ class KVWalker(urwid.ListWalker): self.focus_col = 0 self.editing = False + def _modified(self): + self.editor.show_empty_msg() + return urwid.ListWalker._modified(self) + def get_current_value(self): if self.lst: return self.lst[self.focus][self.focus_col] @@ -187,10 +191,25 @@ class KVEditor(common.WWrap): p = urwid.Text(title) p = urwid.Padding(p, align="left", width=("relative", 100)) p = urwid.AttrWrap(p, "heading") - self.walker = KVWalker(self.value) + self.walker = KVWalker(self.value, self) self.lb = KVListBox(self.walker) self.w = urwid.Frame(self.lb, header = p) self.master.statusbar.update("") + self.show_empty_msg() + + def show_empty_msg(self): + if self.walker.lst: + self.w.set_footer(None) + else: + self.w.set_footer( + urwid.Text( + [ + ("highlight", "No values. Press "), + ("key", "a"), + ("highlight", " to add some."), + ] + ) + ) def keypress(self, size, key): if self.walker.editing: -- cgit v1.2.3