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.payload = payload
|
||||||
self.html_log = html_log
|
self.html_log = html_log
|
||||||
self.log_viewer_title = log_viewer_title
|
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 = self.bb.addButton(_('View log'), self.bb.ActionRole)
|
||||||
self.vlb.setIcon(QIcon(I('debug.png')))
|
self.vlb.setIcon(QIcon(I('debug.png')))
|
||||||
@ -195,18 +195,17 @@ class ProceedNotification(MessageBox): # {{{
|
|||||||
parent=self)
|
parent=self)
|
||||||
|
|
||||||
def do_proceed(self, result):
|
def do_proceed(self, result):
|
||||||
try:
|
from calibre.gui2.ui import get_gui
|
||||||
if result == self.Accepted:
|
func = (self.callback if result == self.Accepted else
|
||||||
self.callback(self.payload)
|
self.cancel_callback)
|
||||||
elif self.cancel_callback is not None:
|
gui = get_gui()
|
||||||
self.cancel_callback(self.payload)
|
gui.proceed_requested.emit(func, self.payload)
|
||||||
finally:
|
# Ensure this notification is garbage collected
|
||||||
# Ensure this notification is garbage collected
|
self.callback = self.cancel_callback = self.payload = None
|
||||||
self.callback = self.cancel_callback = None
|
self.setParent(None)
|
||||||
self.setParent(None)
|
self.finished.disconnect()
|
||||||
self.finished.disconnect()
|
self.vlb.clicked.disconnect()
|
||||||
self.vlb.clicked.disconnect()
|
_proceed_memory.remove(self)
|
||||||
_proceed_memory.remove(self)
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class ErrorNotification(MessageBox): # {{{
|
class ErrorNotification(MessageBox): # {{{
|
||||||
|
@ -102,10 +102,13 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
):
|
):
|
||||||
'The main GUI'
|
'The main GUI'
|
||||||
|
|
||||||
|
proceed_requested = pyqtSignal(object, object)
|
||||||
|
|
||||||
def __init__(self, opts, parent=None, gui_debug=None):
|
def __init__(self, opts, parent=None, gui_debug=None):
|
||||||
global _gui
|
global _gui
|
||||||
MainWindow.__init__(self, opts, parent=parent, disable_automatic_gc=True)
|
MainWindow.__init__(self, opts, parent=parent, disable_automatic_gc=True)
|
||||||
|
self.proceed_requested.connect(self.do_proceed,
|
||||||
|
type=Qt.QueuedConnection)
|
||||||
self.keyboard = Manager(self)
|
self.keyboard = Manager(self)
|
||||||
_gui = self
|
_gui = self
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
@ -402,6 +405,10 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def do_proceed(self, func, payload):
|
||||||
|
if callable(func):
|
||||||
|
func(payload)
|
||||||
|
|
||||||
def no_op(self, *args):
|
def no_op(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user