Reverse the gradient in battery segment

Closes #910
This commit is contained in:
ZyX 2014-07-07 19:37:59 +04:00
parent cbcab959b4
commit 39316c429b
2 changed files with 14 additions and 10 deletions

View File

@ -1162,18 +1162,22 @@ def battery(pl, format='{capacity:3.0%}', steps=5, gamify=False, full_heart='♥
'contents': full_heart * numer, 'contents': full_heart * numer,
'draw_inner_divider': False, 'draw_inner_divider': False,
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 99, # Using zero as “nothing to worry about”: it is least alert color.
'gradient_level': 0,
}) })
ret.append({ ret.append({
'contents': empty_heart * (denom - numer), 'contents': empty_heart * (denom - numer),
'draw_inner_divider': False, 'draw_inner_divider': False,
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 1, # Using a hundred as it is most alert color.
'gradient_level': 100,
}) })
else: else:
ret.append({ ret.append({
'contents': format.format(capacity=(capacity / 100.0)), 'contents': format.format(capacity=(capacity / 100.0)),
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': capacity, # Gradients are “least alert most alert” by default, capacity has
# the opposite semantics.
'gradient_level': 100 - capacity,
}) })
return ret return ret

View File

@ -533,30 +533,30 @@ class TestCommon(TestCase):
self.assertEqual(common.battery(pl=pl), [{ self.assertEqual(common.battery(pl=pl), [{
'contents': '86%', 'contents': '86%',
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 86 'gradient_level': 14,
}]) }])
self.assertEqual(common.battery(pl=pl, format='{capacity:.2f}'), [{ self.assertEqual(common.battery(pl=pl, format='{capacity:.2f}'), [{
'contents': '0.86', 'contents': '0.86',
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 86 'gradient_level': 14,
}]) }])
self.assertEqual(common.battery(pl=pl, steps=7), [{ self.assertEqual(common.battery(pl=pl, steps=7), [{
'contents': '86%', 'contents': '86%',
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 86 'gradient_level': 14,
}]) }])
self.assertEqual(common.battery(pl=pl, gamify=True), [ self.assertEqual(common.battery(pl=pl, gamify=True), [
{ {
'contents': '♥♥♥♥', 'contents': '♥♥♥♥',
'draw_inner_divider': False, 'draw_inner_divider': False,
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 99 'gradient_level': 0
}, },
{ {
'contents': '', 'contents': '',
'draw_inner_divider': False, 'draw_inner_divider': False,
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 1 'gradient_level': 100
} }
]) ])
self.assertEqual(common.battery(pl=pl, gamify=True, full_heart='+', empty_heart='-', steps='10'), [ self.assertEqual(common.battery(pl=pl, gamify=True, full_heart='+', empty_heart='-', steps='10'), [
@ -564,13 +564,13 @@ class TestCommon(TestCase):
'contents': '++++++++', 'contents': '++++++++',
'draw_inner_divider': False, 'draw_inner_divider': False,
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 99 'gradient_level': 0
}, },
{ {
'contents': '--', 'contents': '--',
'draw_inner_divider': False, 'draw_inner_divider': False,
'highlight_group': ['battery_gradient', 'battery'], 'highlight_group': ['battery_gradient', 'battery'],
'gradient_level': 1 'gradient_level': 100
} }
]) ])