Quellcode für miniworlds.actors.widgets.counter

import miniworlds.actors.widgets.label as mod_label


[Doku] class CounterLabel(mod_label.Label): """A counter label contains a ``description`` and a ``counter``. The counter starts with value 0 and can be modified with ``add`` and ``sub``. """ def __init__(self, description, value = 0, image=None): self.value = value self.description = description super().__init__(str(self), image) def __str__(self): return f"{self.description} : {str(self.value)}"
[Doku] def add(self, value): """Increase the counter by ``value``.""" self.value += value self.update_text()
[Doku] def sub(self, value): """Decrease the counter by ``value``.""" self.value -= value self.update_text()
[Doku] def get_value(self): return self.value
[Doku] def set(self, value): self.value = value self.update_text()
[Doku] def update_text(self): self.set_text(f"{self.description} : {str(self.value)}")