From 7027c3ed50728e0fffc5b415448a49d74d6614ea Mon Sep 17 00:00:00 2001 From: Larry Versaw Date: Thu, 8 Feb 2024 11:28:26 -0700 Subject: [PATCH] status reporting --- usfm/txt2USFM.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/usfm/txt2USFM.py b/usfm/txt2USFM.py index 270a4e2c..288edb17 100644 --- a/usfm/txt2USFM.py +++ b/usfm/txt2USFM.py @@ -28,17 +28,26 @@ chapMarker_re = re.compile(r'\\c *[\d]{1,3}', re.UNICODE) def reportError(msg): - if gui: - reportProgress(msg) + reportToGui(msg, '<>') sys.stderr.write(msg + '\n') sys.stderr.flush() # Sends a progress report to the GUI. # To be called only if the gui is set. +def reportStatus(msg): + reportToGui(msg, '<>') + print(msg) + def reportProgress(msg): - with gui.progress_lock: - gui.progress = msg - gui.event_generate('<>', when="tail") + reportToGui(msg, '<>') + print(msg) + +def reportToGui(msg, event): + if gui: + with gui.progress_lock: + gui.progress = msg if not gui.progress else f"{gui.progress}\n{msg}" + gui.event_generate(event, when="tail") + # Calls ensureMarkers() to put in missing chapter and verse markers. # Inserts chapter title where appropriate. @@ -598,9 +607,7 @@ def getChapterTitle(chapterpath): # This method is called to convert the chapters in the current folder to USFM def convertBook(folder, bookId, bookTitle): msg = f"CONVERTING {shortname(folder)}" - if gui: - reportProgress(msg) - print(msg) + reportProgress(msg) sys.stdout.flush() target_dir = config['target_dir'] @@ -650,10 +657,8 @@ def main(app = None): Path(target_dir).mkdir(exist_ok=True) convert(source_dir, target_dir) - print("\nDone.") + reportStatus("\nDone.") if gui: - with gui.progress_lock: - gui.progress = "\nDone." gui.event_generate('<>', when="tail") if __name__ == "__main__":