From 0742bc4fd0dc9ba368d4518e08c8baf60973be0c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 28 Jan 2011 12:18:01 +1300 Subject: [PATCH] Nicer statusbar messages, with timed expiry. --- libmproxy/console.py | 14 +++++++++++--- test/test_utils.py | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libmproxy/console.py b/libmproxy/console.py index 11f867446..757a74970 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import Queue, mailcap, mimetypes, tempfile, os, subprocess, glob +import Queue, mailcap, mimetypes, tempfile, os, subprocess, glob, time import os.path, sys import cStringIO import urwid.curses_display @@ -528,11 +528,14 @@ class ActionBar(WWrap): class StatusBar(WWrap): def __init__(self, master, text): self.master, self.text = master, text + self.expire = None self.ab = ActionBar() self.ib = urwid.AttrWrap(urwid.Text(""), 'foot') self.w = urwid.Pile([self.ib, self.ab]) def redraw(self): + if self.expire and time.time() > self.expire: + self.message("") status = urwid.Columns([ urwid.Text([('title', "mproxy:%s"%self.master.server.port)]), urwid.Text( @@ -561,7 +564,11 @@ class StatusBar(WWrap): def prompt(self, prompt): return self.ab.prompt(prompt) - def message(self, msg): + def message(self, msg, expire=None): + if expire: + self.expire = time.time() + float(expire)/1000 + else: + self.expire = None self.ab.message(msg) @@ -827,6 +834,7 @@ class ConsoleMaster(controller.Master): if self.conn_list_view: self.conn_list_view.set_focus(0) self.sync_list_view() + return "Flows loaded from %s"%path def helptext(self): text = [] @@ -967,7 +975,7 @@ class ConsoleMaster(controller.Master): self.prompt_done() msg = p(txt, *args) if msg: - self.statusbar.message(msg) + self.statusbar.message(msg, 1000) def prompt_cancel(self): self.prompt_done() diff --git a/test/test_utils.py b/test/test_utils.py index 4880cc891..606490590 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -229,7 +229,7 @@ class uprettybody(libpry.AutoTree): assert utils.prettybody(s) s = "".join([chr(i) for i in range(256)]) - print utils.prettybody(s) + assert utils.prettybody(s)