Ejemplo n.º 1
0
 def init_resolver(self, uri):
     try:
         resolver = UriResolver(uri)
     except ReaderError as e:
         log.exception(f"Failed to resolve document uri: {uri}",
                       exc_info=True)
         self.view.notify_user(
             _("Failed to open document"),
             _("The document you are trying to open could not be opened in Bookworm."
               ),
             icon=wx.ICON_ERROR,
         )
         return
     if not resolver.should_read_async():
         doc = self.resolve_document(resolver)
         if doc is not None:
             self.load(doc)
     else:
         AsyncSnakDialog(
             task=partial(self.resolve_document, resolver),
             done_callback=self.load,
             dismiss_callback=lambda: self._cancellation_token.
             request_cancellation() or True,
             message=_("Opening document, please wait..."),
             parent=self.view,
         )
Ejemplo n.º 2
0
 def onUpdateTesseractEngine(self, event):
     AsyncSnakDialog(
         task=tesseract_download.is_new_tesseract_version_available,
         done_callback=self._on_update_tesseract_version_retreived,
         # Translators: message of a dialog
         message=_("Checking for updates. Please wait..."),
         parent=wx.GetApp().GetTopWindow(),
     )
Ejemplo n.º 3
0
 def init_wikipedia_search(self, term, sure_exists=False):
     AsyncSnakDialog(
         task=partial(self.define_term_using_wikipedia,
                      term,
                      sure_exists=sure_exists),
         done_callback=self.view_wikipedia_definition,
         dismiss_callback=lambda: self._cancel_query.set() or True,
         message=_("Retrieving information, please wait..."),
         parent=self.view,
     )
Ejemplo n.º 4
0
 def pop_folder_navigation_stack(self):
     try:
         prev_source = self.__source_navigation_stack.pop()
     except IndexError:
         return
     AsyncSnakDialog(
         message=_("Retrieving items..."),
         task=partial(self.get_source_items, prev_source),
         done_callback=self._get_items_callback,
         parent=self.frame,
     )
Ejemplo n.º 5
0
 def onOpenonWeb(self, event):
     task = partial(
         self.retreive_web_viewer_url,
         os.fspath(self.reader.document.get_file_system_path()),
     )
     AsyncSnakDialog(
         task=task,
         done_callback=self.server_data_ready_callback,
         message=_("Openning in web viewer..."),
         parent=self.view,
     )
Ejemplo n.º 6
0
 def _run_ocr(self, ocr_request, callback):
     ocr_started.send(sender=self.view)
     # Show a modal dialog
     sounds.ocr_start.play()
     future_callback = functools.partial(self._process_ocr_result, callback)
     self._wait_dlg = AsyncSnakDialog(
         task=functools.partial(
             self.service.current_ocr_engine.preprocess_and_recognize,
             ocr_request),
         done_callback=future_callback,
         message=_("Running OCR, please wait..."),
         dismiss_callback=self._on_ocr_cancelled,
         parent=self.view,
     )
Ejemplo n.º 7
0
 def _on_bundle_documents(self, provider):
     retval = wx.MessageBox(
         _("This will create copies of all of the documents you have added to your Local Bookshelf.\nAfter this operation, you can open documents stored in your bookshelf, even if you have deleted or moved the original documents.\n\nPlease note that this action will create duplicate copies of all of your added documents."
           ),
         _("Bundle Documents?"),
         style=wx.YES_NO | wx.ICON_EXCLAMATION,
     )
     if retval != wx.YES:
         return
     AsyncSnakDialog(
         task=self._do_bundle_documents,
         message=_("Bundling documents. Please wait..."),
         done_callback=self._done_bundling_callback,
         parent=wx.GetApp().GetTopWindow(),
     )
Ejemplo n.º 8
0
 def _on_search_bookshelf(self, provider):
     dialog = SearchBookshelfDialog(wx.GetApp().GetTopWindow(),
                                    _("Search Bookshelf"))
     with dialog:
         retval = dialog.ShowModal()
     if retval is None:
         return
     search_query, is_title, is_content = retval
     task = partial(self._do_search_bookshelf, search_query, is_title,
                    is_content)
     AsyncSnakDialog(
         parent=wx.GetApp().GetTopWindow(),
         task=task,
         done_callback=self._search_bookshelf_callback,
         message=_("Searching bookshelf..."),
     )
Ejemplo n.º 9
0
 def _on_add_documents_from_folder(self, provider):
     top_frame = wx.GetApp().GetTopWindow()
     dialog = AddFolderToLocalBookshelfDialog(
         top_frame,
         _("Import Documents From Folder"),
     )
     with dialog:
         retval = dialog.ShowModal()
     if retval is None:
         return
     folder, category_name, should_add_to_fts = retval
     task = partial(import_folder_to_bookshelf, folder, category_name,
                    should_add_to_fts)
     AsyncSnakDialog(
         task=task,
         done_callback=self._on_folder_import_done,
         message=_("Importing documents from folder. Please wait..."),
         parent=wx.GetApp().GetTopWindow(),
     )
Ejemplo n.º 10
0
 def _on_update_tesseract_version_retreived(self, future):
     try:
         if is_update_available := future.result():
             retval = wx.MessageBox(
                 _("A new version of Tesseract OCr engine is available for download.\nIt is strongly recommended to update to the latest version for the best accuracy and performance.\nWould you like to update to the new version?"
                   ),
                 _("Update Tesseract OCr Engine?"),
                 style=wx.YES_NO | wx.ICON_EXCLAMATION,
             )
             if retval != wx.YES:
                 return
             AsyncSnakDialog(
                 task=tesseract_download.remove_tesseract,
                 done_callback=lambda fut: self.onDownloadTesseractEngine(
                     None),
                 # Translators: message of a dialog
                 message=_(
                     "Removing old Tesseract version. Please wait..."),
                 parent=wx.GetApp().GetTopWindow(),
             )
         else:
Ejemplo n.º 11
0
        except IndexError:
            return
        AsyncSnakDialog(
            message=_("Retrieving items..."),
            task=partial(self.get_source_items, prev_source),
            done_callback=self._get_items_callback,
            parent=self.frame,
        )

    def activate_current_item(self):
        if (item := self.selected_item) is None:
            return
        if isinstance(item, ItemContainerSource):
            AsyncSnakDialog(
                message=_("Retrieving items..."),
                task=partial(self.get_source_items, item),
                done_callback=self._navigate_to_folder,
                parent=self.frame,
            )
        else:
            self._do_open_document(item)

    def onContextMenu(self, event):
        if (item := self.selected_item) is None:
            return
        if isinstance(item, ItemContainerSource):
            actions = item.get_source_actions()
        else:
            item_actions = [
                action for action in self.source.get_item_actions(item)
                if action.decider(item)
            ]
Ejemplo n.º 12
0
            if (retval := dialog.ShowModal()) is not None:
                category_name, tags_names, should_add_to_fts = retval
            else:
                return
        task = partial(
            self._do_add_files_to_bookshelf,
            filenames,
            category_name=category_name,
            tags_names=tags_names,
            should_add_to_fts=should_add_to_fts,
        )
        message = (_("Importing document...")
                   if len(filenames) == 1 else _("Importing documents..."))
        AsyncSnakDialog(
            task=task,
            done_callback=self._on_document_imported_callback,
            message=message,
            parent=wx.GetApp().GetTopWindow(),
        )

    def _do_add_files_to_bookshelf(self, filenames, category_name, tags_names,
                                   should_add_to_fts):
        for filename in filenames:
            add_document_to_bookshelf(
                DocumentUri.from_filename(filename),
                category_name=category_name,
                tags_names=tags_names,
                should_add_to_fts=should_add_to_fts,
                database_file=DEFAULT_BOOKSHELF_DATABASE_FILE,
            )

    def _on_document_imported_callback(self, future):