Use object registry for tabbedbrowser.
This commit is contained in:
parent
487300f926
commit
a76c4c8ba5
@ -327,7 +327,7 @@ class Application(QApplication):
|
||||
# we make sure the GUI is refreshed here, so the start seems faster.
|
||||
self.processEvents(QEventLoop.ExcludeUserInputEvents |
|
||||
QEventLoop.ExcludeSocketNotifiers)
|
||||
|
||||
tabbedbrowser = self.registry['tabbedbrowser']
|
||||
for cmd in self.args.command:
|
||||
if cmd.startswith(':'):
|
||||
log.init.debug("Startup cmd {}".format(cmd))
|
||||
@ -340,9 +340,9 @@ class Application(QApplication):
|
||||
message.error("Error in startup argument '{}': {}".format(
|
||||
cmd, e))
|
||||
else:
|
||||
self.mainwindow.tabs.tabopen(url)
|
||||
tabbedbrowser.tabopen(url)
|
||||
|
||||
if self.mainwindow.tabs.count() == 0:
|
||||
if tabbedbrowser.count() == 0:
|
||||
log.init.debug("Opening startpage")
|
||||
for urlstr in self.config.get('general', 'startpage'):
|
||||
try:
|
||||
@ -350,7 +350,7 @@ class Application(QApplication):
|
||||
except urlutils.FuzzyUrlError as e:
|
||||
message.error("Error when opening startpage: {}".format(e))
|
||||
else:
|
||||
self.mainwindow.tabs.tabopen(url)
|
||||
tabbedbrowser.tabopen(url)
|
||||
|
||||
def _python_hacks(self):
|
||||
"""Get around some PyQt-oddities by evil hacks.
|
||||
@ -373,7 +373,7 @@ class Application(QApplication):
|
||||
kp = self._keyparsers
|
||||
status = self.mainwindow.status
|
||||
completion = self.registry['completion']
|
||||
tabs = self.mainwindow.tabs
|
||||
tabs = self.registry['tabbedbrowser']
|
||||
cmd = self.registry['status-cmd']
|
||||
completer = self.registry['completer']
|
||||
searchrunner = self.registry['searchrunner']
|
||||
@ -509,12 +509,12 @@ class Application(QApplication):
|
||||
Return:
|
||||
A list of open pages, or an empty list.
|
||||
"""
|
||||
try:
|
||||
tabbedbrowser = self.registry['tabbedbrowser']
|
||||
except KeyError:
|
||||
return []
|
||||
pages = []
|
||||
if self.mainwindow is None:
|
||||
return pages
|
||||
if self.mainwindow.tabs is None:
|
||||
return pages
|
||||
for tab in self.mainwindow.tabs.widgets():
|
||||
for tab in tabbedbrowser.widgets():
|
||||
try:
|
||||
url = tab.cur_url.toString(
|
||||
QUrl.RemovePassword | QUrl.FullyEncoded)
|
||||
@ -617,7 +617,7 @@ class Application(QApplication):
|
||||
# exceptions occur.
|
||||
if pages is None:
|
||||
pages = []
|
||||
for tab in self.mainwindow.tabs.widgets():
|
||||
for tab in utils.get_object('tabbedbrowser').widgets():
|
||||
urlstr = tab.cur_url.toString(
|
||||
QUrl.RemovePassword | QUrl.FullyEncoded)
|
||||
if urlstr:
|
||||
@ -664,7 +664,8 @@ class Application(QApplication):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
out = traceback.format_exc()
|
||||
qutescheme.pyeval_output = out
|
||||
self.mainwindow.tabs.openurl(QUrl('qute:pyeval'), newtab=True)
|
||||
self.registry['tabbedbrowser'].openurl(
|
||||
QUrl('qute:pyeval'), newtab=True)
|
||||
|
||||
@cmdutils.register(instance='')
|
||||
def report(self):
|
||||
@ -755,9 +756,11 @@ class Application(QApplication):
|
||||
except KeyError:
|
||||
pass
|
||||
# Close all tabs
|
||||
if self.mainwindow is not None:
|
||||
try:
|
||||
log.destroy.debug("Closing tabs...")
|
||||
self.mainwindow.tabs.shutdown()
|
||||
self.registry['tabbedbrowser'].shutdown()
|
||||
except KeyError:
|
||||
pass
|
||||
# Save everything
|
||||
if hasattr(self, 'config') and self.config is not None:
|
||||
to_save = []
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
import argparse
|
||||
|
||||
from PyQt5.QtCore import QCoreApplication, QUrl
|
||||
from PyQt5.QtCore import QUrl
|
||||
|
||||
from qutebrowser.commands import cmdexc
|
||||
from qutebrowser.utils import utils
|
||||
@ -54,7 +54,7 @@ class HelpAction(argparse.Action):
|
||||
"""
|
||||
|
||||
def __call__(self, parser, _namespace, _values, _option_string=None):
|
||||
QCoreApplication.instance().mainwindow.tabs.tabopen(
|
||||
utils.get_object('tabbedbrowser').tabopen(
|
||||
QUrl('qute://help/commands.html#{}'.format(parser.name)))
|
||||
parser.exit()
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
"""Module containing command managers (SearchRunner and CommandRunner)."""
|
||||
|
||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QCoreApplication, QUrl
|
||||
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QObject, QUrl
|
||||
from PyQt5.QtWebKitWidgets import QWebPage
|
||||
|
||||
from qutebrowser.config import config
|
||||
@ -32,8 +32,7 @@ def replace_variables(arglist):
|
||||
args = []
|
||||
for arg in arglist:
|
||||
if arg == '{url}':
|
||||
app = QCoreApplication.instance()
|
||||
url = app.mainwindow.tabs.current_url().toString(
|
||||
url = utils.get_object('tabbedbrowser').current_url().toString(
|
||||
QUrl.FullyEncoded | QUrl.RemovePassword)
|
||||
args.append(url)
|
||||
else:
|
||||
|
@ -40,9 +40,9 @@ class MainWindow(QWidget):
|
||||
signals.
|
||||
|
||||
Attributes:
|
||||
tabs: The TabbedBrowser widget.
|
||||
status: The StatusBar widget.
|
||||
downloadview: The DownloadView widget.
|
||||
_tabbedbrowser: The TabbedBrowser widget.
|
||||
_vbox: The main QVBoxLayout.
|
||||
"""
|
||||
|
||||
@ -81,9 +81,10 @@ class MainWindow(QWidget):
|
||||
self._vbox.addWidget(self.downloadview)
|
||||
self.downloadview.show()
|
||||
|
||||
self.tabs = tabbedbrowser.TabbedBrowser()
|
||||
self.tabs.title_changed.connect(self.setWindowTitle)
|
||||
self._vbox.addWidget(self.tabs)
|
||||
self._tabbedbrowser = tabbedbrowser.TabbedBrowser()
|
||||
self._tabbedbrowser.title_changed.connect(self.setWindowTitle)
|
||||
utils.register_object('tabbedbrowser', self._tabbedbrowser)
|
||||
self._vbox.addWidget(self._tabbedbrowser)
|
||||
|
||||
self._completion = completion.CompletionView(self)
|
||||
utils.register_object('completion', self._completion)
|
||||
@ -163,12 +164,12 @@ class MainWindow(QWidget):
|
||||
super().resizeEvent(e)
|
||||
self.resize_completion()
|
||||
self.downloadview.updateGeometry()
|
||||
self.tabs.tabBar().refresh()
|
||||
self._tabbedbrowser.tabBar().refresh()
|
||||
|
||||
def closeEvent(self, e):
|
||||
"""Override closeEvent to display a confirmation if needed."""
|
||||
confirm_quit = config.get('ui', 'confirm-quit')
|
||||
count = self.tabs.count()
|
||||
count = self._tabbedbrowser.count()
|
||||
if confirm_quit == 'never':
|
||||
e.accept()
|
||||
elif confirm_quit == 'multiple-tabs' and count <= 1:
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
"""The commandline in the statusbar."""
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QCoreApplication, QUrl
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QUrl
|
||||
from PyQt5.QtWidgets import QSizePolicy, QApplication
|
||||
|
||||
from qutebrowser.keyinput import modeman, modeparsers
|
||||
from qutebrowser.commands import runners, cmdexc, cmdutils
|
||||
from qutebrowser.widgets import misc
|
||||
from qutebrowser.models import cmdhistory
|
||||
from qutebrowser.utils import usertypes, log
|
||||
from qutebrowser.utils import usertypes, log, utils
|
||||
|
||||
|
||||
class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||
@ -172,8 +172,7 @@ class Command(misc.MinimalLineEditMixin, misc.CommandLineEdit):
|
||||
Args:
|
||||
text: The commandline to set.
|
||||
"""
|
||||
app = QCoreApplication.instance()
|
||||
url = app.mainwindow.tabs.current_url().toString(
|
||||
url = utils.get_object('tabbedbrowser').current_url().toString(
|
||||
QUrl.FullyEncoded | QUrl.RemovePassword)
|
||||
# FIXME we currently replace the URL in any place in the arguments,
|
||||
# rather than just replacing it if it is a dedicated argument. We could
|
||||
|
Loading…
Reference in New Issue
Block a user