Get rid of mainwindow.MainWindow.spawn.
This commit is contained in:
parent
d8fe62bc61
commit
56b0ae2b6e
@ -205,11 +205,10 @@ class Application(QApplication):
|
|||||||
objreg.register('cache', diskcache)
|
objreg.register('cache', diskcache)
|
||||||
if not session_manager.exists(self._args.session):
|
if not session_manager.exists(self._args.session):
|
||||||
log.init.debug("Initializing main window...")
|
log.init.debug("Initializing main window...")
|
||||||
win_id = mainwindow.MainWindow.spawn(
|
window = mainwindow.MainWindow()
|
||||||
False if self._args.nowindow else True)
|
if not self._args.nowindow:
|
||||||
main_window = objreg.get('main-window', scope='window',
|
window.show()
|
||||||
window=win_id)
|
self.setActiveWindow(window)
|
||||||
self.setActiveWindow(main_window)
|
|
||||||
|
|
||||||
def _init_icon(self):
|
def _init_icon(self):
|
||||||
"""Initialize the icon of qutebrowser."""
|
"""Initialize the icon of qutebrowser."""
|
||||||
@ -305,17 +304,18 @@ class Application(QApplication):
|
|||||||
window_to_raise = None
|
window_to_raise = None
|
||||||
open_target = config.get('general', 'new-instance-open-target')
|
open_target = config.get('general', 'new-instance-open-target')
|
||||||
if (open_target == 'window' or force_window) and not force_tab:
|
if (open_target == 'window' or force_window) and not force_tab:
|
||||||
win_id = mainwindow.MainWindow.spawn()
|
window = mainwindow.MainWindow()
|
||||||
window = objreg.get('main-window', scope='window', window=win_id)
|
window.show()
|
||||||
|
win_id = window.win_id
|
||||||
window_to_raise = window
|
window_to_raise = window
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
window = objreg.last_window()
|
window = objreg.last_window()
|
||||||
except objreg.NoWindow:
|
except objreg.NoWindow:
|
||||||
# There is no window left, so we open a new one
|
# There is no window left, so we open a new one
|
||||||
win_id = mainwindow.MainWindow.spawn()
|
window = mainwindow.MainWindow()
|
||||||
window = objreg.get('main-window', scope='window',
|
window.show()
|
||||||
window=win_id)
|
win_id = window.win_id
|
||||||
window_to_raise = window
|
window_to_raise = window
|
||||||
win_id = window.win_id
|
win_id = window.win_id
|
||||||
if open_target != 'tab-silent':
|
if open_target != 'tab-silent':
|
||||||
|
@ -70,10 +70,11 @@ class CommandDispatcher:
|
|||||||
Args:
|
Args:
|
||||||
window: If True, open a new window.
|
window: If True, open a new window.
|
||||||
"""
|
"""
|
||||||
|
from qutebrowser.mainwindow import mainwindow
|
||||||
if window:
|
if window:
|
||||||
main_window = objreg.get('main-window', scope='window',
|
new_window = mainwindow.MainWindow()
|
||||||
window=self._win_id)
|
new_window.show()
|
||||||
win_id = main_window.spawn()
|
win_id = new_window.win_id
|
||||||
else:
|
else:
|
||||||
win_id = self._win_id
|
win_id = self._win_id
|
||||||
return objreg.get('tabbed-browser', scope='window', window=win_id)
|
return objreg.get('tabbed-browser', scope='window', window=win_id)
|
||||||
|
@ -612,6 +612,7 @@ class HintManager(QObject):
|
|||||||
background: True to open in a background tab.
|
background: True to open in a background tab.
|
||||||
window: True to open in a new window, False for the current one.
|
window: True to open in a new window, False for the current one.
|
||||||
"""
|
"""
|
||||||
|
from qutebrowser.mainwindow import mainwindow
|
||||||
elem = self._find_prevnext(frame, prev)
|
elem = self._find_prevnext(frame, prev)
|
||||||
if elem is None:
|
if elem is None:
|
||||||
raise cmdexc.CommandError("No {} links found!".format(
|
raise cmdexc.CommandError("No {} links found!".format(
|
||||||
@ -622,11 +623,10 @@ class HintManager(QObject):
|
|||||||
"prev" if prev else "forward"))
|
"prev" if prev else "forward"))
|
||||||
qtutils.ensure_valid(url)
|
qtutils.ensure_valid(url)
|
||||||
if window:
|
if window:
|
||||||
main_window = objreg.get('main-window', scope='window',
|
new_window = mainwindow.MainWindow()
|
||||||
window=self._win_id)
|
new_window.show()
|
||||||
win_id = main_window.spawn()
|
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=new_window.win_id)
|
||||||
tabbed_browser.tabopen(url, background=False)
|
tabbed_browser.tabopen(url, background=False)
|
||||||
elif tab:
|
elif tab:
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
|
@ -502,11 +502,11 @@ class BrowserPage(QWebPage):
|
|||||||
tabbed_browser.tabopen(url, True)
|
tabbed_browser.tabopen(url, True)
|
||||||
return False
|
return False
|
||||||
elif open_target == usertypes.ClickTarget.window:
|
elif open_target == usertypes.ClickTarget.window:
|
||||||
main_window = objreg.get('main-window', scope='window',
|
from qutebrowser.mainwindow import mainwindow
|
||||||
window=self._win_id)
|
window = mainwindow.MainWindow()
|
||||||
win_id = main_window.spawn()
|
window.show()
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=window.win_id)
|
||||||
tabbed_browser.tabopen(url, False)
|
tabbed_browser.tabopen(url, False)
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
|
@ -54,33 +54,33 @@ class MainWindow(QWidget):
|
|||||||
_commandrunner: The main CommandRunner instance.
|
_commandrunner: The main CommandRunner instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, win_id, geometry=None, parent=None):
|
def __init__(self, geometry=None, parent=None):
|
||||||
"""Create a new main window.
|
"""Create a new main window.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
win_id: The ID the new window whouls get.
|
|
||||||
geometry: The geometry to load, as a bytes-object (or None).
|
geometry: The geometry to load, as a bytes-object (or None).
|
||||||
parent: The parent the window should get.
|
parent: The parent the window should get.
|
||||||
"""
|
"""
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.setAttribute(Qt.WA_DeleteOnClose)
|
self.setAttribute(Qt.WA_DeleteOnClose)
|
||||||
self._commandrunner = None
|
self._commandrunner = None
|
||||||
self.win_id = win_id
|
self.win_id = next(win_id_gen)
|
||||||
self.registry = objreg.ObjectRegistry()
|
self.registry = objreg.ObjectRegistry()
|
||||||
objreg.window_registry[win_id] = self
|
objreg.window_registry[self.win_id] = self
|
||||||
objreg.register('main-window', self, scope='window', window=win_id)
|
objreg.register('main-window', self, scope='window',
|
||||||
|
window=self.win_id)
|
||||||
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=self.win_id)
|
||||||
|
|
||||||
message_bridge = message.MessageBridge(self)
|
message_bridge = message.MessageBridge(self)
|
||||||
objreg.register('message-bridge', message_bridge, scope='window',
|
objreg.register('message-bridge', message_bridge, scope='window',
|
||||||
window=win_id)
|
window=self.win_id)
|
||||||
|
|
||||||
self.setWindowTitle('qutebrowser')
|
self.setWindowTitle('qutebrowser')
|
||||||
if geometry is not None:
|
if geometry is not None:
|
||||||
self._load_geometry(geometry)
|
self._load_geometry(geometry)
|
||||||
elif win_id == 0:
|
elif self.win_id == 0:
|
||||||
self._load_state_geometry()
|
self._load_state_geometry()
|
||||||
else:
|
else:
|
||||||
self._set_default_geometry()
|
self._set_default_geometry()
|
||||||
@ -91,33 +91,33 @@ class MainWindow(QWidget):
|
|||||||
self._vbox.setSpacing(0)
|
self._vbox.setSpacing(0)
|
||||||
|
|
||||||
log.init.debug("Initializing downloads...")
|
log.init.debug("Initializing downloads...")
|
||||||
download_manager = downloads.DownloadManager(win_id, self)
|
download_manager = downloads.DownloadManager(self.win_id, self)
|
||||||
objreg.register('download-manager', download_manager, scope='window',
|
objreg.register('download-manager', download_manager, scope='window',
|
||||||
window=win_id)
|
window=self.win_id)
|
||||||
|
|
||||||
self._downloadview = downloadview.DownloadView(win_id)
|
self._downloadview = downloadview.DownloadView(self.win_id)
|
||||||
self._vbox.addWidget(self._downloadview)
|
self._vbox.addWidget(self._downloadview)
|
||||||
self._downloadview.show()
|
self._downloadview.show()
|
||||||
|
|
||||||
self._tabbed_browser = tabbedbrowser.TabbedBrowser(win_id)
|
self._tabbed_browser = tabbedbrowser.TabbedBrowser(self.win_id)
|
||||||
objreg.register('tabbed-browser', self._tabbed_browser, scope='window',
|
objreg.register('tabbed-browser', self._tabbed_browser, scope='window',
|
||||||
window=win_id)
|
window=self.win_id)
|
||||||
self._vbox.addWidget(self._tabbed_browser)
|
self._vbox.addWidget(self._tabbed_browser)
|
||||||
|
|
||||||
# We need to set an explicit parent for StatusBar because it does some
|
# We need to set an explicit parent for StatusBar because it does some
|
||||||
# show/hide magic immediately which would mean it'd show up as a
|
# show/hide magic immediately which would mean it'd show up as a
|
||||||
# window.
|
# window.
|
||||||
self.status = bar.StatusBar(win_id, parent=self)
|
self.status = bar.StatusBar(self.win_id, parent=self)
|
||||||
self._vbox.addWidget(self.status)
|
self._vbox.addWidget(self.status)
|
||||||
|
|
||||||
self._completion = completionwidget.CompletionView(win_id, self)
|
self._completion = completionwidget.CompletionView(self.win_id, self)
|
||||||
|
|
||||||
self._commandrunner = runners.CommandRunner(win_id)
|
self._commandrunner = runners.CommandRunner(self.win_id)
|
||||||
|
|
||||||
log.init.debug("Initializing search...")
|
log.init.debug("Initializing search...")
|
||||||
search_runner = runners.SearchRunner(self)
|
search_runner = runners.SearchRunner(self)
|
||||||
objreg.register('search-runner', search_runner, scope='window',
|
objreg.register('search-runner', search_runner, scope='window',
|
||||||
window=win_id)
|
window=self.win_id)
|
||||||
|
|
||||||
log.init.debug("Initializing modes...")
|
log.init.debug("Initializing modes...")
|
||||||
modeman.init(self.win_id, self)
|
modeman.init(self.win_id, self)
|
||||||
@ -142,23 +142,6 @@ class MainWindow(QWidget):
|
|||||||
if section == 'completion' and option in ('height', 'shrink'):
|
if section == 'completion' and option in ('height', 'shrink'):
|
||||||
self.resize_completion()
|
self.resize_completion()
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def spawn(cls, show=True, geometry=None):
|
|
||||||
"""Create a new main window.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
show: Show the window after creating.
|
|
||||||
geometry: The geometry to load, as a bytes-object.
|
|
||||||
|
|
||||||
Return:
|
|
||||||
The new window id.
|
|
||||||
"""
|
|
||||||
win_id = next(win_id_gen)
|
|
||||||
win = MainWindow(win_id, geometry=geometry)
|
|
||||||
if show:
|
|
||||||
win.show()
|
|
||||||
return win_id
|
|
||||||
|
|
||||||
def _load_state_geometry(self):
|
def _load_state_geometry(self):
|
||||||
"""Load the geometry from the state file."""
|
"""Load the geometry from the state file."""
|
||||||
state_config = objreg.get('state-config')
|
state_config = objreg.get('state-config')
|
||||||
|
@ -327,9 +327,10 @@ class TabbedBrowser(tabwidget.TabWidget):
|
|||||||
log.webview.debug("Creating new tab with URL {}".format(url))
|
log.webview.debug("Creating new tab with URL {}".format(url))
|
||||||
if config.get('tabs', 'tabs-are-windows') and self.count() > 0:
|
if config.get('tabs', 'tabs-are-windows') and self.count() > 0:
|
||||||
from qutebrowser.mainwindow import mainwindow
|
from qutebrowser.mainwindow import mainwindow
|
||||||
window = mainwindow.MainWindow.spawn()
|
window = mainwindow.MainWindow()
|
||||||
|
window.show()
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=window)
|
window=window.win_id)
|
||||||
return tabbed_browser.tabopen(url, background, explicit)
|
return tabbed_browser.tabopen(url, background, explicit)
|
||||||
tab = webview.WebView(self._win_id, self)
|
tab = webview.WebView(self._win_id, self)
|
||||||
self._connect_tab_signals(tab)
|
self._connect_tab_signals(tab)
|
||||||
|
@ -207,9 +207,10 @@ class SessionManager(QObject):
|
|||||||
raise SessionError(e)
|
raise SessionError(e)
|
||||||
log.misc.debug("Loading session {} from {}...".format(name, path))
|
log.misc.debug("Loading session {} from {}...".format(name, path))
|
||||||
for win in data['windows']:
|
for win in data['windows']:
|
||||||
win_id = mainwindow.MainWindow.spawn(geometry=win['geometry'])
|
window = mainwindow.MainWindow(geometry=win['geometry'])
|
||||||
|
window.show()
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=window.win_id)
|
||||||
tab_to_focus = None
|
tab_to_focus = None
|
||||||
for i, tab in enumerate(win['tabs']):
|
for i, tab in enumerate(win['tabs']):
|
||||||
new_tab = tabbed_browser.tabopen()
|
new_tab = tabbed_browser.tabopen()
|
||||||
|
Loading…
Reference in New Issue
Block a user