chiark / gitweb /
mon/tripemon.in: Add simple function for formatting `statslayout' entries.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 6 Sep 2017 20:06:05 +0000 (21:06 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 14 Jun 2018 09:34:25 +0000 (10:34 +0100)
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

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