Use object registry for mainwindow.

This commit is contained in:
Florian Bruhin 2014-09-23 22:02:21 +02:00
parent a76c4c8ba5
commit a32ed36ba6
3 changed files with 12 additions and 13 deletions

View File

@ -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')

View File

@ -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

View File

@ -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)