Add AbstractTab.data
This commit is contained in:
parent
70b7314b76
commit
78f425c98b
@ -357,7 +357,7 @@ class CommandDispatcher:
|
|||||||
new_tabbed_browser.setTabIcon(idx, curtab.icon())
|
new_tabbed_browser.setTabIcon(idx, curtab.icon())
|
||||||
if config.get('tabs', 'tabs-are-windows'):
|
if config.get('tabs', 'tabs-are-windows'):
|
||||||
new_tabbed_browser.window().setWindowIcon(curtab.icon())
|
new_tabbed_browser.window().setWindowIcon(curtab.icon())
|
||||||
newtab.keep_icon = True
|
newtab.data.keep_icon = True
|
||||||
newtab.zoom.set_factor(curtab.zoom.factor())
|
newtab.zoom.set_factor(curtab.zoom.factor())
|
||||||
newtab.history.deserialize(curtab.history.serialize())
|
newtab.history.deserialize(curtab.history.serialize())
|
||||||
return newtab
|
return newtab
|
||||||
|
@ -63,6 +63,34 @@ class WrapperLayout(QLayout):
|
|||||||
self._widget.setGeometry(r)
|
self._widget.setGeometry(r)
|
||||||
|
|
||||||
|
|
||||||
|
class TabData(QObject):
|
||||||
|
|
||||||
|
"""A simple namespace with a fixed set of attributes.
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
keep_icon: Whether the (e.g. cloned) icon should not be cleared on page
|
||||||
|
load.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._data = {'keep_icon': False}
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
if attr.startswith('_'):
|
||||||
|
return super().__getattr__(attr)
|
||||||
|
try:
|
||||||
|
return self._data[attr]
|
||||||
|
except KeyError:
|
||||||
|
raise AttributeError(attr)
|
||||||
|
|
||||||
|
def __setattr__(self, attr, value):
|
||||||
|
if attr.startswith('_'):
|
||||||
|
return super().__setattr__(attr, value)
|
||||||
|
if attr not in self._data:
|
||||||
|
raise AttributeError("Can't set unknown attribute {!r}".format(attr))
|
||||||
|
self._data[attr] = value
|
||||||
|
|
||||||
|
|
||||||
class AbstractSearch(QObject):
|
class AbstractSearch(QObject):
|
||||||
|
|
||||||
"""Attribute of AbstractTab for doing searches.
|
"""Attribute of AbstractTab for doing searches.
|
||||||
@ -381,8 +409,6 @@ class AbstractTab(QWidget):
|
|||||||
We use this to unify QWebView and QWebEngineView.
|
We use this to unify QWebView and QWebEngineView.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
keep_icon: Whether the (e.g. cloned) icon should not be cleared on page
|
|
||||||
load.
|
|
||||||
history: The AbstractHistory for the current tab.
|
history: The AbstractHistory for the current tab.
|
||||||
|
|
||||||
for properties, see WebView/WebEngineView docs.
|
for properties, see WebView/WebEngineView docs.
|
||||||
@ -416,9 +442,9 @@ class AbstractTab(QWidget):
|
|||||||
# self.caret = AbstractCaret(win_id=win_id, tab=self, parent=self)
|
# self.caret = AbstractCaret(win_id=win_id, tab=self, parent=self)
|
||||||
# self.zoom = AbstractZoom(win_id=win_id)
|
# self.zoom = AbstractZoom(win_id=win_id)
|
||||||
# self.search = AbstractSearch(parent=self)
|
# self.search = AbstractSearch(parent=self)
|
||||||
|
self.data = TabData()
|
||||||
self._layout = None
|
self._layout = None
|
||||||
self._widget = None
|
self._widget = None
|
||||||
self.keep_icon = False # FIXME:refactor get rid of this?
|
|
||||||
self.backend = None
|
self.backend = None
|
||||||
|
|
||||||
def _set_widget(self, widget):
|
def _set_widget(self, widget):
|
||||||
|
@ -98,7 +98,6 @@ class WebView(QWebView):
|
|||||||
self._old_scroll_pos = (-1, -1)
|
self._old_scroll_pos = (-1, -1)
|
||||||
self._has_ssl_errors = False
|
self._has_ssl_errors = False
|
||||||
self._ignore_wheel_event = False
|
self._ignore_wheel_event = False
|
||||||
self.keep_icon = False
|
|
||||||
self._set_bg_color()
|
self._set_bg_color()
|
||||||
self.cur_url = QUrl()
|
self.cur_url = QUrl()
|
||||||
self.progress = 0
|
self.progress = 0
|
||||||
|
@ -464,8 +464,8 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
# We can get signals for tabs we already deleted...
|
# We can get signals for tabs we already deleted...
|
||||||
return
|
return
|
||||||
self.update_tab_title(idx)
|
self.update_tab_title(idx)
|
||||||
if tab.keep_icon:
|
if tab.data.keep_icon:
|
||||||
tab.keep_icon = False
|
tab.data.keep_icon = False
|
||||||
else:
|
else:
|
||||||
self.setTabIcon(idx, QIcon())
|
self.setTabIcon(idx, QIcon())
|
||||||
if (config.get('tabs', 'tabs-are-windows') and
|
if (config.get('tabs', 'tabs-are-windows') and
|
||||||
|
@ -47,3 +47,19 @@ def test_tab(qtbot, view):
|
|||||||
assert tab_w.history.tab is tab_w
|
assert tab_w.history.tab is tab_w
|
||||||
assert tab_w.history.history is w.history()
|
assert tab_w.history.history is w.history()
|
||||||
assert w.parent() is tab_w
|
assert w.parent() is tab_w
|
||||||
|
|
||||||
|
|
||||||
|
class TestTabData:
|
||||||
|
|
||||||
|
def test_known_attr(self):
|
||||||
|
data = tab.TabData()
|
||||||
|
assert data.keep_icon == False
|
||||||
|
data.keep_icon = True
|
||||||
|
assert data.keep_icon == True
|
||||||
|
|
||||||
|
def test_unknown_attr(self):
|
||||||
|
data = tab.TabData()
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
data.bar = 42
|
||||||
|
with pytest.raises(AttributeError):
|
||||||
|
data.bar
|
||||||
|
Loading…
Reference in New Issue
Block a user