chiark / gitweb /
mon/tripemon.in: Add simple function for formatting `statslayout' entries.
[tripe] / mon / tripemon.in
index 1e62f03e517f4fda790bef3f19c81caa951d67e9..360d44d416b1bfc89ecb6876415dcf1eb74c1e46 100644 (file)
@@ -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