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