Fix handling of signals with deleted tabs.
This commit is contained in:
parent
c8c095d499
commit
801f6b2667
@ -38,6 +38,11 @@ from qutebrowser.utils import (log, message, usertypes, utils, qtutils, objreg,
|
|||||||
UndoEntry = collections.namedtuple('UndoEntry', ['url', 'history'])
|
UndoEntry = collections.namedtuple('UndoEntry', ['url', 'history'])
|
||||||
|
|
||||||
|
|
||||||
|
class TabDeletedError(Exception):
|
||||||
|
|
||||||
|
"""Exception raised when _tab_index is called for a deleted tab."""
|
||||||
|
|
||||||
|
|
||||||
class TabbedBrowser(tabwidget.TabWidget):
|
class TabbedBrowser(tabwidget.TabWidget):
|
||||||
|
|
||||||
"""A TabWidget with QWebViews inside.
|
"""A TabWidget with QWebViews inside.
|
||||||
@ -119,6 +124,21 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self, count=self.count())
|
return utils.get_repr(self, count=self.count())
|
||||||
|
|
||||||
|
def _tab_index(self, tab):
|
||||||
|
"""Get the index of a given tab.
|
||||||
|
|
||||||
|
Raises TabDeletedError if the tab doesn't exist anymore.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
idx = self.indexOf(tab)
|
||||||
|
except RuntimeError as e:
|
||||||
|
log.webview.debug("Got invalid tab {} ({})!".format(tab, e))
|
||||||
|
raise TabDeletedError(e)
|
||||||
|
if idx == -1:
|
||||||
|
log.webview.debug("Got invalid tab {} (index is -1)!".format(tab))
|
||||||
|
raise TabDeletedError("index is -1!")
|
||||||
|
return idx
|
||||||
|
|
||||||
def widgets(self):
|
def widgets(self):
|
||||||
"""Get a list of open tab widgets.
|
"""Get a list of open tab widgets.
|
||||||
|
|
||||||
@ -428,14 +448,10 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
tab: The tab where the signal belongs to.
|
tab: The tab where the signal belongs to.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
idx = self.indexOf(tab)
|
idx = self._tab_index(tab)
|
||||||
except RuntimeError:
|
except TabDeletedError:
|
||||||
# We can get signals for tabs we already deleted...
|
# We can get signals for tabs we already deleted...
|
||||||
return
|
return
|
||||||
if idx == -1:
|
|
||||||
# We can get signals for tabs we already deleted...
|
|
||||||
log.webview.debug("Got invalid tab {}!".format(tab))
|
|
||||||
return
|
|
||||||
self.update_tab_title(idx)
|
self.update_tab_title(idx)
|
||||||
if tab.keep_icon:
|
if tab.keep_icon:
|
||||||
tab.keep_icon = False
|
tab.keep_icon = False
|
||||||
@ -466,16 +482,12 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
log.webview.debug("Ignoring title change to '{}'.".format(text))
|
log.webview.debug("Ignoring title change to '{}'.".format(text))
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
idx = self.indexOf(tab)
|
idx = self._tab_index(tab)
|
||||||
except RuntimeError:
|
except TabDeletedError:
|
||||||
# We can get signals for tabs we already deleted...
|
# We can get signals for tabs we already deleted...
|
||||||
return
|
return
|
||||||
log.webview.debug("Changing title for idx {} to '{}'".format(
|
log.webview.debug("Changing title for idx {} to '{}'".format(
|
||||||
idx, text))
|
idx, text))
|
||||||
if idx == -1:
|
|
||||||
# We can get signals for tabs we already deleted...
|
|
||||||
log.webview.debug("Got invalid tab {}!".format(tab))
|
|
||||||
return
|
|
||||||
self.set_page_title(idx, text)
|
self.set_page_title(idx, text)
|
||||||
if idx == self.currentIndex():
|
if idx == self.currentIndex():
|
||||||
self.update_window_title()
|
self.update_window_title()
|
||||||
@ -489,14 +501,10 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
url: The new URL.
|
url: The new URL.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
idx = self.indexOf(tab)
|
idx = self._tab_index(tab)
|
||||||
except RuntimeError:
|
except TabDeletedError:
|
||||||
# We can get signals for tabs we already deleted...
|
# We can get signals for tabs we already deleted...
|
||||||
return
|
return
|
||||||
if idx == -1:
|
|
||||||
# We can get signals for tabs we already deleted...
|
|
||||||
log.webview.debug("Got invalid tab {}!".format(tab))
|
|
||||||
return
|
|
||||||
if not self.page_title(idx):
|
if not self.page_title(idx):
|
||||||
self.set_page_title(idx, url)
|
self.set_page_title(idx, url)
|
||||||
|
|
||||||
@ -512,14 +520,10 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
if not config.get('tabs', 'show-favicons'):
|
if not config.get('tabs', 'show-favicons'):
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
idx = self.indexOf(tab)
|
idx = self._tab_index(tab)
|
||||||
except RuntimeError:
|
except TabDeletedError:
|
||||||
# We can get signals for tabs we already deleted...
|
# We can get signals for tabs we already deleted...
|
||||||
return
|
return
|
||||||
if idx == -1:
|
|
||||||
# We can get *_changed signals for tabs we already deleted...
|
|
||||||
log.webview.debug("Got invalid tab {}!".format(tab))
|
|
||||||
return
|
|
||||||
self.setTabIcon(idx, tab.icon())
|
self.setTabIcon(idx, tab.icon())
|
||||||
|
|
||||||
@pyqtSlot(usertypes.KeyMode)
|
@pyqtSlot(usertypes.KeyMode)
|
||||||
@ -562,8 +566,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
def on_load_progress(self, tab, perc):
|
def on_load_progress(self, tab, perc):
|
||||||
"""Adjust tab indicator on load progress."""
|
"""Adjust tab indicator on load progress."""
|
||||||
try:
|
try:
|
||||||
idx = self.indexOf(tab)
|
idx = self._tab_index(tab)
|
||||||
except RuntimeError:
|
except TabDeletedError:
|
||||||
# We can get signals for tabs we already deleted...
|
# We can get signals for tabs we already deleted...
|
||||||
return
|
return
|
||||||
start = config.get('colors', 'tabs.indicator.start')
|
start = config.get('colors', 'tabs.indicator.start')
|
||||||
@ -583,8 +587,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
See https://github.com/The-Compiler/qutebrowser/issues/84
|
See https://github.com/The-Compiler/qutebrowser/issues/84
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
idx = self.indexOf(tab)
|
idx = self._tab_index(tab)
|
||||||
except RuntimeError:
|
except TabDeletedError:
|
||||||
# We can get signals for tabs we already deleted...
|
# We can get signals for tabs we already deleted...
|
||||||
return
|
return
|
||||||
if tab.page().error_occured:
|
if tab.page().error_occured:
|
||||||
|
Loading…
Reference in New Issue
Block a user