Large restructure
This commit is contained in:
parent
bc9b9d3762
commit
1329866b2c
8 changed files with 65 additions and 59 deletions
32
printr/EllipsisPrintr/__init__.py
Normal file
32
printr/EllipsisPrintr/__init__.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
from printr.utils import write
|
||||||
|
|
||||||
|
class EllipsisPrintr():
|
||||||
|
def __init__(self, string, max=3, erase_after=False):
|
||||||
|
self.string = string
|
||||||
|
self.max = max
|
||||||
|
self.count = -1
|
||||||
|
self.erase_after = erase_after
|
||||||
|
|
||||||
|
def update(self, commit=False):
|
||||||
|
self.clear()
|
||||||
|
ellipsis = "." * self.count
|
||||||
|
write(self.string + ellipsis, commit=commit)
|
||||||
|
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')
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
return self
|
||||||
|
def __exit__(self, type, value, traceback):
|
||||||
|
if self.erase_after:
|
||||||
|
self.clear()
|
||||||
|
self.commit()
|
|
@ -1,4 +1,5 @@
|
||||||
from exceptions import FormattingError
|
from printr.exceptions import FormattingError
|
||||||
|
from printr.utils import write
|
||||||
|
|
||||||
|
|
||||||
class ItterPrintr():
|
class ItterPrintr():
|
||||||
|
@ -20,8 +21,7 @@ class ItterPrintr():
|
||||||
return self.maxValue <= self.value
|
return self.maxValue <= self.value
|
||||||
|
|
||||||
def update(self, inc=True):
|
def update(self, inc=True):
|
||||||
ending = '\r' if not self.reachedLimit() else '\n'
|
write(self.buildString(), commit=(not self.reachedLimit()))
|
||||||
print(self.buildString(), end=ending)
|
|
||||||
if inc:
|
if inc:
|
||||||
self.inc()
|
self.inc()
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
# Import python modules
|
|
||||||
import os
|
import os
|
||||||
from json import loads as json_loads
|
from json import load as json_load
|
||||||
|
|
||||||
# Import Printr Modules
|
|
||||||
from .simplePrintr import SimplePrintr
|
|
||||||
from .itterPrintr import ItterPrintr
|
|
||||||
from .ellipsisPrintr import EllipsisPrintr
|
|
||||||
|
|
||||||
# Initialise
|
|
||||||
PRINTR_PATH = os.path.dirname(os.path.abspath(__file__))
|
PRINTR_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
with open(PRINTR_PATH + '/details.json') as file:
|
from .ItterPrintr import ItterPrintr
|
||||||
PRINTR_DETAILS = json_loads(file)
|
from .EllipsisPrintr import EllipsisPrintr
|
||||||
|
|
||||||
|
with open(PRINTR_PATH + '/../details.json') as file:
|
||||||
|
PRINTR_DETAILS = json_load(file)
|
||||||
|
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
class EllipsisPrintr():
|
|
||||||
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')
|
|
|
@ -1,11 +0,0 @@
|
||||||
class SimplePrintr():
|
|
||||||
@classmethod
|
|
||||||
def write(string, commit=False):
|
|
||||||
if commit:
|
|
||||||
print(string)
|
|
||||||
else:
|
|
||||||
print(string, end='\r')
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def commit():
|
|
||||||
print()
|
|
6
printr/utils.py
Normal file
6
printr/utils.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
def write(string, commit=False):
|
||||||
|
ending = '\n' if commit else '\r'
|
||||||
|
print(string, end=ending)
|
||||||
|
|
||||||
|
def commit():
|
||||||
|
print()
|
23
setup.py
23
setup.py
|
@ -1,5 +1,5 @@
|
||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
from json import loads as json_loads
|
from json import load as json_load
|
||||||
LONG_DESCRIPTION = None
|
LONG_DESCRIPTION = None
|
||||||
try:
|
try:
|
||||||
LONG_DESCRIPTION = open('README.md').read()
|
LONG_DESCRIPTION = open('README.md').read()
|
||||||
|
@ -8,17 +8,16 @@ except:
|
||||||
|
|
||||||
DETAILS = None
|
DETAILS = None
|
||||||
with open('details.json') as file:
|
with open('details.json') as file:
|
||||||
DETAILS = json_loads(file)
|
DETAILS = json_load(file)
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name = DETAILS.name,
|
name = DETAILS['name'],
|
||||||
packages = DETAILS.packages,
|
packages = DETAILS['packages'],
|
||||||
version = DETAILS.version,
|
version = DETAILS['version'],
|
||||||
description = DETAILS.description,
|
description = DETAILS['description'],
|
||||||
long_description = LONG_DESCRIPTION,
|
long_description = LONG_DESCRIPTION,
|
||||||
author = DETAILS.author,
|
author = DETAILS['author'],
|
||||||
author_email = DETAILS.author_email,
|
author_email = DETAILS['author_email'],
|
||||||
url = DETAILS.url,
|
url = DETAILS['url'],
|
||||||
license = DETAILS.license,
|
license = DETAILS['license'],
|
||||||
platforms = DETAILS.platform
|
platforms = DETAILS['platforms']
|
||||||
)
|
)
|
7
tests/context_manager.py
Normal file
7
tests/context_manager.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from printr import EllipsisPrintr
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
with EllipsisPrintr('Printing') as p:
|
||||||
|
for i in range(30):
|
||||||
|
p.update()
|
||||||
|
sleep(0.1)
|
Reference in a new issue