# HG changeset patch # User David Douard # Date 1197934713 -3600 # Node ID b930440af3547ec96a971e0f5ee69cff0cc12dd2 # Parent 07e2cbf140df2927c8e4ce2a3dbc0dea1d2b8c04 make header_formatter a little bit smarter (interpret bool values when it can) diff -r 07e2cbf140df -r b930440af354 HP3562A/__init__.py --- a/HP3562A/__init__.py Tue Dec 18 00:23:10 2007 +0100 +++ b/HP3562A/__init__.py Tue Dec 18 00:38:33 2007 +0100 @@ -13,6 +13,7 @@ """ import struct +import re import gpib ######################################## @@ -52,13 +53,29 @@ """ Pretty print a data block (trace, state or coord) """ + bool_re = re.compile(r'((?P.*) )?(?P\w+/\w+)( (?P.*))?') + todisp = [] for row in head_struct: - key = row[0] + key = row[0] + typ = row[1] val = header.get(key, "N/A") if isinstance(val, basestring): val = repr(val) - else: + elif typ is bool and isinstance(val, typ): + m = bool_re.match(key) + if m: + d = m.groupdict() + key = "" + if d['before']: + key += d['before'] + if d['after']: + key += d['after'] + key = key.capitalize() + val = d['flag'].split('/')[not val] + else: + val = str(val) + else: val = str(val) todisp.append((key+":", val)) maxk = max([len(k) for k, v in todisp])