A less crash prone (I hope) implementation of ProceedNotification

This commit is contained in:
Kovid Goyal 2012-02-08 14:01:29 +05:30
parent 62f0688ae5
commit b0d13adba7
2 changed files with 19 additions and 13 deletions

View File

@ -180,7 +180,7 @@ class ProceedNotification(MessageBox): # {{{
self.payload = payload
self.html_log = html_log
self.log_viewer_title = log_viewer_title
self.finished.connect(self.do_proceed, type=Qt.QueuedConnection)
self.finished.connect(self.do_proceed)
self.vlb = self.bb.addButton(_('View log'), self.bb.ActionRole)
self.vlb.setIcon(QIcon(I('debug.png')))
@ -195,14 +195,13 @@ class ProceedNotification(MessageBox): # {{{
parent=self)
def do_proceed(self, result):
try:
if result == self.Accepted:
self.callback(self.payload)
elif self.cancel_callback is not None:
self.cancel_callback(self.payload)
finally:
from calibre.gui2.ui import get_gui
func = (self.callback if result == self.Accepted else
self.cancel_callback)
gui = get_gui()
gui.proceed_requested.emit(func, self.payload)
# Ensure this notification is garbage collected
self.callback = self.cancel_callback = None
self.callback = self.cancel_callback = self.payload = None
self.setParent(None)
self.finished.disconnect()
self.vlb.clicked.disconnect()

View File

@ -102,10 +102,13 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
):
'The main GUI'
proceed_requested = pyqtSignal(object, object)
def __init__(self, opts, parent=None, gui_debug=None):
global _gui
MainWindow.__init__(self, opts, parent=parent, disable_automatic_gc=True)
self.proceed_requested.connect(self.do_proceed,
type=Qt.QueuedConnection)
self.keyboard = Manager(self)
_gui = self
self.opts = opts
@ -402,6 +405,10 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
except:
pass
def do_proceed(self, func, payload):
if callable(func):
func(payload)
def no_op(self, *args):
pass