Clean up mainwindow import mess.
This commit is contained in:
parent
bb530ed9e1
commit
fd9a3fc5e7
@ -153,7 +153,7 @@ class Application(QApplication):
|
|||||||
download_manager = downloads.DownloadManager(self)
|
download_manager = downloads.DownloadManager(self)
|
||||||
objreg.register('download-manager', download_manager)
|
objreg.register('download-manager', download_manager)
|
||||||
log.init.debug("Initializing main window...")
|
log.init.debug("Initializing main window...")
|
||||||
mainwindow.create_window(False if self._args.nowindow else True)
|
mainwindow.MainWindow.spawn(False if self._args.nowindow else True)
|
||||||
log.init.debug("Initializing debug console...")
|
log.init.debug("Initializing debug console...")
|
||||||
debug_console = console.ConsoleWidget()
|
debug_console = console.ConsoleWidget()
|
||||||
objreg.register('debug-console', debug_console)
|
objreg.register('debug-console', debug_console)
|
||||||
@ -227,7 +227,7 @@ class Application(QApplication):
|
|||||||
commandrunner.run_safely_init(cmd.lstrip(':'))
|
commandrunner.run_safely_init(cmd.lstrip(':'))
|
||||||
elif not cmd:
|
elif not cmd:
|
||||||
log.init.debug("Empty argument")
|
log.init.debug("Empty argument")
|
||||||
win_id = mainwindow.create_window(True)
|
win_id = mainwindow.MainWindow.spawn()
|
||||||
else:
|
else:
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
|
@ -70,9 +70,9 @@ class CommandDispatcher:
|
|||||||
window: If True, open a new window.
|
window: If True, open a new window.
|
||||||
"""
|
"""
|
||||||
if window:
|
if window:
|
||||||
# We have to import this here to avoid a circular import.
|
main_window = objreg.get('main-window', scope='window',
|
||||||
from qutebrowser.widgets import mainwindow
|
window=self._win_id)
|
||||||
win_id = mainwindow.create_window(True)
|
win_id = main_window.spawn()
|
||||||
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)
|
||||||
|
@ -527,9 +527,9 @@ 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:
|
||||||
# We have to import this here to avoid a circular import.
|
main_window = objreg.get('main-window', scope='window',
|
||||||
from qutebrowser.widgets import mainwindow
|
window=self._win_id)
|
||||||
win_id = mainwindow.create_window(True)
|
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=win_id)
|
||||||
tabbed_browser.tabopen(url, background=False)
|
tabbed_browser.tabopen(url, background=False)
|
||||||
|
@ -310,9 +310,9 @@ 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:
|
||||||
# We have to import this here to avoid a circular import.
|
main_window = objreg.get('main-window', scope='window',
|
||||||
from qutebrowser.widgets import mainwindow
|
window=self._win_id)
|
||||||
win_id = mainwindow.create_window(True)
|
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=win_id)
|
||||||
tabbed_browser.tabopen(url, False)
|
tabbed_browser.tabopen(url, False)
|
||||||
|
@ -39,22 +39,6 @@ from qutebrowser.browser import hints
|
|||||||
win_id_gen = itertools.count(0)
|
win_id_gen = itertools.count(0)
|
||||||
|
|
||||||
|
|
||||||
def create_window(show):
|
|
||||||
"""Create a new main window.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
show: Show the window after creating.
|
|
||||||
|
|
||||||
Return:
|
|
||||||
The new window id.
|
|
||||||
"""
|
|
||||||
win_id = next(win_id_gen)
|
|
||||||
win = MainWindow(win_id)
|
|
||||||
if show:
|
|
||||||
win.show()
|
|
||||||
return win_id
|
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QWidget):
|
class MainWindow(QWidget):
|
||||||
|
|
||||||
"""The main window of qutebrowser.
|
"""The main window of qutebrowser.
|
||||||
@ -145,6 +129,22 @@ class MainWindow(QWidget):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return utils.get_repr(self)
|
return utils.get_repr(self)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def spawn(cls, show=True):
|
||||||
|
"""Create a new main window.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
show: Show the window after creating.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
The new window id.
|
||||||
|
"""
|
||||||
|
win_id = next(win_id_gen)
|
||||||
|
win = MainWindow(win_id)
|
||||||
|
if show:
|
||||||
|
win.show()
|
||||||
|
return win_id
|
||||||
|
|
||||||
def _load_geometry(self):
|
def _load_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')
|
||||||
|
Loading…
Reference in New Issue
Block a user