Commit ac022b09 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Now loading bar is working

parent c0d284d5
......@@ -102,6 +102,8 @@ if D_HIERARCHY in ('CLIENT', 'client'):
# MyFig: Overlay on matplotlib.Figure class
from .myFig_client import MyFig_client as MyFig
from .progressbar import ProgressBar
from .mplClient import MplClient
elif(D_HIERARCHY in ('SERVER', 'server')):
......
......@@ -2,7 +2,7 @@ from . import socket, AF_INET, SOCK_STREAM
from . import INFO, DBUG, WARN, SEVR, SPCE
SIZE_STATUS_MAX = 1024
from . import progressbar
from . import ProgressBar
from . import D_DEBUG
DEBUG = D_DEBUG
......@@ -254,7 +254,7 @@ class MplClient(object):
# Wait for the formatted data
packedData = self.waitForData(sock, dataSize)
print(INFO+str(packedData))
# print(INFO+str(packedData))
# Unpack
header, datas, errmsg = self.unpackFormattedData(packedData)
......@@ -320,7 +320,7 @@ class MplClient(object):
header, content, errmsg = eval(packedData)
except:
print(WARN+'The data sent by the server could not be evaluated')
print(SPCE+str(packedData))
# print(SPCE+str(packedData))
return((None, None, None))
# The tuple of as many strings as axes
......
from __future__ import print_function
import sys
class ProgressBar(object):
DEFAULT = 'Progress: %(bar)s %(percent)3d%%'
FULL = '%(bar)s %(current)d/%(total)d (%(percent)3d%%) %(remaining)d to go'
DEFAULT = "{bar} {current}/{total} ({percent}%) {remaining} to go"
FULL = "{bar} {current}/{total} kB ({percent:3.1f}%) {remaining:>10} kB to go"
def __init__(self, total, width=40, fmt=DEFAULT, symbol='=',
output=sys.stderr):
......@@ -10,8 +14,25 @@ class ProgressBar(object):
self.width = width
self.symbol = symbol
self.output = output
self.fmt = re.sub(r'(?P<name>%\(.+?\))d',
r'\g<name>%dd' % len(str(total)), fmt)
if total > 1024:
unit = 'kB'
self.convert = 1024
else:
unit = 'Bit'
self.convert = 1
if total > 1048576:
unit = 'MB'
self.convert = 1048576
if total > 1073741824:
unit = 'GB'
self.convert = 1073741824
lg = len(str(total/self.convert))
self.fmt = "{bar} {current}/{total} "+str(unit)+" ({percent:3.1f}%) {remaining:>"+str(lg)+"} "+str(unit)+" to go"
self.current = 0
......@@ -22,13 +43,15 @@ class ProgressBar(object):
bar = '[' + self.symbol * size + ' ' * (self.width - size) + ']'
args = {
'total': self.total,
'total': self.total / self.convert,
'bar': bar,
'current': self.current,
'current': self.current / self.convert,
'percent': percent * 100,
'remaining': remaining
'remaining': remaining / self.convert
}
print('\r' + self.fmt % args, file=self.output, end='')
print('\r' + self.fmt.format(**args), file=self.output, end='')
self.current += inc
def done(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment