Skip to content

Commit

Permalink
Merge pull request #264 from cary-rowen/fixExitProcessing
Browse files Browse the repository at this point in the history
Refactor to remove add_done_callback usage, ensuring safe passing of self.view as the parent to wx.MessageBox, resolving the issue of the dialog not appearing in the foreground.
  • Loading branch information
cary-rowen authored Aug 31, 2024
2 parents cc29a1f + cd7e7b0 commit 1a185ad
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions bookworm/ocr/ocr_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,22 +315,25 @@ def _continue_with_text_extraction(self, ocr_opts, output_file, progress_dlg):
target=self.service.current_ocr_engine.scan_to_text, args=args
)
progress_dlg.set_abort_callback(scan2text_process.cancel)
scan2text_process.add_done_callback(
wx.CallAfter,
wx.MessageBox,
_(
"Successfully processed {total} pages.\nExtracted text was written to: {file}"
).format(total=total, file=output_file),
_("OCR Completed"),
wx.ICON_INFORMATION,
)
for progress in scan2text_process:
progress_dlg.Update(
progress + 1,
f"Scanning page {progress} of {total}",

try:
for progress in scan2text_process:
progress_dlg.Update(
progress + 1,
f"Scanning page {progress} of {total}",
)
wx.CallAfter(
wx.MessageBox,
message = _(
"Successfully processed {total} pages.\nExtracted text was written to: {file}"
).format(total=total, file=output_file),
caption = _("OCR Completed"),
style = wx.ICON_INFORMATION | wx.OK,
parent = self.view # 设置 parent 确保对话框聚焦
)
progress_dlg.Dismiss()
wx.CallAfter(self.view.contentTextCtrl.SetFocus)
finally:
progress_dlg.Dismiss()
wx.CallAfter(self.view.contentTextCtrl.SetFocus)

def onChangeOCROptions(self, event):
self._get_ocr_options(from_cache=False)
Expand Down

0 comments on commit 1a185ad

Please sign in to comment.