Fixed progress bar on windows + formatting fixes
parent
e2cb686214
commit
bad9ff69d0
|
@ -10,7 +10,7 @@ import argparse
|
|||
|
||||
|
||||
class SSTVCommand(object):
|
||||
""" Main class to handle the command line features """
|
||||
"""Main class to handle the command line features"""
|
||||
|
||||
examples_of_use = """
|
||||
examples:
|
||||
|
@ -22,7 +22,8 @@ examples:
|
|||
"""
|
||||
|
||||
def __init__(self):
|
||||
""" Handle command line arguments """
|
||||
"""Handle command line arguments"""
|
||||
|
||||
self._audio_file = None
|
||||
self._output_file = None
|
||||
|
||||
|
@ -38,7 +39,8 @@ examples:
|
|||
self.close()
|
||||
|
||||
def init_args(self):
|
||||
""" Initialise argparse parser """
|
||||
"""Initialise argparse parser"""
|
||||
|
||||
version = "sstv 0.1"
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
|
@ -69,7 +71,8 @@ examples:
|
|||
return parser
|
||||
|
||||
def parse_args(self):
|
||||
""" Parse command line arguments """
|
||||
"""Parse command line arguments"""
|
||||
|
||||
parser = self.init_args()
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -93,6 +96,8 @@ examples:
|
|||
return args
|
||||
|
||||
def start(self):
|
||||
"""Start decoder"""
|
||||
|
||||
with SSTVDecoder(self._audio_file) as sstv:
|
||||
img = sstv.decode()
|
||||
if img is None: # No SSTV signal found
|
||||
|
@ -106,7 +111,8 @@ examples:
|
|||
img.save("result.png")
|
||||
|
||||
def close(self):
|
||||
""" Closes any input/output files if they exist """
|
||||
"""Closes any input/output files if they exist"""
|
||||
|
||||
if self._audio_file is not None and not self._audio_file.closed:
|
||||
self._audio_file.close()
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
"""Shared methods"""
|
||||
|
||||
from os import get_terminal_size
|
||||
from sys import stderr, stdout
|
||||
from sys import stderr, stdout, platform
|
||||
|
||||
|
||||
def log_message(message="", show=True, err=False, recur=False, prefix=True):
|
||||
"""Simple print wrapper"""
|
||||
|
||||
if not show:
|
||||
return
|
||||
out = stdout
|
||||
|
@ -23,14 +25,18 @@ def log_message(message="", show=True, err=False, recur=False, prefix=True):
|
|||
|
||||
|
||||
def progress_bar(progress, complete, message="", show=True):
|
||||
"""Simple loading bar"""
|
||||
|
||||
if not show:
|
||||
return
|
||||
|
||||
message = ' '.join(["[SSTV]", message])
|
||||
cols = get_terminal_size().columns
|
||||
percent_on = True
|
||||
level = progress / complete
|
||||
bar_size = min(cols - len(message) - 10, 100)
|
||||
bar = ""
|
||||
|
||||
if bar_size > 5:
|
||||
fill_size = round(bar_size * level)
|
||||
bar = "[{}]".format(''.join(['#' * fill_size,
|
||||
|
@ -42,6 +48,9 @@ def progress_bar(progress, complete, message="", show=True):
|
|||
if percent_on:
|
||||
percent = "{:4.0f}%".format(level * 100)
|
||||
|
||||
if platform == "win32":
|
||||
message = '\r' + message
|
||||
|
||||
align = cols - len(message) - len(percent)
|
||||
not_end = not progress == complete
|
||||
log_message("{}{:>{width}}{}".format(message, bar, percent, width=align),
|
||||
|
|
Loading…
Reference in New Issue