Add tab.create() helper function
This commit is contained in:
parent
334f6cda4f
commit
55784f9783
@ -25,6 +25,7 @@ from PyQt5.QtCore import pyqtSignal, pyqtSlot, QUrl, QObject, QPoint
|
|||||||
from PyQt5.QtGui import QIcon
|
from PyQt5.QtGui import QIcon
|
||||||
from PyQt5.QtWidgets import QWidget, QLayout
|
from PyQt5.QtWidgets import QWidget, QLayout
|
||||||
|
|
||||||
|
from qutebrowser.keyinput import modeman
|
||||||
from qutebrowser.config import config
|
from qutebrowser.config import config
|
||||||
from qutebrowser.utils import utils, objreg, usertypes, message
|
from qutebrowser.utils import utils, objreg, usertypes, message
|
||||||
|
|
||||||
@ -35,6 +36,25 @@ tab_id_gen = itertools.count(0)
|
|||||||
Backend = usertypes.enum('Backend', ['QtWebKit', 'QtWebEngine'])
|
Backend = usertypes.enum('Backend', ['QtWebKit', 'QtWebEngine'])
|
||||||
|
|
||||||
|
|
||||||
|
def create(win_id, parent=None):
|
||||||
|
"""Get a QtWebKit/QtWebEngine tab object.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
win_id: The window ID where the tab will be shown.
|
||||||
|
parent: The Qt parent to set.
|
||||||
|
"""
|
||||||
|
# Importing modules here so we don't depend on QtWebEngine without the
|
||||||
|
# argument and to avoid circular imports.
|
||||||
|
mode_manager = modeman.instance(win_id)
|
||||||
|
if objreg.get('args').backend == 'webengine':
|
||||||
|
from qutebrowser.browser.webengine import webenginetab
|
||||||
|
tab_class = webenginetab.WebEngineViewTab
|
||||||
|
else:
|
||||||
|
from qutebrowser.browser.webkit import webkittab
|
||||||
|
tab_class = webkittab.WebViewTab
|
||||||
|
return tab_class(win_id=win_id, mode_manager=mode_manager, parent=parent)
|
||||||
|
|
||||||
|
|
||||||
class WebTabError(Exception):
|
class WebTabError(Exception):
|
||||||
|
|
||||||
"""Base class for various errors."""
|
"""Base class for various errors."""
|
||||||
|
@ -381,20 +381,12 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
window=window.win_id)
|
window=window.win_id)
|
||||||
return tabbed_browser.tabopen(url, background, explicit)
|
return tabbed_browser.tabopen(url, background, explicit)
|
||||||
|
|
||||||
if objreg.get('args').backend == 'webengine':
|
tab = tabmod.create(win_id=self._win_id, parent=self)
|
||||||
# Importing this here so we don't depend on QtWebEngine without the
|
|
||||||
# argument.
|
|
||||||
from qutebrowser.browser.webengine import webenginetab
|
|
||||||
tab_class = webenginetab.WebEngineViewTab
|
|
||||||
else:
|
|
||||||
tab_class = webkittab.WebViewTab
|
|
||||||
|
|
||||||
tab = tab_class(self._win_id, modeman.instance(self._win_id),
|
|
||||||
parent=self)
|
|
||||||
|
|
||||||
self._connect_tab_signals(tab)
|
self._connect_tab_signals(tab)
|
||||||
|
|
||||||
idx = self._get_new_tab_idx(explicit)
|
idx = self._get_new_tab_idx(explicit)
|
||||||
self.insertTab(idx, tab, "")
|
self.insertTab(idx, tab, "")
|
||||||
|
|
||||||
if url is not None:
|
if url is not None:
|
||||||
tab.openurl(url)
|
tab.openurl(url)
|
||||||
if background is None:
|
if background is None:
|
||||||
|
Loading…
Reference in New Issue
Block a user