Store window registries in objreg.

This commit is contained in:
Florian Bruhin 2014-10-05 22:17:29 +02:00
parent b6393a1841
commit dfd3b3d9c4
3 changed files with 18 additions and 16 deletions

View File

@ -359,8 +359,10 @@ 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() not in
objreg.window_registry.values()):
win = QApplication.instance().activeWindow()
if win is None:
return False
if win.objectName() != 'MainWindow':
# Some other window (print dialog, etc.) is focused so we pass
# the event through.
return False

View File

@ -115,22 +115,19 @@ def _get_tab_registry():
raise RegistryUnavailableError('tab')
def _get_window_registry(window):
def _get_window_registry(win_id):
"""Get the registry of a window."""
if window is None:
raise TypeError("window is None with scope window!")
if window is 'current':
if win_id is None:
raise TypeError("win_id is None with scope window!")
if win_id == 'current':
app = get('app')
win = app.activeWindow()
if win is None:
raise RegistryUnavailableError('window')
else:
try:
win = window_registry[window]
except KeyError:
raise RegistryUnavailableError('window')
else:
win_id = win.win_id
try:
return win.registry
return window_registry[win_id]
except AttributeError:
raise RegistryUnavailableError('window')
@ -199,8 +196,7 @@ def dump_objects():
blocks = []
lines = []
blocks.append(('global', global_registry.dump_objects()))
for win_id in window_registry:
registry = _get_registry('window', window=win_id)
for win_id, registry in window_registry.items():
blocks.append(('window-{}'.format(win_id), registry.dump_objects()))
# FIXME: Add tab registries
for name, data in sorted(blocks, key=lambda e: e[0]):

View File

@ -72,11 +72,15 @@ class MainWindow(QWidget):
def __init__(self, win_id, parent=None):
super().__init__(parent)
# Note the objectname is used in the event filter to filter keypresses
# not intended for the mainwindow. If this is changed, the event filter
# needs to be changed as well!
self.setObjectName('MainWindow')
self.setAttribute(Qt.WA_DeleteOnClose)
self._commandrunner = None
self.win_id = win_id
self.registry = objreg.ObjectRegistry()
objreg.window_registry[win_id] = self
registry = objreg.ObjectRegistry()
objreg.window_registry[win_id] = registry
objreg.register('main-window', self, scope='window', window=win_id)
message_bridge = message.MessageBridge(self)