Example #1
0
    def add_tab(self, url=None, scripting=False):
        """ Creates a new tab, either empty or navegating to the url.
        Sets itself as the active tab.

        If navegating to an url it gives focus to the webkit area. Otherwise,
        the address bar is focused.

        """
        tab = WebTab(parent=self.tab_widget)

        self.tab_widget.addTab(tab, tab.current['title'])

        self.tab_widget.setCurrentWidget(tab)
        tab_idx = self.tab_widget.indexOf(tab)

        self.tab_widget.tabBar().tabButton(tab_idx, 1).hide()  # 1: right align

        if scripting:
            tab.toggle_script()

        if url is not None:
            qurl = fix_url(url)
            tab.webkit.navigate(qurl)
        else:
            tab.address_bar.setFocus()
Example #2
0
    def add_tab(self, url=None, scripting=False):
        """ Creates a new tab, either empty or navegating to the url.
        Sets itself as the active tab.

        If navegating to an url it gives focus to the webkit area. Otherwise,
        the address bar is focused.

        """
        tab = WebTab(parent=self.tab_widget)

        self.tab_widget.addTab(tab, tab.current['title'])

        self.tab_widget.setCurrentWidget(tab)
        tab_idx = self.tab_widget.indexOf(tab)

        self.tab_widget.tabBar().tabButton(tab_idx, 1).hide()  # 1: right align

        if scripting:
            tab.toggle_script()

        if url is not None:
            qurl = fix_url(url)
            tab.webkit.navigate(qurl)
        else:
            tab.address_bar.setFocus()
Example #3
0
    def navigate(self, request=None):
        """ Open the url on this tab. If 'url' is already a QUrl
        (if it comes from a href click), just send it. Otherwise,
        it comes either from the address bar or the PRIMARY
        clipboard through a keyboard shortcut.
        Check if the "url" is actually one, partial or otherwise;
        if it's not, construct a web search.

        BRW01

        """

        if isinstance(request, QUrl):
            qurl = request

        # 'navigate' was connected to a QLineEdit to extract its text
        elif isinstance(request, QLineEdit):
            url = request.text()
            qurl = fix_url(url)  # BRW11
        else:
            raise RuntimeError("Navigating to non-navigable")

        # if the qurl does not trigger an URL in SHORTENERS or REDIRECTORS,
        # this will be a no-op
        qurl = do_redirect(qurl)  # BRW12

        if self.attr.prefix is None:
            # this is the first navigation on this tab/webkit; replace
            # the Network Access Manager CFG02

            instance = extract_instance(qurl.toString())
            self.attr.set_prefix(get_options()['sites'][instance]['prefix'])

            if self.attr.prefix is None:
                raise RuntimeError(
                    "prefix failed to be set... 'options' is broken")

            # strictly speaking, this should emit from Attributes.set_prefix
            self.set_prefix.emit(self.attr.prefix)
            if self.attr.prefix == "":
                print("GENERAL")
            else:
                print("INSTANCE: {}".format(self.attr.prefix))

            if not has_manager(self.attr.prefix):
                register_manager(self.attr.prefix,
                                 InterceptNAM(instance,
                                              parent=None))

            if not has_manager(self.attr.prefix):
                raise RuntimeError("prefix manager not registered...")

            self.page().setNetworkAccessManager(get_manager(self.attr.prefix))

        print("{}>>>\t\t{}\n>>> NAVIGATE {}{}".format(
            Fore.CYAN,
            datetime.datetime.now().isoformat(),
            qurl.toString(),
            Fore.RESET))

        self.setFocus()
        self.load_requested.emit(qurl.toString())
        self.load(qurl)