Merge branch 'mika'

This commit is contained in:
steffen123 2010-08-30 17:25:44 +02:00
commit b434759037

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: