diff --git a/src/calibre/gui2/actions/show_book_details.py b/src/calibre/gui2/actions/show_book_details.py index 1d707cbfa6..164feb7958 100644 --- a/src/calibre/gui2/actions/show_book_details.py +++ b/src/calibre/gui2/actions/show_book_details.py @@ -22,7 +22,7 @@ class ShowBookDetailsAction(InterfaceAction): def genesis(self): self.qaction.triggered.connect(self.show_book_info) - self.memory = [] + self.dialogs = [None, ] def show_book_info(self, *args, **kwargs): library_path = kwargs.get('library_path', None) @@ -36,33 +36,46 @@ class ShowBookDetailsAction(InterfaceAction): 'on the device.')).exec() return if library_path or index.isValid(): + # Window #0 is slaved to changes in the book list. As such + # it must not be used for details from other libraries. + for dn,v in enumerate(self.dialogs): + if dn == 0 and library_path: + continue + if v is None: + break + else: + self.dialogs.append(None) + dn += 1 + try: d = BookInfo(self.gui, self.gui.library_view, index, - self.gui.book_details.handle_click, + self.gui.book_details.handle_click, dialog_number=dn, library_id=library_id, library_path=library_path, book_id=book_id, query=query) except ValueError as e: error_dialog(self.gui, _('Book not found'), str(e)).exec() return d.open_cover_with.connect(self.gui.bd_open_cover_with, type=Qt.ConnectionType.QueuedConnection) - self.memory.append(d) + self.dialogs[dn] = d d.closed.connect(self.closed, type=Qt.ConnectionType.QueuedConnection) d.show() def shutting_down(self): - for d in self.memory: - d.close() - self.memory = [] + for d in self.dialogs: + if d: + d.done(0) def library_about_to_change(self, *args): - for d in self.memory: - if d.for_external_library: - d.close() + for i,d in enumerate(self.dialogs): + if i == 0: + continue + if d: + d.done(0) def closed(self, d): try: d.closed.disconnect(self.closed) - self.memory.remove(d) + self.dialogs[d.dialog_number] = None except ValueError: pass else: diff --git a/src/calibre/gui2/dialogs/book_info.py b/src/calibre/gui2/dialogs/book_info.py index 1ef95c593f..c56ec17900 100644 --- a/src/calibre/gui2/dialogs/book_info.py +++ b/src/calibre/gui2/dialogs/book_info.py @@ -135,10 +135,10 @@ class BookInfo(QDialog): closed = pyqtSignal(object) open_cover_with = pyqtSignal(object, object) - def __init__(self, parent, view, row, link_delegate, + def __init__(self, parent, view, row, link_delegate, dialog_number=None, library_id=None, library_path=None, book_id=None, query=None): QDialog.__init__(self, None, flags=Qt.WindowType.Window) - self.for_external_library = bool(library_path) + self.dialog_number = dialog_number self.library_id = library_id self.marked = None self.gui = parent @@ -179,7 +179,7 @@ class BookInfo(QDialog): hl.setContentsMargins(0, 0, 0, 0) l2.addLayout(hl, l2.rowCount(), 0, 1, -1) hl.addWidget(self.fit_cover), hl.addStretch() - if not self.for_external_library: + if self.dialog_number == 0: self.previous_button = QPushButton(QIcon.ic('previous.png'), _('&Previous'), self) self.previous_button.clicked.connect(self.previous) l2.addWidget(self.previous_button, l2.rowCount(), 0) @@ -218,7 +218,7 @@ class BookInfo(QDialog): self.refresh(row, mi) else: self.view = view - if not self.for_external_library: + if dialog_number == 0: self.slave_connected = True self.view.model().new_bookdisplay_data.connect(self.slave) self.refresh(row) @@ -245,9 +245,9 @@ class BookInfo(QDialog): pass def geometry_string(self, txt): - if self.for_external_library: - txt += '_' + 'for_external_library' - return txt + if self.dialog_number is None or self.dialog_number == 0: + return txt + return txt + '_' + str(self.dialog_number) def sizeHint(self): try: @@ -378,7 +378,7 @@ class BookInfo(QDialog): # Indicates books was deleted from library, or row numbers have # changed return - if not self.for_external_library: + if self.dialog_number == 0: self.previous_button.setEnabled(False if row == 0 else True) self.next_button.setEnabled(False if row == self.view.model().rowCount(QModelIndex())-1 else True) self.setWindowTitle(mi.title + ' ' + _('(the current book)'))