Keep references to BookInfo to prevent object lifetime issues

This commit is contained in:
Kovid Goyal 2013-08-09 15:25:11 +05:30
parent 89c712128e
commit 4ce6bb4378
2 changed files with 22 additions and 3 deletions

View File

@ -5,6 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from PyQt4.Qt import Qt
from calibre.gui2.actions import InterfaceAction from calibre.gui2.actions import InterfaceAction
from calibre.gui2.dialogs.book_info import BookInfo from calibre.gui2.dialogs.book_info import BookInfo
@ -20,6 +21,7 @@ class ShowBookDetailsAction(InterfaceAction):
def genesis(self): def genesis(self):
self.qaction.triggered.connect(self.show_book_info) self.qaction.triggered.connect(self.show_book_info)
self.memory = []
def show_book_info(self, *args): def show_book_info(self, *args):
if self.gui.current_view() is not self.gui.library_view: if self.gui.current_view() is not self.gui.library_view:
@ -29,6 +31,16 @@ class ShowBookDetailsAction(InterfaceAction):
return return
index = self.gui.library_view.currentIndex() index = self.gui.library_view.currentIndex()
if index.isValid(): if index.isValid():
BookInfo(self.gui, self.gui.library_view, index, d = BookInfo(self.gui, self.gui.library_view, index,
self.gui.book_details.handle_click).show() self.gui.book_details.handle_click)
self.memory.append(d)
d.closed.connect(self.closed, type=Qt.QueuedConnection)
d.show()
def closed(self, d):
try:
d.closed.disconnect(self.closed)
self.memory.remove(d)
except ValueError:
pass

View File

@ -4,7 +4,7 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from PyQt4.Qt import (QCoreApplication, QModelIndex, QTimer, Qt, from PyQt4.Qt import (QCoreApplication, QModelIndex, QTimer, Qt, pyqtSignal,
QDialog, QPixmap, QIcon, QSize, QPalette, QShortcut, QKeySequence) QDialog, QPixmap, QIcon, QSize, QPalette, QShortcut, QKeySequence)
from calibre.gui2.dialogs.book_info_ui import Ui_BookInfo from calibre.gui2.dialogs.book_info_ui import Ui_BookInfo
@ -14,6 +14,8 @@ from calibre.gui2.book_details import render_html
class BookInfo(QDialog, Ui_BookInfo): class BookInfo(QDialog, Ui_BookInfo):
closed = pyqtSignal(object)
def __init__(self, parent, view, row, link_delegate): def __init__(self, parent, view, row, link_delegate):
QDialog.__init__(self, parent) QDialog.__init__(self, parent)
Ui_BookInfo.__init__(self) Ui_BookInfo.__init__(self)
@ -59,6 +61,11 @@ class BookInfo(QDialog, Ui_BookInfo):
link = unicode(qurl.toString()) link = unicode(qurl.toString())
self.link_delegate(link) self.link_delegate(link)
def done(self, r):
ret = QDialog.done(self, r)
self.closed.emit(self)
return ret
def cover_changed(self, data): def cover_changed(self, data):
if self.current_row is not None: if self.current_row is not None:
id_ = self.view.model().id(self.current_row) id_ = self.view.model().id(self.current_row)