Fix getting last main window when it was closed.

Fixes #242.
This commit is contained in:
Florian Bruhin 2014-11-10 23:21:31 +01:00
parent 2278d30187
commit 5fa1556588
3 changed files with 18 additions and 5 deletions

View File

@ -231,8 +231,8 @@ class Application(QApplication):
window_to_raise = window
else:
try:
window = objreg.get('last-main-window')
except KeyError:
window = objreg.last_window()
except objreg.NoWindow:
# We can't display an error here because... duh, there is no
# window.
log.ipc.error("No main window found!")

View File

@ -45,6 +45,11 @@ class RegistryUnavailableError(Exception):
pass
class NoWindow(Exception):
"""Exception raised by last_window if no window is available."""
_UNSET = UnsetObject()
@ -141,8 +146,8 @@ def _get_window_registry(window):
win = get('last-focused-main-window')
except KeyError:
try:
win = get('last-main-window')
except KeyError:
win = last_window()
except NoWindow:
raise RegistryUnavailableError('window')
assert hasattr(win, 'registry')
else:
@ -238,3 +243,12 @@ def dump_objects():
for line in data:
lines.append(" {}".format(line))
return lines
def last_window():
"""Get the last opened window object."""
if not window_registry:
raise NoWindow()
else:
key = sorted(window_registry)[-1]
return window_registry[key]

View File

@ -62,7 +62,6 @@ class MainWindow(QWidget):
self.registry = objreg.ObjectRegistry()
objreg.window_registry[win_id] = self
objreg.register('main-window', self, scope='window', window=win_id)
objreg.register('last-main-window', self, update=True)
tab_registry = objreg.ObjectRegistry()
objreg.register('tab-registry', tab_registry, scope='window',
window=win_id)