From 106f69f7035abf1cef27137a1d0a2eed4d9036e3 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 26 Sep 2015 14:04:41 +0100 Subject: [PATCH] Initialised Module --- README.md | 0 printr/__init__.py | 3 +++ printr/ellipsisPrintr.py | 23 +++++++++++++++++++++++ printr/itterPrintr.py | 23 +++++++++++++++++++++++ printr/simplePrintr.py | 11 +++++++++++ setup.py | 19 +++++++++++++++++++ 6 files changed, 79 insertions(+) create mode 100644 README.md create mode 100644 printr/__init__.py create mode 100644 printr/ellipsisPrintr.py create mode 100644 printr/itterPrintr.py create mode 100644 printr/simplePrintr.py create mode 100644 setup.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/printr/__init__.py b/printr/__init__.py new file mode 100644 index 0000000..2d52e2a --- /dev/null +++ b/printr/__init__.py @@ -0,0 +1,3 @@ +from simplePrintr import SimplePrintr +from itterPrintr import ItterPrintr +from ellipsisPrintr import EllipsisPrintr \ No newline at end of file diff --git a/printr/ellipsisPrintr.py b/printr/ellipsisPrintr.py new file mode 100644 index 0000000..595a92e --- /dev/null +++ b/printr/ellipsisPrintr.py @@ -0,0 +1,23 @@ +class EllipsisPrinter(): + def __init__(self, string, max=5): + self.string = string + self.max = max + self.count = -1 + + def update(self, commit=False): + self.clear() + ellipsis = "." * self.count + ending = '\r' if not commit else '\n' + print(self.string + ellipsis, end=ending) + if self.count >= self.max: + self.zero() + self.count += 1 + + def zero(self): + self.count = -1 + + def commit(self): + print() + + def clear(self): + print(' ' * (len(self.string) + self.max), end='\r') \ No newline at end of file diff --git a/printr/itterPrintr.py b/printr/itterPrintr.py new file mode 100644 index 0000000..fff155a --- /dev/null +++ b/printr/itterPrintr.py @@ -0,0 +1,23 @@ +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): + return self.string.format(c=self.value, m=self.maxValue) + + def reachedLimit(self): + return self.maxValue <= self.value + + def update(self, inc=True): + ending = '\r' if not self.reachedLimit() else '\n' + print(self.buildString(), end=ending) + if inc: + self.inc() + + def inc(self): + self.value += self.diff diff --git a/printr/simplePrintr.py b/printr/simplePrintr.py new file mode 100644 index 0000000..bce5911 --- /dev/null +++ b/printr/simplePrintr.py @@ -0,0 +1,11 @@ +class SimplePrintr(): + @classmethod + def write(string, commit=False): + if commit: + print(string) + else: + print(string, end='\r') + + @classmethod + def commit(): + print() \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f7d4510 --- /dev/null +++ b/setup.py @@ -0,0 +1,19 @@ +from distutils.core import setup + +LONG_DESCRIPTION = None +try: + LONG_DESCRIPTION = open('README.md').read() +except: + pass + +setup( + name = 'Printr', + packages = ['printr'], + version = '0.0.1', + description = 'Python module to allow a print line to be updated after printing', + long_description = LONG_DESCRIPTION + author = 'Jake Howard', + url = 'https://github.com/RealOrangeOne/Printr', + license='MIT', + platforms=['any'] +) \ No newline at end of file