diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-06-23 10:54:59 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-06-23 11:04:10 +0200 |
commit | 6363c7f637eb25a3e6e8d7cf2f066451e128c853 (patch) | |
tree | d068ec67d72c0268bfe5bd2532fc4bcd7c607d30 | |
parent | 72bb4032e9b8ee5cc3108af0a2d2dd0ebbe0ff17 (diff) | |
download | qutebrowser-6363c7f637eb25a3e6e8d7cf2f066451e128c853.tar.gz qutebrowser-6363c7f637eb25a3e6e8d7cf2f066451e128c853.zip |
inspector: Simplify showing in a window
-rw-r--r-- | qutebrowser/browser/inspector.py | 32 | ||||
-rw-r--r-- | tests/unit/browser/test_inspector.py | 15 |
2 files changed, 14 insertions, 33 deletions
diff --git a/qutebrowser/browser/inspector.py b/qutebrowser/browser/inspector.py index c1d680730..dd12f0a38 100644 --- a/qutebrowser/browser/inspector.py +++ b/qutebrowser/browser/inspector.py @@ -130,6 +130,7 @@ class AbstractWebInspector(QWidget): self._widget = widget self._widget.setWindowTitle("Web Inspector") self._widget.installEventFilter(self._child_event_filter) + self._layout.wrap(self, self._widget) def _load_position(self) -> Position: """Get the last position the inspector was in.""" @@ -157,39 +158,20 @@ class AbstractWebInspector(QWidget): self._position = position if position == Position.window: - self._show_window() + self.setParent(None) + self._load_state_geometry() else: - self._show_docked(position) - - def _show_window(self) -> None: - """Show the inspector in a separate window. + self._splitter.set_inspector(self, position) - In theory, we should be able to do self.setParent(None) to remove - ourselves from the InspectorSplitter and show up as window instead. - - In practice, that approach doesn't work for some odd reason. Thus, we - instead remove ourselves from the InspectorSplitter, and then show the - actual inspector widget without a WrapperLayout involved. - """ - self.hide() - self._layout.unwrap() - self._load_state_geometry() - self._widget.show() - - def _show_docked(self, position: Position) -> None: - """Show the inspector docked inside the main window.""" - self._layout.wrap(self, self._widget) - self._splitter.set_inspector(self, position) self._widget.show() self.show() def toggle(self) -> None: """Toggle visibility of the inspector.""" - target = self._widget if self._position == Position.window else self - if target.isVisible(): - target.hide() + if self.isVisible(): + self.hide() else: - target.show() + self.show() def _load_state_geometry(self) -> None: """Load the geometry from the state file.""" diff --git a/tests/unit/browser/test_inspector.py b/tests/unit/browser/test_inspector.py index 48458a0e2..1f4763608 100644 --- a/tests/unit/browser/test_inspector.py +++ b/tests/unit/browser/test_inspector.py @@ -73,18 +73,18 @@ def fake_inspector(qtbot, splitter, inspector_widget, (inspector.Position.top, 2, False), ]) def test_set_position(position, splitter_count, window_visible, - fake_inspector, splitter, inspector_widget): + fake_inspector, splitter): fake_inspector.set_position(position) assert splitter.count() == splitter_count - assert (inspector_widget.isWindow() and - inspector_widget.isVisible()) == window_visible + assert (fake_inspector.isWindow() and + fake_inspector.isVisible()) == window_visible -def test_toggle_window(fake_inspector, inspector_widget): +def test_toggle_window(fake_inspector): fake_inspector.set_position(inspector.Position.window) for visible in [True, False, True]: - assert (inspector_widget.isWindow() and - inspector_widget.isVisible()) == visible + assert (fake_inspector.isWindow() and + fake_inspector.isVisible()) == visible fake_inspector.toggle() @@ -139,5 +139,4 @@ def test_detach_after_toggling(hidden_again, fake_inspector, inspector_widget, fake_inspector.set_position(inspector.Position.window) - assert not fake_inspector.isVisible() - assert inspector_widget.isWindow() and inspector_widget.isVisible() + assert fake_inspector.isVisible() and fake_inspector.isWindow() |