Skip to content

Commit

Permalink
status reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
lversaw committed Feb 8, 2024
1 parent c7d81a0 commit 7027c3e
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions usfm/txt2USFM.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,26 @@
chapMarker_re = re.compile(r'\\c *[\d]{1,3}', re.UNICODE)

def reportError(msg):
if gui:
reportProgress(msg)
reportToGui(msg, '<<ScriptMessage>>')
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, '<<ScriptMessage>>')
print(msg)

def reportProgress(msg):
with gui.progress_lock:
gui.progress = msg
gui.event_generate('<<ScriptProgress>>', when="tail")
reportToGui(msg, '<<ScriptProgress>>')
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.
Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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('<<ScriptEnd>>', when="tail")

if __name__ == "__main__":
Expand Down

0 comments on commit 7027c3e

Please sign in to comment.