mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
A less crash prone (I hope) implementation of ProceedNotification
This commit is contained in:
parent
62f0688ae5
commit
b0d13adba7
@ -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,18 +195,17 @@ 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:
|
||||
# Ensure this notification is garbage collected
|
||||
self.callback = self.cancel_callback = None
|
||||
self.setParent(None)
|
||||
self.finished.disconnect()
|
||||
self.vlb.clicked.disconnect()
|
||||
_proceed_memory.remove(self)
|
||||
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 = self.payload = None
|
||||
self.setParent(None)
|
||||
self.finished.disconnect()
|
||||
self.vlb.clicked.disconnect()
|
||||
_proceed_memory.remove(self)
|
||||
# }}}
|
||||
|
||||
class ErrorNotification(MessageBox): # {{{
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user