From c2f76f29326700bfb251bb00203794096743a9ce Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 29 Oct 2020 23:18:01 -0400 Subject: [PATCH] viewer: error out if print book is used when no book is open This is slightly nicer than erroring out, but with a traceback due to trying to access a nonexistent pathtoebook attribute. --- src/calibre/gui2/viewer/ui.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calibre/gui2/viewer/ui.py b/src/calibre/gui2/viewer/ui.py index c74b55ac80..d1c8e8f701 100644 --- a/src/calibre/gui2/viewer/ui.py +++ b/src/calibre/gui2/viewer/ui.py @@ -428,6 +428,10 @@ class EbookViewer(MainWindow): error_dialog(self, title, msg, det_msg=details or None, show=True) def print_book(self): + if not hasattr(set_book_path, 'pathtoebook'): + error_dialog(self, _('No ebook selected'), _( + "Cannot print a book if no book is open yet."), show=True) + return from .printing import print_book print_book(set_book_path.pathtoebook, book_title=self.current_book_data['metadata']['title'], parent=self)