parent
2278d30187
commit
5fa1556588
@ -231,8 +231,8 @@ class Application(QApplication):
|
|||||||
window_to_raise = window
|
window_to_raise = window
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
window = objreg.get('last-main-window')
|
window = objreg.last_window()
|
||||||
except KeyError:
|
except objreg.NoWindow:
|
||||||
# We can't display an error here because... duh, there is no
|
# We can't display an error here because... duh, there is no
|
||||||
# window.
|
# window.
|
||||||
log.ipc.error("No main window found!")
|
log.ipc.error("No main window found!")
|
||||||
|
@ -45,6 +45,11 @@ class RegistryUnavailableError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NoWindow(Exception):
|
||||||
|
|
||||||
|
"""Exception raised by last_window if no window is available."""
|
||||||
|
|
||||||
|
|
||||||
_UNSET = UnsetObject()
|
_UNSET = UnsetObject()
|
||||||
|
|
||||||
|
|
||||||
@ -141,8 +146,8 @@ def _get_window_registry(window):
|
|||||||
win = get('last-focused-main-window')
|
win = get('last-focused-main-window')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
try:
|
try:
|
||||||
win = get('last-main-window')
|
win = last_window()
|
||||||
except KeyError:
|
except NoWindow:
|
||||||
raise RegistryUnavailableError('window')
|
raise RegistryUnavailableError('window')
|
||||||
assert hasattr(win, 'registry')
|
assert hasattr(win, 'registry')
|
||||||
else:
|
else:
|
||||||
@ -238,3 +243,12 @@ def dump_objects():
|
|||||||
for line in data:
|
for line in data:
|
||||||
lines.append(" {}".format(line))
|
lines.append(" {}".format(line))
|
||||||
return lines
|
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]
|
||||||
|
@ -62,7 +62,6 @@ class MainWindow(QWidget):
|
|||||||
self.registry = objreg.ObjectRegistry()
|
self.registry = objreg.ObjectRegistry()
|
||||||
objreg.window_registry[win_id] = self
|
objreg.window_registry[win_id] = self
|
||||||
objreg.register('main-window', self, scope='window', window=win_id)
|
objreg.register('main-window', self, scope='window', window=win_id)
|
||||||
objreg.register('last-main-window', self, update=True)
|
|
||||||
tab_registry = objreg.ObjectRegistry()
|
tab_registry = objreg.ObjectRegistry()
|
||||||
objreg.register('tab-registry', tab_registry, scope='window',
|
objreg.register('tab-registry', tab_registry, scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user