archive
/
Printr
Archived
1
Fork 0

Large restructure

This commit is contained in:
Jake Howard 2015-10-08 15:39:22 +01:00
parent bc9b9d3762
commit 1329866b2c
8 changed files with 65 additions and 59 deletions

View 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()

View File

@ -1,4 +1,5 @@
from exceptions import FormattingError
from printr.exceptions import FormattingError
from printr.utils import write
class ItterPrintr():
@ -20,8 +21,7 @@ class ItterPrintr():
return self.maxValue <= self.value
def update(self, inc=True):
ending = '\r' if not self.reachedLimit() else '\n'
print(self.buildString(), end=ending)
write(self.buildString(), commit=(not self.reachedLimit()))
if inc:
self.inc()

View File

@ -1,17 +1,13 @@
# Import python modules
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__))
with open(PRINTR_PATH + '/details.json') as file:
PRINTR_DETAILS = json_loads(file)
from .ItterPrintr import ItterPrintr
from .EllipsisPrintr import EllipsisPrintr
with open(PRINTR_PATH + '/../details.json') as file:
PRINTR_DETAILS = json_load(file)
def get_version():

View File

@ -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')

View File

@ -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
View File

@ -0,0 +1,6 @@
def write(string, commit=False):
ending = '\n' if commit else '\r'
print(string, end=ending)
def commit():
print()

View File

@ -1,5 +1,5 @@
from distutils.core import setup
from json import loads as json_loads
from json import load as json_load
LONG_DESCRIPTION = None
try:
LONG_DESCRIPTION = open('README.md').read()
@ -8,17 +8,16 @@ except:
DETAILS = None
with open('details.json') as file:
DETAILS = json_loads(file)
DETAILS = json_load(file)
setup(
name = DETAILS.name,
packages = DETAILS.packages,
version = DETAILS.version,
description = DETAILS.description,
name = DETAILS['name'],
packages = DETAILS['packages'],
version = DETAILS['version'],
description = DETAILS['description'],
long_description = LONG_DESCRIPTION,
author = DETAILS.author,
author_email = DETAILS.author_email,
url = DETAILS.url,
license = DETAILS.license,
platforms = DETAILS.platform
author = DETAILS['author'],
author_email = DETAILS['author_email'],
url = DETAILS['url'],
license = DETAILS['license'],
platforms = DETAILS['platforms']
)

7
tests/context_manager.py Normal file
View 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)