def __init__(self, geometry=None, parent=None):
        """Create a new main window.

        Args:
            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 = next(win_id_gen)
        self.registry = objreg.ObjectRegistry()
        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=self.win_id)

        message_bridge = message.MessageBridge(self)
        objreg.register('message-bridge',
                        message_bridge,
                        scope='window',
                        window=self.win_id)

        self.setWindowTitle('qutebrowser')
        self._vbox = QVBoxLayout(self)
        self._vbox.setContentsMargins(0, 0, 0, 0)
        self._vbox.setSpacing(0)

        log.init.debug("Initializing downloads...")
        download_manager = downloads.DownloadManager(self.win_id, self)
        objreg.register('download-manager',
                        download_manager,
                        scope='window',
                        window=self.win_id)

        self._downloadview = downloadview.DownloadView(self.win_id)

        self.tabbed_browser = tabbedbrowser.TabbedBrowser(self.win_id)
        objreg.register('tabbed-browser',
                        self.tabbed_browser,
                        scope='window',
                        window=self.win_id)
        dispatcher = commands.CommandDispatcher(self.win_id,
                                                self.tabbed_browser)
        objreg.register('command-dispatcher',
                        dispatcher,
                        scope='window',
                        window=self.win_id)
        self.tabbed_browser.destroyed.connect(
            functools.partial(objreg.delete,
                              'command-dispatcher',
                              scope='window',
                              window=self.win_id))

        # 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(self.win_id, parent=self)

        self._add_widgets()
        self._downloadview.show()

        self._completion = completionwidget.CompletionView(self.win_id, self)

        self._commandrunner = runners.CommandRunner(self.win_id)

        log.init.debug("Initializing modes...")
        modeman.init(self.win_id, self)

        if geometry is not None:
            self._load_geometry(geometry)
        elif self.win_id == 0:
            self._load_state_geometry()
        else:
            self._set_default_geometry()
        log.init.debug("Initial main window geometry: {}".format(
            self.geometry()))

        self._connect_signals()

        # When we're here the statusbar might not even really exist yet, so
        # resizing will fail. Therefore, we use singleShot QTimers to make sure
        # we defer this until everything else is initialized.
        QTimer.singleShot(0, self._connect_resize_completion)
        objreg.get('config').changed.connect(self.on_config_changed)

        if config.get('ui', 'hide-mouse-cursor'):
            self.setCursor(Qt.BlankCursor)
Exemple #2
0
    def __init__(self, win_id, parent=None):
        super().__init__(parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self._commandrunner = None
        self.win_id = win_id
        self.registry = objreg.ObjectRegistry()
        objreg.window_registry[win_id] = self
        objreg.register('main-window', self, scope='window', window=win_id)
        tab_registry = objreg.ObjectRegistry()
        objreg.register('tab-registry',
                        tab_registry,
                        scope='window',
                        window=win_id)

        message_bridge = message.MessageBridge(self)
        objreg.register('message-bridge',
                        message_bridge,
                        scope='window',
                        window=win_id)

        self.setWindowTitle('qutebrowser')
        if win_id == 0:
            self._load_geometry()
        else:
            self._set_default_geometry()
        log.init.debug("Initial mainwindow geometry: {}".format(
            self.geometry()))
        self._vbox = QVBoxLayout(self)
        self._vbox.setContentsMargins(0, 0, 0, 0)
        self._vbox.setSpacing(0)

        log.init.debug("Initializing downloads...")
        download_manager = downloads.DownloadManager(win_id, self)
        objreg.register('download-manager',
                        download_manager,
                        scope='window',
                        window=win_id)

        self._downloadview = downloadswidget.DownloadView(win_id)
        self._vbox.addWidget(self._downloadview)
        self._downloadview.show()

        self._tabbed_browser = tabbedbrowser.TabbedBrowser(win_id)
        objreg.register('tabbed-browser',
                        self._tabbed_browser,
                        scope='window',
                        window=win_id)
        self._vbox.addWidget(self._tabbed_browser)

        self.status = bar.StatusBar(win_id)
        self._vbox.addWidget(self.status)

        self._completion = completion.CompletionView(win_id, self)

        self._commandrunner = runners.CommandRunner(win_id)

        log.init.debug("Initializing search...")
        search_runner = runners.SearchRunner(self)
        objreg.register('search-runner',
                        search_runner,
                        scope='window',
                        window=win_id)

        log.init.debug("Initializing modes...")
        modeman.init(self.win_id, self)

        self._connect_signals()
        QTimer.singleShot(
            0,
            functools.partial(modeman.enter, win_id, usertypes.KeyMode.normal,
                              'init'))

        # When we're here the statusbar might not even really exist yet, so
        # resizing will fail. Therefore, we use singleShot QTimers to make sure
        # we defer this until everything else is initialized.
        QTimer.singleShot(0, self._connect_resize_completion)
        objreg.get('config').changed.connect(self.on_config_changed)