예제 #1
0
def test_queue_process():
    expected = {1, 2, 3, 4, 5}
    valid_input = [1, 4, 9, 16, 25]
    process = QueueProcess(target=_produce_sqrts, args=(valid_input, ))
    assert set(process) == expected

    # Test with invalid input
    invalid_input = (-16, -4, -1)
    process_iterator = iter(
        QueueProcess(target=_produce_sqrts, args=(invalid_input, )))
    with pytest.raises(ValueError):
        next(process_iterator)
예제 #2
0
 def search(self, request: doctools.SearchRequest):
     text = self.get_content()[request.text_range.as_slice()]
     yield from QueueProcess(
         target=doctools.search_single_page_document,
         args=(
             text,
             request,
         ),
         name="document-search",
     )
예제 #3
0
 def _continue_with_text_extraction(self, ocr_opts, output_file,
                                    progress_dlg):
     doc = self.service.reader.document
     total = len(doc)
     args = (doc, output_file, ocr_opts)
     scan2text_process = QueueProcess(
         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}",
         )
     progress_dlg.Dismiss()
     wx.CallAfter(self.view.contentTextCtrl.SetFocus)
예제 #4
0
 def search(document_path, request):
     args = (document_path, request)
     process = QueueProcess(target=_tools.do_search_book,
                            args=args,
                            name="bookworm-search")
     process.start()
     while True:
         value = process.queue.get()
         if value == -1:
             break
         yield value
     process.join()
예제 #5
0
 def export_to_text(document_path, target_filename):
     args = (document_path, target_filename)
     process = QueueProcess(target=_tools.do_export_to_text,
                            args=args,
                            name="bookworm-exporter")
     process.start()
     while True:
         value = process.queue.get()
         if value == -1:
             break
         yield value
     process.join()
예제 #6
0
 def search(self, request: doctools.SearchRequest):
     yield from QueueProcess(
         target=doctools.search_book, args=(self, request), name="document-search"
     )
예제 #7
0
 def export_to_text(self, target_filename: t.PathLike):
     return QueueProcess(
         target=doctools.export_to_plain_text,
         args=(self, target_filename),
         name="document-export",
     )