This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Printr/printr/ItterPrintr/__init__.py

29 lines
755 B
Python
Raw Permalink Normal View History

2015-10-08 15:39:22 +01:00
from printr.exceptions import FormattingError
from printr.utils import write
2015-09-26 21:50:36 +01:00
2015-09-26 14:04:41 +01:00
class ItterPrintr():
def __init__(self, string, maxValue, start, diff=1):
self.string = string
self.maxValue = maxValue
self.start = start
self.diff = diff
self.value = self.start
self.buildString()
def buildString(self):
2015-09-26 21:50:36 +01:00
try:
return self.string.format(c=self.value, m=self.maxValue)
except:
raise FormattingError()
2015-09-26 14:04:41 +01:00
def reachedLimit(self):
return self.maxValue <= self.value
def update(self, inc=True):
2015-10-08 15:39:22 +01:00
write(self.buildString(), commit=(not self.reachedLimit()))
2015-09-26 14:04:41 +01:00
if inc:
self.inc()
def inc(self):
2015-09-26 21:50:36 +01:00
self.value += self.diff