widgets: guard against RuntimeError during application shutdown
If we create a commit and then immediately exit the program then we can
trigger a rare bug where events are triggered after the C++ Qt widgets
have been deleted.
This could also involve the widgets losing focus at just the right time.
What was observed is that the focusOut event was getting detected in
the event filter and the focus_out() method fails to query the widget.
Traceback (most recent call last):
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 532, in eventFilter
self.focus_out()
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 545, in focus_out
if not get(widget):
File "/usr/share/git-cola/lib/cola/qtutils.py", line 83, in get
value = widget.value()
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 312, in value
return self.ext.value()
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 110, in value
return self._get_value(self.widget)
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 400, in get_value_hinted
text = get_stripped(widget)
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 21, in get_stripped
return widget.get().strip()
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 308, in get
return self.ext.get()
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 106, in get
return self.widget.toPlainText()
RuntimeError: wrapped C/C++ object of type CommitMessageTextEdit has been deleted
Traceback (most recent call last):
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 524, in <lambda>
QtCore.QTimer.singleShot(0, lambda: self._widget.setStyleSheet(style))
RuntimeError: wrapped C/C++ object of type CommitMessageTextEdit has been deleted
Traceback (most recent call last):
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 524, in <lambda>
QtCore.QTimer.singleShot(0, lambda: self._widget.setStyleSheet(style))
RuntimeError: wrapped C/C++ object of type CommitSummaryLineEdit has been deleted
Traceback (most recent call last):
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 524, in <lambda>
QtCore.QTimer.singleShot(0, lambda: self._widget.setStyleSheet(style))
RuntimeError: wrapped C/C++ object of type CommitMessageTextEdit has been deleted
Traceback (most recent call last):
File "/usr/share/git-cola/lib/cola/widgets/text.py", line 524, in <lambda>
QtCore.QTimer.singleShot(0, lambda: self._widget.setStyleSheet(style))
RuntimeError: wrapped C/C++ object of type CommitMessageTextEdit has been deleted
The above traceback was from an older version of git-cola (3.9) but
this code path is still present.
Catch the RuntimeErrror and exit early in the focus_out() method that
responds to FocusOut events via the event filter.
Signed-off-by: David Aguilar <davvid@gmail.com>