def onOpenDocumentation(self, event): help_filename = f"bookworm.{'html' if app.is_frozen else 'md'}" lang = app.current_language.given_lang docs = paths.docs_path(lang, help_filename) wx.LaunchDefaultApplication(str(docs))
def __init__(self): self.menuBar = wx.MenuBar() self._page_turn_timer = wx.Timer(self) self._last_page_turn = 0.0 self._reset_search_history() # The menu fileMenu = wx.Menu() toolsMenu = wx.Menu() speechMenu = wx.Menu() annotationsMenu = wx.Menu() helpMenu = wx.Menu() # A submenu for recent files self.recentFilesMenu = wx.Menu() # add items to the menu # File menu # Translators: the label of an ietm in the application menubar fileMenu.Append(wx.ID_OPEN, _("Open...\tCtrl-O")) fileMenu.AppendSeparator() # Translators: the label of an ietm in the application menubar fileMenu.Append(BookRelatedMenuIds.export, _("&Save As Plain Text...")) fileMenu.AppendSeparator() fileMenu.Append( BookRelatedMenuIds.closeCurrentFile, # Translators: the label of an ietm in the application menubar _("&Close Current Book\tCtrl-W"), # Translators: the help text of an ietm in the application menubar _("Close the currently open e-book"), ) fileMenu.AppendSeparator() fileMenu.AppendSubMenu( self.recentFilesMenu, # Translators: the label of an ietm in the application menubar _("&Recent Books"), # Translators: the help text of an ietm in the application menubar _("Opens a list of recently opened books."), ) self.recentFilesMenu.Append( wx.ID_CLEAR, # Translators: the label of an ietm in the application menubar _("Clear list"), # Translators: the help text of an ietm in the application menubar _("Clear the recent books list."), ) fileMenu.AppendSeparator() # Translators: the label of an ietm in the application menubar fileMenu.Append(wx.ID_EXIT, _("Exit")) # Tools menu toolsMenu.Append( BookRelatedMenuIds.goToPage, # Translators: the label of an ietm in the application menubar _("&Go To Page...\tCtrl-G"), # Translators: the help text of an ietm in the application menubar _("Go to page"), ) toolsMenu.Append( wx.ID_FIND, # Translators: the label of an ietm in the application menubar _("&Find in Book...\tCtrl-F"), # Translators: the help text of an ietm in the application menubar _("Search this book."), ) toolsMenu.Append( BookRelatedMenuIds.findNext, # Translators: the label of an ietm in the application menubar _("&Find &Next\tF3"), # Translators: the help text of an ietm in the application menubar _("Find next occurrence."), ) toolsMenu.Append( BookRelatedMenuIds.findPrev, # Translators: the label of an ietm in the application menubar _("&Find &Previous\tShift-F3"), # Translators: the help text of an ietm in the application menubar _("Find previous occurrence."), ) self.renderItem = toolsMenu.Append( BookRelatedMenuIds.viewRenderedAsImage, # Translators: the label of an ietm in the application menubar _("&Render Page...\tCtrl-R"), # Translators: the help text of an ietm in the application menubar _("View a fully rendered version of this page."), ) toolsMenu.Append( wx.ID_PREFERENCES, # Translators: the label of an ietm in the application menubar _("&Preferences...\tCtrl-Shift-P"), # Translators: the help text of an ietm in the application menubar _("Configure application"), ) # Speech menu speechMenu.Append( BookRelatedMenuIds.play, # Translators: the label of an ietm in the application menubar _("&Play\tF5"), # Translators: the help text of an ietm in the application menubar _("Start reading aloud"), ) speechMenu.Append( BookRelatedMenuIds.pauseToggle, # Translators: the label of an ietm in the application menubar _("Pa&use/Resume\tF6"), # Translators: the help text of an ietm in the application menubar _("Pause/Resume reading aloud"), ) speechMenu.Append( BookRelatedMenuIds.stop, # Translators: the label of an ietm in the application menubar _("&Stop\tF7"), # Translators: the help text of an ietm in the application menubar _("Stop reading aloud"), ) speechMenu.Append( BookRelatedMenuIds.rewind, # Translators: the label of an ietm in the application menubar _("&Rewind\tAlt-LeftArrow"), # Translators: the help text of an ietm in the application menubar _("Skip to previous paragraph"), ) speechMenu.Append( BookRelatedMenuIds.fastforward, # Translators: the label of an ietm in the application menubar _("&Fast Forward\tAlt-RightArrow"), # Translators: the help text of an ietm in the application menubar _("Skip to next paragraph"), ) speechMenu.Append( ViewerMenuIds.voiceProfiles, # Translators: the label of an ietm in the application menubar _("&Voice Profiles\tCtrl-Shift-V"), # Translators: the help text of an ietm in the application menubar _("Manage voice profiles."), ) speechMenu.Append( ViewerMenuIds.deactivateVoiceProfiles, # Translators: the label of an ietm in the application menubar _("&Deactivate Active Voice Profile"), # Translators: the help text of an ietm in the application menubar _("Deactivate the active voice profile."), ) # Annotations menu annotationsMenu.Append( BookRelatedMenuIds.addBookmark, # Translators: the label of an ietm in the application menubar _("Add &Bookmark...\tCtrl-B"), # Translators: the help text of an ietm in the application menubar _("Bookmark the current location"), ) annotationsMenu.Append( BookRelatedMenuIds.addNote, # Translators: the label of an ietm in the application menubar _("Take &Note...\tCtrl-N"), # Translators: the help text of an ietm in the application menubar _("Add a note at the current location"), ) annotationsMenu.Append( BookRelatedMenuIds.viewBookmarks, # Translators: the label of an ietm in the application menubar _("&View Bookmarks...\tCtrl-Shift-B"), # Translators: the help text of an ietm in the application menubar _("View added bookmarks"), ) annotationsMenu.Append( BookRelatedMenuIds.viewNotes, # Translators: the label of an ietm in the application menubar _("&Manage Notes...\tCtrl-Shift-N"), # Translators: the help text of an ietm in the application menubar _("View, edit, and remove notes."), ) annotationsMenu.Append( BookRelatedMenuIds.ExportNotes, # Translators: the label of an ietm in the application menubar _("Notes &Exporter") + "...", # Translators: the help text of an ietm in the application menubar _("Export notes to a file."), ) # Help menu helpMenu.Append( ViewerMenuIds.documentation, # Translators: the label of an ietm in the application menubar _("&User guide...\tF1"), # Translators: the help text of an ietm in the application menubar _("View Bookworm manuals"), ) helpMenu.Append( ViewerMenuIds.website, # Translators: the label of an ietm in the application menubar _("Bookworm &website..."), # Translators: the help text of an ietm in the application menubar _("Visit the official website of Bookworm"), ) helpMenu.Append( ViewerMenuIds.license, # Translators: the label of an ietm in the application menubar _("&License"), # Translators: the help text of an ietm in the application menubar _("View legal information about this program ."), ) helpMenu.Append( ViewerMenuIds.contributors, # Translators: the label of an ietm in the application menubar _("Con&tributors"), # Translators: the help text of an ietm in the application menubar _("View a list of notable contributors to the program."), ) helpMenu.Append( ViewerMenuIds.check_for_updates, # Translators: the label of an ietm in the application menubar _("&Check for updates"), # Translators: the help text of an ietm in the application menubar _("Update the application"), ) if app.is_frozen and not app.debug: helpMenu.Append( ViewerMenuIds.restart_with_debug, # Translators: the label of an ietm in the application menubar _("&Restart with debug-mode enabled"), # Translators: the help text of an ietm in the application menubar _("Restart the program with debug mode enabled to show errors"), ) self.Bind( wx.EVT_MENU, self.onRestartWithDebugMode, id=ViewerMenuIds.restart_with_debug, ) helpMenu.Append( ViewerMenuIds.about, # Translators: the label of an ietm in the application menubar _("&About Bookworm") + "...", # Translators: the help text of an ietm in the application menubar _("Show general information about this program"), ) # Event handling self.Bind(wx.EVT_TIMER, self.onTimerTick) # Bind menu events to event handlers # File menu event handlers self.Bind(wx.EVT_MENU, self.onOpenEBook, id=wx.ID_OPEN) self.Bind(wx.EVT_MENU, self.onExportAsPlainText, id=BookRelatedMenuIds.export) self.Bind( wx.EVT_MENU, self.onCloseCurrentFile, id=BookRelatedMenuIds.closeCurrentFile ) self.Bind(wx.EVT_MENU, self.onClearRecentFileList, id=wx.ID_CLEAR) self.Bind(wx.EVT_MENU, self.onClose, id=wx.ID_EXIT) self.Bind(wx.EVT_CLOSE, self.onClose, self) # Tools menu event handlers self.Bind(wx.EVT_MENU, self.onGoToPage, id=BookRelatedMenuIds.goToPage) self.Bind(wx.EVT_MENU, self.onFind, id=wx.ID_FIND) self.Bind(wx.EVT_MENU, self.onFindNext, id=BookRelatedMenuIds.findNext) self.Bind(wx.EVT_MENU, self.onFindPrev, id=BookRelatedMenuIds.findPrev) self.Bind( wx.EVT_MENU, self.onViewRenderedAsImage, id=BookRelatedMenuIds.viewRenderedAsImage, ) self.Bind(wx.EVT_MENU, self.onPreferences, id=wx.ID_PREFERENCES) # Speech menu event handlers self.Bind(wx.EVT_MENU, self.onPlay, id=BookRelatedMenuIds.play) self.Bind(wx.EVT_MENU, self.onPauseToggle, id=BookRelatedMenuIds.pauseToggle) self.Bind( wx.EVT_MENU, lambda e: self.reader.rewind(), id=BookRelatedMenuIds.rewind ) self.Bind( wx.EVT_MENU, lambda e: self.reader.fastforward(), id=BookRelatedMenuIds.fastforward, ) self.Bind(wx.EVT_MENU, self.onStop, id=BookRelatedMenuIds.stop) self.Bind(wx.EVT_MENU, self.onVoiceProfiles, id=ViewerMenuIds.voiceProfiles) self.Bind( wx.EVT_MENU, self.onDeactivateVoiceProfile, id=ViewerMenuIds.deactivateVoiceProfiles, ) # Annotations menu event handlers self.Bind(wx.EVT_MENU, self.onAddBookmark, id=BookRelatedMenuIds.addBookmark) self.Bind(wx.EVT_MENU, self.onAddNote, id=BookRelatedMenuIds.addNote) self.Bind( wx.EVT_MENU, self.onViewBookmarks, id=BookRelatedMenuIds.viewBookmarks ) self.Bind(wx.EVT_MENU, self.onViewNotes, id=BookRelatedMenuIds.viewNotes) self.Bind(wx.EVT_MENU, self.onNotesExporter, id=BookRelatedMenuIds.ExportNotes) # Help menu event handlers self.Bind(wx.EVT_MENU, self.onOpenDocumentation, id=ViewerMenuIds.documentation) self.Bind( wx.EVT_MENU, lambda e: webbrowser.open(app.website), id=ViewerMenuIds.website, ) self.Bind( wx.EVT_MENU, lambda e: wx.LaunchDefaultApplication(str(paths.docs_path("license.txt"))), id=ViewerMenuIds.license, ) self.Bind( wx.EVT_MENU, lambda e: wx.LaunchDefaultApplication( str(paths.docs_path("contributors.txt")) ), id=ViewerMenuIds.contributors, ) self.Bind( wx.EVT_MENU, lambda e: check_for_updates(verbose=True), id=ViewerMenuIds.check_for_updates, ) self.Bind(wx.EVT_MENU, self.onAbout, id=ViewerMenuIds.about) # and put the menu on the menubar # Translators: the label of an ietm in the application menubar self.menuBar.Append(fileMenu, _("&File")) # Translators: the label of an ietm in the application menubar self.menuBar.Append(toolsMenu, _("&Tools")) # Translators: the label of an ietm in the application menubar self.menuBar.Append(speechMenu, _("&Speech")) # Translators: the label of an ietm in the application menubar self.menuBar.Append(annotationsMenu, _("&Annotations")) # Translators: the label of an ietm in the application menubar self.menuBar.Append(helpMenu, _("&Help")) self.SetMenuBar(self.menuBar) # Set accelerators for the menu items self._set_menu_accelerators() # Disable this when no voice profile is active self.menuBar.FindItemById(wx.ID_REVERT).Enable(False) # Populate the recent files submenu self._recent_files_data = [] self.populate_recent_file_list() config_updated.connect(self._on_config_changed_for_cont)