Add WrapperLayout/AbstractTab
This commit is contained in:
parent
29ee605c79
commit
4305966f7b
58
qutebrowser/browser/tab.py
Normal file
58
qutebrowser/browser/tab.py
Normal file
@ -0,0 +1,58 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""Base class for a wrapper over QWebView/QWebEngineView."""
|
||||
|
||||
from PyQt5.QtWidgets import QWidget, QLayout
|
||||
|
||||
|
||||
class WrapperLayout(QLayout):
|
||||
|
||||
def __init__(self, widget, parent=None):
|
||||
super().__init__(parent)
|
||||
self._widget = widget
|
||||
|
||||
def addItem(self, w):
|
||||
raise AssertionError("Should never be called!")
|
||||
|
||||
def sizeHint(self):
|
||||
return self._widget.sizeHint()
|
||||
|
||||
def itemAt(self, i):
|
||||
raise AssertionError("Should never be called!")
|
||||
|
||||
def takeAt(self, i):
|
||||
raise AssertionError("Should never be called!")
|
||||
|
||||
def setGeometry(self, r):
|
||||
self._widget.setGeometry(r)
|
||||
|
||||
|
||||
class AbstractTab(QWidget):
|
||||
|
||||
"""A wrapper over the given widget to hide its API and expose another one.
|
||||
|
||||
We use this to unify QWebView QWebEngineView.
|
||||
"""
|
||||
|
||||
def __init__(self, widget, parent=None):
|
||||
super().__init__(parent)
|
||||
self._layout = WrapperLayout(widget, self)
|
||||
self._widget = widget
|
||||
widget.setParent(self)
|
@ -70,6 +70,8 @@ PERFECT_FILES = [
|
||||
|
||||
('tests/unit/browser/test_signalfilter.py',
|
||||
'qutebrowser/browser/signalfilter.py'),
|
||||
('tests/unit/browser/test_tab.py',
|
||||
'qutebrowser/browser/tab.py'),
|
||||
|
||||
('tests/unit/keyinput/test_basekeyparser.py',
|
||||
'qutebrowser/keyinput/basekeyparser.py'),
|
||||
|
30
tests/unit/browser/test_tab.py
Normal file
30
tests/unit/browser/test_tab.py
Normal file
@ -0,0 +1,30 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from qutebrowser.browser import tab
|
||||
|
||||
from PyQt5.QtWidgets import QWidget
|
||||
|
||||
|
||||
def test_tab(qtbot):
|
||||
w = QWidget()
|
||||
qtbot.add_widget(w)
|
||||
tab_w = tab.AbstractTab(w)
|
||||
tab_w.show()
|
||||
assert tab_w._widget is w
|
Loading…
Reference in New Issue
Block a user