From 2b97d938f1f549bfb7eb69ca7b364766892b7f0e Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Mon, 30 Aug 2010 12:35:49 +0300 Subject: [PATCH] Fix HUD bug with specified decimals If any stat in HUD had manually specified number of decimal places, the entire hand processing stopped when the first such stat was encountered. Now really do the decimal place formatting as it was supposed to work. Also, for future reference: tuples are immutable - you can't overwrite any tuple member. Hence the need for new routine, __stat_override() --- pyfpdb/Stats.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pyfpdb/Stats.py b/pyfpdb/Stats.py index 285a45ea..3616fa87 100755 --- a/pyfpdb/Stats.py +++ b/pyfpdb/Stats.py @@ -83,14 +83,29 @@ re_Places = re.compile("_[0-9]$") import codecs encoder = codecs.lookup(Configuration.LOCALE_ENCODING) + +# Since tuples are immutable, we have to create a new one when +# overriding any decimal placements. Copy old ones and recreate the +# second value in tuple to specified format- +def __stat_override(decimals, stat_vals): + s = '%.*f' % (decimals, 100.0*stat_vals[0]) + res = (stat_vals[0], s, stat_vals[2], + stat_vals[3], stat_vals[4], stat_vals[5]) + return res + + def do_tip(widget, tip): _tip = Charset.to_utf8(tip) widget.set_tooltip_text(_tip) def do_stat(stat_dict, player = 24, stat = 'vpip'): + statname = stat match = re_Places.search(stat) - result = eval("%(stat)s(stat_dict, %(player)d)" % {'stat': stat, 'player': player}) + if match: # override if necessary + statname = stat[0:-2] + + result = eval("%(stat)s(stat_dict, %(player)d)" % {'stat': statname, 'player': player}) # If decimal places have been defined, override result[1] # NOTE: decimal place override ALWAYS assumes the raw result is a @@ -99,9 +114,8 @@ def do_stat(stat_dict, player = 24, stat = 'vpip'): # to three decimal places anyhow, so they are unlikely override # candidates. if match: - base = stat[0:-2] places = int(stat[-1:]) - result[1] = '%.*f' % (places, 100.0*result[0]) + result = __stat_override(places, result) return result # OK, for reference the tuple returned by the stat is: