コード例 #1
0
 def onExportAsPlainText(self, event):
     book_title = slugify(self.reader.current_book.title)
     filename, _nope = wx.FileSelectorEx(
         # Translators: the title of a dialog to save the exported book
         _("Save As"),
         default_path=wx.GetUserHome(),
         default_filename=f"{book_title}.txt",
         # Translators: a name of a file format
         wildcard=_("Plain Text") + " (*.txt)|.txt",
         flags=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
         parent=self,
     )
     if not filename.strip():
         return
     total = len(self.reader.document)
     dlg = wx.ProgressDialog(
         # Translators: the title of a dialog showing
         # the progress of book export process
         _("Exporting Book"),
         # Translators: the message of a dialog showing the progress of book export
         _("Converting your book to plain text."),
         parent=self,
         maximum=total - 1,
         style=wx.PD_APP_MODAL | wx.PD_REMAINING_TIME | wx.PD_AUTO_HIDE,
     )
     export_func = self.reader.document.export_to_text
     for progress in export_func(self.reader.document.filename, filename):
         # Translators: a message shown when the book is being exported
         dlg.Update(progress, _("Converting book..."))
     dlg.Close()
     dlg.Destroy()
コード例 #2
0
 def onSubmit(self, event):
     suffix = self.reader.get_view_title()
     renderer = NotesExporter.renderers[self.formatChoice.GetSelection()]
     if self.outputRangeRb.GetSelection() == 0:
         notes = self.annotator.get_list(asc=True)
     else:
         notes = self.annotator.get_for_section(
             self.reader.active_section.unique_identifier, asc=True)
         pager = self.reader.active_section.pager
         suffix += f" {pager.first + 1}-{pager.last + 1}"
     if not notes.count():
         wx.MessageBox(
             # Translators: the content of a message dialog
             _("There are no notes for this book or the selected section.\n"
               "Please make sure you have added some notes before using the export functionality."
               ),
             # Translators: the title of a message dialog
             _("No Notes"),
             style=wx.ICON_WARNING,
         )
         return self.Close()
     filename = slugify(suffix) + renderer.output_ext
     saveExportedFD = wx.FileDialog(
         self,
         # Translators: the title of a save file dialog asking the user for a filename to export notes to
         _("Export To"),
         defaultDir=wx.GetUserHome(),
         defaultFile=filename,
         wildcard=
         f"{_(renderer.display_name)} (*{renderer.output_ext})|{renderer.output_ext}",
         style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
     )
     if saveExportedFD.ShowModal() != wx.ID_OK:
         return
     file_path = saveExportedFD.GetPath().strip()
     saveExportedFD.Destroy()
     try:
         file_path = file_path.encode("mbcs")
     except UnicodeEncodeError:
         wx.MessageBox(
             # Translators: the content of a message telling the user that the file name is invalid
             _("The provided file name is not valid. Please try again with a different name."
               ),
             # Translators: the title of a message telling the user that the provided file name is invalid
             _("Invalid File Name"),
             style=wx.ICON_ERROR,
         )
         self.fileCtrl.SetValue("")
         self.fileCtrl.SetFocus()
         return
     exporter = NotesExporter(
         renderer_name=renderer.name,
         notes=notes,
         doc_title=self.reader.current_book.title,
         filename=file_path,
     )
     self.shouldOpenAfterExport = self.openAfterExportCheckBox.GetValue()
     notes_export_completed.connect(self.onExportCompleted, sender=exporter)
     exporter.render_to_file()
     self.Close()
コード例 #3
0
ファイル: menubar.py プロジェクト: blindpandas/bookworm
 def onExportAsPlainText(self, event):
     book_title = slugify(self.reader.current_book.title)
     filename, _nope = wx.FileSelectorEx(
         # Translators: the title of a dialog to save the exported book
         _("Save As"),
         default_path=wx.GetUserHome(),
         default_filename=f"{book_title}.txt",
         # Translators: a name of a file format
         wildcard=_("Plain Text") + " (*.txt)|.txt",
         flags=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
         parent=self.view,
     )
     if not filename.strip():
         return
     total = len(self.reader.document)
     dlg = RobustProgressDialog(
         self.view,
         # Translators: the title of a dialog showing
         # the progress of book export process
         _("Exporting Document"),
         # Translators: the message of a dialog showing the progress of book export
         _("Converting document to plain text."),
         maxvalue=total,
         can_hide=True,
         can_abort=True,
     )
     process = self.reader.document.export_to_text(filename)
     dlg.set_abort_callback(process.cancel)
     self._continue_with_export_to_text(process, dlg, total)
コード例 #4
0
 def onScanToTextFile(self, event):
     ocr_opts = self._get_ocr_options(from_cache=False, force_save=True)
     if ocr_opts is None:
         return
     # Get output file path
     filename = f"{self.view.reader.current_book.title}.txt"
     saveExportedFD = wx.FileDialog(
         self.view,
         # Translators: the title of a save file dialog asking the user for a filename to export notes to
         _("Save as"),
         defaultDir=wx.GetUserHome(),
         defaultFile=filename,
         # Translators: file type in a save as dialog
         wildcard=_("Plain Text") + "(*.txt)|.txt",
         style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
     )
     if saveExportedFD.ShowModal() != wx.ID_OK:
         return
     output_file = saveExportedFD.GetPath().strip()
     saveExportedFD.Destroy()
     if not output_file:
         return
     # Continue with OCR
     progress_dlg = RobustProgressDialog(
         self.view,
         # Translators: the title of a progress dialog
         _("Scanning Pages"),
         # Translators: the message of a progress dialog
         message=_("Preparing book"),
         maxvalue=len(self.service.reader.document),
         can_hide=True,
         can_abort=True,
     )
     self._continue_with_text_extraction(ocr_opts, output_file,
                                         progress_dlg)
コード例 #5
0
 def onBrowse(self, event):
     saveExportedFD = wx.FileDialog(
         self,
         # Translators: the title of a save file dialog asking the user for a filename to export annotations to
         _("Save As"),
         defaultDir=wx.GetUserHome(),
         defaultFile="",
         wildcard=(
             f"{_(self.selected_renderer.display_name)} (*{self.selected_renderer.output_ext})"
             f"|{self.selected_renderer.output_ext}"
         ),
         style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
     )
     if saveExportedFD.ShowModal() == wx.ID_OK:
         self.outputFileTextCtrl.SetValue(saveExportedFD.GetPath().strip())
     saveExportedFD.Destroy()
コード例 #6
0
ファイル: FileTreeDemo.py プロジェクト: wangdyna/wxPython
    def __init__(self, parent, log):
        super(TestPanel, self).__init__(parent)

        # Attributes
        self.ftree = eclib.FileTree(self)
        self.ftree.AddWatchDirectory(wx.GetUserHome())
        self.selbtn = wx.Button(self, label="Selected Files")
        self.addbtn = wx.DirPickerCtrl(self,
                                       message="Add Watch",
                                       style=wx.DIRP_CHANGE_DIR)
        self.addbtn.PickerCtrl.SetLabel("Add Watch")
        self.rmbtn = wx.Button(self, label="Remove Watch")
        self.setselbtn = wx.Button(self, label="Select a File")
        self.log = log

        # Layout
        self.__DoLayout()

        # Event Handlers
        self.Bind(wx.EVT_BUTTON, self.OnGetSelected, self.selbtn)
        self.Bind(wx.EVT_DIRPICKER_CHANGED, self.OnAddWatch, self.addbtn)
        self.Bind(wx.EVT_BUTTON, self.OnRemoveWatch, self.rmbtn)
        self.Bind(wx.EVT_BUTTON, self.OnSelectFile, self.setselbtn)
コード例 #7
0
        """Get data from given tree item
        @param item: TreeItemId

        """
        data = None
        # avoid assertions in base class when retrieving data...
        if item and item.IsOk():
            try:
                data = super(FileTree, self).GetPyData(item)
            except wx.PyAssertionError:
                pass
        return data

    def SortParentDirectory(self, item):
        """Sort the parent directory of the given item"""
        parent = self.GetItemParent(item)
        if parent.IsOk():
            self.SortChildren(parent)


#-----------------------------------------------------------------------------#
# Test
if __name__ == '__main__':
    app = wx.App(False)
    f = wx.Frame(None)
    ft = FileTree(f)
    d = wx.GetUserHome()
    ft.AddWatchDirectory(d)
    f.Show()
    app.MainLoop()