diff options
Diffstat (limited to 'qutebrowser/browser/commands.py')
-rw-r--r-- | qutebrowser/browser/commands.py | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/qutebrowser/browser/commands.py b/qutebrowser/browser/commands.py index f9c4bb8e1..84f217a38 100644 --- a/qutebrowser/browser/commands.py +++ b/qutebrowser/browser/commands.py @@ -24,8 +24,8 @@ import shlex import functools from typing import cast, Callable, Dict, Union, Optional -from PyQt5.QtWidgets import QApplication, QTabBar -from PyQt5.QtCore import Qt, QUrl, QEvent, QUrlQuery +from qutebrowser.qt.widgets import QApplication, QTabBar +from qutebrowser.qt.core import Qt, QUrl, QEvent, QUrlQuery from qutebrowser.commands import userscripts, runners from qutebrowser.api import cmdutils @@ -70,9 +70,7 @@ class CommandDispatcher: raise cmdutils.CommandError("Private windows are unavailable with " "the single-process process model.") - new_window = mainwindow.MainWindow(private=private) - new_window.show() - return new_window.tabbed_browser + return mainwindow.MainWindow(private=private).tabbed_browser def _count(self) -> int: """Convenience method to get the widget count.""" @@ -109,8 +107,15 @@ class CommandDispatcher: raise cmdutils.CommandError("No WebView available yet!") return widget - def _open(self, url, tab=False, background=False, window=False, - related=False, private=None): + def _open( + self, + url: QUrl, + tab: bool = False, + background: bool = False, + window: bool = False, + related: bool = False, + private: Optional[bool] = None, + ) -> None: """Helper function to open a page. Args: @@ -123,13 +128,15 @@ class CommandDispatcher: """ urlutils.raise_cmdexc_if_invalid(url) tabbed_browser = self._tabbed_browser - cmdutils.check_exclusive((tab, background, window, private), 'tbwp') + cmdutils.check_exclusive((tab, background, window, private or False), 'tbwp') if window and private is None: private = self._tabbed_browser.is_private if window or private: + assert isinstance(private, bool) tabbed_browser = self._new_tabbed_browser(private) tabbed_browser.tabopen(url) + tabbed_browser.window().show() elif tab: tabbed_browser.tabopen(url, background=False, related=related) elif background: @@ -192,21 +199,21 @@ class CommandDispatcher: what's configured in 'tabs.select_on_remove'. Return: - QTabBar.SelectLeftTab, QTabBar.SelectRightTab, or None if no change + QTabBar.SelectionBehavior.SelectLeftTab, QTabBar.SelectionBehavior.SelectRightTab, or None if no change should be made. """ cmdutils.check_exclusive((prev, next_, opposite), 'pno') if prev: - return QTabBar.SelectLeftTab + return QTabBar.SelectionBehavior.SelectLeftTab elif next_: - return QTabBar.SelectRightTab + return QTabBar.SelectionBehavior.SelectRightTab elif opposite: conf_selection = config.val.tabs.select_on_remove - if conf_selection == QTabBar.SelectLeftTab: - return QTabBar.SelectRightTab - elif conf_selection == QTabBar.SelectRightTab: - return QTabBar.SelectLeftTab - elif conf_selection == QTabBar.SelectPreviousTab: + if conf_selection == QTabBar.SelectionBehavior.SelectLeftTab: + return QTabBar.SelectionBehavior.SelectRightTab + elif conf_selection == QTabBar.SelectionBehavior.SelectRightTab: + return QTabBar.SelectionBehavior.SelectLeftTab + elif conf_selection == QTabBar.SelectionBehavior.SelectPreviousTab: raise cmdutils.CommandError( "-o is not supported with 'tabs.select_on_remove' set to " "'last-used'!") @@ -403,14 +410,17 @@ class CommandDispatcher: except browsertab.WebTabError as e: raise cmdutils.CommandError(e) - # The new tab could be in a new tabbed_browser (e.g. because of - # tabs.tabs_are_windows being set) if window or private: new_tabbed_browser = self._new_tabbed_browser( private=self._tabbed_browser.is_private or private) else: new_tabbed_browser = self._tabbed_browser + newtab = new_tabbed_browser.tabopen(background=bg) + new_tabbed_browser.window().show() + + # The new tab could be in a new tabbed_browser (e.g. because of + # tabs.tabs_are_windows being set) new_tabbed_browser = objreg.get('tabbed-browser', scope='window', window=newtab.win_id) idx = new_tabbed_browser.widget.indexOf(newtab) @@ -498,6 +508,8 @@ class CommandDispatcher: "The window with id {} is not private".format(win_id)) tabbed_browser.tabopen(self._current_url()) + tabbed_browser.window().show() + if not keep: self._tabbed_browser.close_tab(self._current_widget(), add_undo=False, @@ -706,9 +718,9 @@ class CommandDispatcher: assert what in ['url', 'pretty-url'], what if what == 'pretty-url': - flags = QUrl.RemovePassword | QUrl.DecodeReserved + flags = QUrl.UrlFormattingOption.RemovePassword | QUrl.ComponentFormattingOption.DecodeReserved else: - flags = QUrl.RemovePassword | QUrl.FullyEncoded + flags = QUrl.UrlFormattingOption.RemovePassword | QUrl.ComponentFormattingOption.FullyEncoded url = QUrl(self._current_url()) url_query = QUrlQuery() @@ -1200,7 +1212,7 @@ class CommandDispatcher: except qtutils.QtValueError: pass else: - env['QUTE_URL'] = url.toString(QUrl.FullyEncoded) + env['QUTE_URL'] = url.toString(QUrl.ComponentFormattingOption.FullyEncoded) try: runner = userscripts.run_async( @@ -1330,8 +1342,8 @@ class CommandDispatcher: current page's url. """ if url is None: - url = self._current_url().toString(QUrl.RemovePassword | - QUrl.FullyEncoded) + url = self._current_url().toString(QUrl.UrlFormattingOption.RemovePassword | + QUrl.ComponentFormattingOption.FullyEncoded) try: objreg.get('bookmark-manager').delete(url) except KeyError: @@ -1774,8 +1786,8 @@ class CommandDispatcher: raise cmdutils.CommandError(str(e)) for keyinfo in sequence: - press_event = keyinfo.to_event(QEvent.KeyPress) - release_event = keyinfo.to_event(QEvent.KeyRelease) + press_event = keyinfo.to_event(QEvent.Type.KeyPress) + release_event = keyinfo.to_event(QEvent.Type.KeyRelease) if global_: window = QApplication.focusWindow() @@ -1882,9 +1894,9 @@ class CommandDispatcher: if not window.isFullScreen(): window.state_before_fullscreen = window.windowState() if enter: - window.setWindowState(window.windowState() | Qt.WindowFullScreen) + window.setWindowState(window.windowState() | Qt.WindowState.WindowFullScreen) else: - window.setWindowState(window.windowState() ^ Qt.WindowFullScreen) + window.setWindowState(window.windowState() ^ Qt.WindowState.WindowFullScreen) log.misc.debug('state before fullscreen: {}'.format( debug.qflags_key(Qt, window.state_before_fullscreen))) |