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()
This commit is contained in:
Mika Bostrom 2010-08-30 12:35:49 +03:00
parent 18a863a5de
commit 2b97d938f1

View File

@ -83,14 +83,29 @@ re_Places = re.compile("_[0-9]$")
import codecs import codecs
encoder = codecs.lookup(Configuration.LOCALE_ENCODING) 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): def do_tip(widget, tip):
_tip = Charset.to_utf8(tip) _tip = Charset.to_utf8(tip)
widget.set_tooltip_text(_tip) widget.set_tooltip_text(_tip)
def do_stat(stat_dict, player = 24, stat = 'vpip'): def do_stat(stat_dict, player = 24, stat = 'vpip'):
statname = stat
match = re_Places.search(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] # If decimal places have been defined, override result[1]
# NOTE: decimal place override ALWAYS assumes the raw result is a # 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 # to three decimal places anyhow, so they are unlikely override
# candidates. # candidates.
if match: if match:
base = stat[0:-2]
places = int(stat[-1:]) places = int(stat[-1:])
result[1] = '%.*f' % (places, 100.0*result[0]) result = __stat_override(places, result)
return result return result
# OK, for reference the tuple returned by the stat is: # OK, for reference the tuple returned by the stat is: