E-book viewer: Disable toolbar buttons when no book is open

This commit is contained in:
Kovid Goyal 2021-05-13 07:12:13 +05:30
parent 505c92df47
commit 4b5f899366
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 0 deletions

View File

@ -118,6 +118,12 @@ class ActionsToolBar(ToolBar):
self.setObjectName('actions_toolbar') self.setObjectName('actions_toolbar')
self.customContextMenuRequested.connect(self.show_context_menu) self.customContextMenuRequested.connect(self.show_context_menu)
def update_action_state(self, book_open):
for ac in self.shortcut_actions.values():
ac.setEnabled(book_open)
self.search_action.setEnabled(book_open)
self.color_scheme_action.setEnabled(book_open)
def show_context_menu(self, pos): def show_context_menu(self, pos):
m = QMenu(self) m = QMenu(self)
a = m.addAction(_('Customize this toolbar')) a = m.addAction(_('Customize this toolbar'))

View File

@ -192,6 +192,7 @@ class EbookViewer(MainWindow):
self.web_view.highlights_changed.connect(self.highlights_changed) self.web_view.highlights_changed.connect(self.highlights_changed)
self.web_view.edit_book.connect(self.edit_book) self.web_view.edit_book.connect(self.edit_book)
self.actions_toolbar.initialize(self.web_view, self.search_dock.toggleViewAction()) self.actions_toolbar.initialize(self.web_view, self.search_dock.toggleViewAction())
at.update_action_state(False)
self.setCentralWidget(self.web_view) self.setCentralWidget(self.web_view)
self.loading_overlay = LoadingOverlay(self) self.loading_overlay = LoadingOverlay(self)
self.restore_state() self.restore_state()
@ -411,11 +412,13 @@ class EbookViewer(MainWindow):
def show_loading_message(self, msg): def show_loading_message(self, msg):
if msg: if msg:
self.loading_overlay(msg) self.loading_overlay(msg)
self.actions_toolbar.update_action_state(False)
else: else:
if not hasattr(self, 'initial_loading_performace_reported'): if not hasattr(self, 'initial_loading_performace_reported'):
performance_monitor('loading finished') performance_monitor('loading finished')
self.initial_loading_performace_reported = True self.initial_loading_performace_reported = True
self.loading_overlay.hide() self.loading_overlay.hide()
self.actions_toolbar.update_action_state(True)
def show_error(self, title, msg, details): def show_error(self, title, msg, details):
self.loading_overlay.hide() self.loading_overlay.hide()
@ -461,6 +464,7 @@ class EbookViewer(MainWindow):
def load_ebook(self, pathtoebook, open_at=None, reload_book=False): def load_ebook(self, pathtoebook, open_at=None, reload_book=False):
performance_monitor('Load of book started', reset=True) performance_monitor('Load of book started', reset=True)
self.actions_toolbar.update_action_state(False)
self.web_view.show_home_page_on_ready = False self.web_view.show_home_page_on_ready = False
if open_at: if open_at:
self.pending_open_at = open_at self.pending_open_at = open_at
@ -501,6 +505,7 @@ class EbookViewer(MainWindow):
open_at, self.pending_open_at = self.pending_open_at, None open_at, self.pending_open_at = self.pending_open_at, None
self.web_view.clear_caches() self.web_view.clear_caches()
if not ok: if not ok:
self.actions_toolbar.update_action_state(False)
self.setWindowTitle(self.base_window_title) self.setWindowTitle(self.base_window_title)
tb = as_unicode(data['tb'].strip(), errors='replace') tb = as_unicode(data['tb'].strip(), errors='replace')
tb = re.split(r'^calibre\.gui2\.viewer\.convert_book\.ConversionFailure:\s*', tb, maxsplit=1, flags=re.M)[-1] tb = re.split(r'^calibre\.gui2\.viewer\.convert_book\.ConversionFailure:\s*', tb, maxsplit=1, flags=re.M)[-1]