aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-02-09 11:30:35 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-02-09 11:30:35 +1300
commitd564086377db72f5d8f0cf9083d0b34b25d76016 (patch)
treec4dd66b3a2a14b8db3411e03a62cb553c3f47267
parent4914dbc971166a8a394c9b5033b63de5c5078036 (diff)
downloadmitmproxy-d564086377db72f5d8f0cf9083d0b34b25d76016.tar.gz
mitmproxy-d564086377db72f5d8f0cf9083d0b34b25d76016.tar.bz2
mitmproxy-d564086377db72f5d8f0cf9083d0b34b25d76016.zip
KVEditor: show a msg when editing an empty set of values
Just having nothing on screen can be confusing to users.
-rw-r--r--libmproxy/console/kveditor.py25
1 files changed, 22 insertions, 3 deletions
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: