From a32ed36ba6cd4a1b6f996e8fce18260be8248539 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 23 Sep 2014 22:02:21 +0200 Subject: [PATCH] Use object registry for mainwindow. --- qutebrowser/app.py | 13 +++++++------ qutebrowser/keyinput/modeman.py | 5 ++--- qutebrowser/widgets/tabwidget.py | 7 +++---- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index bab2438f5..1a833dff5 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -135,8 +135,8 @@ class Application(QApplication): log.init.debug("Initializing downloads...") self.downloadmanager = downloads.DownloadManager(self) log.init.debug("Initializing main window...") - self.mainwindow = mainwindow.MainWindow() - modeman_obj.mainwindow = self.mainwindow + mainwin = mainwindow.MainWindow() + self.registry['mainwindow'] = mainwin log.init.debug("Initializing debug console...") self._debugconsole = console.ConsoleWidget() log.init.debug("Initializing eventfilter...") @@ -149,7 +149,7 @@ class Application(QApplication): log.init.debug("Showing mainwindow...") if not args.nowindow: - self.mainwindow.show() + mainwin.show() log.init.debug("Applying python hacks...") self._python_hacks() QTimer.singleShot(0, self._process_init_args) @@ -371,7 +371,8 @@ class Application(QApplication): # pylint: disable=too-many-statements # syntactic sugar kp = self._keyparsers - status = self.mainwindow.status + mainwin = self.registry['mainwindow'] + status = mainwin.status completion = self.registry['completion'] tabs = self.registry['tabbedbrowser'] cmd = self.registry['status-cmd'] @@ -419,7 +420,7 @@ class Application(QApplication): # config self.config.style_changed.connect(style.get_stylesheet.cache_clear) - for obj in (tabs, completion, self.mainwindow, self.cmd_history, + for obj in (tabs, completion, mainwin, self.cmd_history, websettings, modeman, status, status.txt): self.config.changed.connect(obj.on_config_changed) for obj in kp.values(): @@ -527,7 +528,7 @@ class Application(QApplication): def _save_geometry(self): """Save the window geometry to the state config.""" stateconfig = self.registry['stateconfig'] - data = bytes(self.mainwindow.saveGeometry()) + data = bytes(self.registry['mainwindow'].saveGeometry()) geom = base64.b64encode(data).decode('ASCII') try: stateconfig.add_section('geometry') diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index 394c07388..3912717da 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -70,7 +70,6 @@ class ModeManager(QObject): Attributes: passthrough: A list of modes in which to pass through events. - mainwindow: The mainwindow object locked: Whether current mode is locked. This means the current mode can still be left (then locked will be reset), but no new mode can be entered while the current mode is active. @@ -94,7 +93,6 @@ class ModeManager(QObject): def __init__(self, parent=None): super().__init__(parent) - self.mainwindow = None self.locked = False self._handlers = {} self.passthrough = [] @@ -284,7 +282,8 @@ class ModeManager(QObject): # We already handled this same event at some point earlier, so # we're not interested in it anymore. return False - if QApplication.instance().activeWindow() is not self.mainwindow: + if (QApplication.instance().activeWindow() is not + utils.get_object('mainwindow')): # Some other window (print dialog, etc.) is focused so we pass # the event through. return False diff --git a/qutebrowser/widgets/tabwidget.py b/qutebrowser/widgets/tabwidget.py index 26e8b2df7..68a9e9627 100644 --- a/qutebrowser/widgets/tabwidget.py +++ b/qutebrowser/widgets/tabwidget.py @@ -28,11 +28,10 @@ import functools from PyQt5.QtCore import pyqtSlot, Qt, QSize, QRect, QPoint, QTimer from PyQt5.QtWidgets import (QTabWidget, QTabBar, QSizePolicy, QCommonStyle, - QStyle, QStylePainter, QStyleOptionTab, - QApplication) + QStyle, QStylePainter, QStyleOptionTab) from PyQt5.QtGui import QIcon, QPalette, QColor -from qutebrowser.utils import qtutils +from qutebrowser.utils import qtutils, utils from qutebrowser.config import config @@ -210,7 +209,7 @@ class TabBar(QTabBar): confwidth = str(config.get('tabs', 'width')) if confwidth.endswith('%'): perc = int(confwidth.rstrip('%')) - width = QApplication.instance().mainwindow.width() * perc / 100 + width = utils.get_object('mainwindow').width() * perc / 100 else: width = int(confwidth) size = QSize(max(minimum_size.width(), width), height)