Skip to content

Commit

Permalink
Add exception handling for the QThread
Browse files Browse the repository at this point in the history
Signed-off-by: Akashdeep Dhar <[email protected]>
  • Loading branch information
gridhead authored and sdglitched committed Oct 5, 2024
1 parent 7406c35 commit d34355b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 11 additions & 1 deletion gi_loadouts/face/scan/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,18 @@ def register_return_from_scanning(self, rslt: tuple) -> None:
:return:
"""
area, main, seco, team, levl, rare, duration, expt = rslt

if expt:
self.show_dialog(
QMessageBox.Information,
"Faulty scanning",
f"Please consider checking your input after ensuring that the proper Tesseract OCR executable has been selected.\n\n{expt}"
)
return

self.arti_shot.setPixmap(self.shot)
area, main, seco, team, levl, rare, duration = rslt

if area in [self.arti_dist.itemText(indx) for indx in range(self.arti_dist.count())]:
self.arti_dist.setCurrentText(area)
if team in [self.arti_type.itemText(indx) for indx in range(self.arti_type.count())]:
Expand Down
12 changes: 8 additions & 4 deletions gi_loadouts/face/scan/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ def scan_artifact(self) -> None:
text = image_to_string(self.snap, lang=conf.tempname, config=f"--tessdata-dir {location}")
except (OSError, TesseractError) as expt:
if isinstance(expt, OSError):
raise OSError("Selected executable of Tesseract OCR is unfunctional.") from expt
elif isinstance(expt, TesseractError):
raise ValueError("Processing failed as either Tesseract OCR executable ceased to function or training data was tampered with.") from expt
expt = "Selected executable of Tesseract OCR is unfunctional."
else:
expt = "Processing failed as either Tesseract OCR executable ceased to function or training data was tampered with."
stoptime = time()
rslt = area, main, seco, team, levl, rare, (stoptime - strttime), expt
self.result.emit(rslt)
return

# DISTRIBUTION AREA
areadict = {}
Expand Down Expand Up @@ -148,6 +152,6 @@ def scan_artifact(self) -> None:

stoptime = time()

rslt = area, main, seco, team, levl, rare, (stoptime - strttime)
rslt = area, main, seco, team, levl, rare, (stoptime - strttime), None

self.result.emit(rslt)

0 comments on commit d34355b

Please sign in to comment.