From 3f230a0faea72cc8d079204bc73197a742390dc8 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 6 Sep 2017 21:06:05 +0100 Subject: [PATCH] mon/tripemon.in: Add simple function for formatting `statslayout' entries. This adds extra functionality: now an entry can be a function rather than just a format string. But nothing takes advantage of this yet, so there's still no functional change. --- mon/tripemon.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mon/tripemon.in b/mon/tripemon.in index 1e62f03e..360d44d4 100644 --- a/mon/tripemon.in +++ b/mon/tripemon.in @@ -1256,6 +1256,10 @@ statsxlate = \ ('ip-bytes-in', xlate_bytes), ('ip-bytes-out', xlate_bytes)] +def format_stat(format, dict): + if callable(format): return format(dict) + else: return format % dict + ## How to lay out the stats dialog. Format is (LABEL, FORMAT): LABEL is ## the label to give the entry box; FORMAT is the format string to write into ## the entry. @@ -1362,7 +1366,7 @@ class PeerWindow (TrivialWindow): stat[s] = trans(stat[s]) stat.update(me.peer.__dict__) for label, format in statslayout: - me.e[label].set_text(format % stat) + me.e[label].set_text(format_stat(format, stat)) GL.timeout_add(1000, lambda: me.cr.switch() and False) me.cr.parent.switch() me.cr = None -- 2.11.0