Add miscwidgets.WrapperLayout.wrap
This makes it easier for an user of WrapperLayout to wrap a widget.
This commit is contained in:
parent
57ed5ae876
commit
029ea2e5a7
@ -475,7 +475,7 @@ class AbstractTab(QWidget):
|
|||||||
# self.search = AbstractSearch(parent=self)
|
# self.search = AbstractSearch(parent=self)
|
||||||
# self.printing = AbstractPrinting()
|
# self.printing = AbstractPrinting()
|
||||||
self.data = TabData()
|
self.data = TabData()
|
||||||
self._layout = None
|
self._layout = miscwidgets.WrapperLayout(self)
|
||||||
self._widget = None
|
self._widget = None
|
||||||
self._progress = 0
|
self._progress = 0
|
||||||
self._has_ssl_errors = False
|
self._has_ssl_errors = False
|
||||||
@ -484,8 +484,8 @@ class AbstractTab(QWidget):
|
|||||||
|
|
||||||
def _set_widget(self, widget):
|
def _set_widget(self, widget):
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
self._layout = miscwidgets.WrapperLayout(widget, self)
|
|
||||||
self._widget = widget
|
self._widget = widget
|
||||||
|
self._layout.wrap(self, widget)
|
||||||
self.history._history = widget.history()
|
self.history._history = widget.history()
|
||||||
self.scroller._init_widget(widget)
|
self.scroller._init_widget(widget)
|
||||||
self.caret._widget = widget
|
self.caret._widget = widget
|
||||||
@ -493,8 +493,6 @@ class AbstractTab(QWidget):
|
|||||||
self.search._widget = widget
|
self.search._widget = widget
|
||||||
self.printing._widget = widget
|
self.printing._widget = widget
|
||||||
widget.mouse_wheel_zoom.connect(self.zoom._on_mouse_wheel_zoom)
|
widget.mouse_wheel_zoom.connect(self.zoom._on_mouse_wheel_zoom)
|
||||||
widget.setParent(self)
|
|
||||||
self.setFocusProxy(widget)
|
|
||||||
|
|
||||||
def _set_load_status(self, val):
|
def _set_load_status(self, val):
|
||||||
"""Setter for load_status."""
|
"""Setter for load_status."""
|
||||||
|
@ -59,14 +59,12 @@ class AbstractWebInspector(QWebInspector):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._widget = None
|
self._widget = None
|
||||||
self._layout = None
|
self._layout = miscwidgets.WrapperLayout(self)
|
||||||
self._load_state_geometry()
|
self._load_state_geometry()
|
||||||
|
|
||||||
def _set_widget(self, widget):
|
def _set_widget(self, widget):
|
||||||
self._widget = widget
|
self._widget = widget
|
||||||
self._layout = miscwidgets.WrapperLayout(self._widget, self)
|
self._layout.wrap(self, widget)
|
||||||
self.setFocusProxy(self._widget)
|
|
||||||
self._widget.setParent(self)
|
|
||||||
|
|
||||||
def _load_state_geometry(self):
|
def _load_state_geometry(self):
|
||||||
"""Load the geometry from the state file."""
|
"""Load the geometry from the state file."""
|
||||||
|
@ -235,9 +235,9 @@ class WrapperLayout(QLayout):
|
|||||||
easily be accidentally accessed.
|
easily be accidentally accessed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, widget, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._widget = widget
|
self._widget = None
|
||||||
|
|
||||||
def addItem(self, _widget):
|
def addItem(self, _widget):
|
||||||
raise AssertionError("Should never be called!")
|
raise AssertionError("Should never be called!")
|
||||||
@ -254,3 +254,9 @@ class WrapperLayout(QLayout):
|
|||||||
|
|
||||||
def setGeometry(self, rect):
|
def setGeometry(self, rect):
|
||||||
self._widget.setGeometry(rect)
|
self._widget.setGeometry(rect)
|
||||||
|
|
||||||
|
def wrap(self, container, widget):
|
||||||
|
"""Wrap the given widget in the given container."""
|
||||||
|
self._widget = widget
|
||||||
|
container.setFocusProxy(widget)
|
||||||
|
widget.setParent(container)
|
||||||
|
@ -27,7 +27,7 @@ from unittest import mock
|
|||||||
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
|
from PyQt5.QtCore import pyqtSignal, QPoint, QProcess, QObject
|
||||||
from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
|
from PyQt5.QtNetwork import (QNetworkRequest, QAbstractNetworkCache,
|
||||||
QNetworkCacheMetaData)
|
QNetworkCacheMetaData)
|
||||||
from PyQt5.QtWidgets import QCommonStyle, QLineEdit
|
from PyQt5.QtWidgets import QCommonStyle, QLineEdit, QWidget
|
||||||
|
|
||||||
from qutebrowser.browser import browsertab
|
from qutebrowser.browser import browsertab
|
||||||
from qutebrowser.browser.webkit import history
|
from qutebrowser.browser.webkit import history
|
||||||
@ -253,6 +253,8 @@ class FakeWebTab(browsertab.AbstractTab):
|
|||||||
self._url = url
|
self._url = url
|
||||||
self._progress = progress
|
self._progress = progress
|
||||||
self.scroller = FakeWebTabScroller(self, scroll_pos_perc)
|
self.scroller = FakeWebTabScroller(self, scroll_pos_perc)
|
||||||
|
wrapped = QWidget()
|
||||||
|
self._layout.wrap(self, wrapped)
|
||||||
|
|
||||||
def url(self):
|
def url(self):
|
||||||
return self._url
|
return self._url
|
||||||
|
@ -96,7 +96,6 @@ def tab(request, default_config, qtbot, tab_registry, cookiejar_and_cache):
|
|||||||
def test_tab(qtbot, view, config_stub, tab_registry):
|
def test_tab(qtbot, view, config_stub, tab_registry):
|
||||||
tab_w = browsertab.AbstractTab(win_id=0)
|
tab_w = browsertab.AbstractTab(win_id=0)
|
||||||
qtbot.add_widget(tab_w)
|
qtbot.add_widget(tab_w)
|
||||||
tab_w.show()
|
|
||||||
|
|
||||||
assert tab_w.win_id == 0
|
assert tab_w.win_id == 0
|
||||||
assert tab_w._widget is None
|
assert tab_w._widget is None
|
||||||
@ -118,6 +117,9 @@ def test_tab(qtbot, view, config_stub, tab_registry):
|
|||||||
assert tab_w.history._history is view.history()
|
assert tab_w.history._history is view.history()
|
||||||
assert view.parent() is tab_w
|
assert view.parent() is tab_w
|
||||||
|
|
||||||
|
tab_w.show()
|
||||||
|
qtbot.waitForWindowShown(tab_w)
|
||||||
|
|
||||||
|
|
||||||
class TestJs:
|
class TestJs:
|
||||||
|
|
||||||
|
@ -89,8 +89,14 @@ class TestWrapperLayout:
|
|||||||
parent = QWidget()
|
parent = QWidget()
|
||||||
qtbot.add_widget(wrapped)
|
qtbot.add_widget(wrapped)
|
||||||
qtbot.add_widget(parent)
|
qtbot.add_widget(parent)
|
||||||
miscwidgets.WrapperLayout(wrapped, parent)
|
layout = miscwidgets.WrapperLayout(parent)
|
||||||
|
layout.wrap(parent, wrapped)
|
||||||
|
parent.wrapped = wrapped
|
||||||
return parent
|
return parent
|
||||||
|
|
||||||
def test_size_hint(self, container):
|
def test_size_hint(self, container):
|
||||||
assert container.sizeHint() == QSize(23, 42)
|
assert container.sizeHint() == QSize(23, 42)
|
||||||
|
|
||||||
|
def test_wrapped(self, container):
|
||||||
|
assert container.wrapped.parent() is container
|
||||||
|
assert container.focusProxy() is container.wrapped
|
||||||
|
Loading…
Reference in New Issue
Block a user