Ejemplo n.º 1
0
     def OnOpeningURL(self, typ, url):
         if url.startswith("file:"):
             if self._RE_RIGHT_FILE_URL.match(url):
                 return wx.html.HTML_OPEN
             # At least under Windows, wxWidgets has another
             # opinion how a local file URL should look like
             # than Python.
             # The same processing is done already by the exporter
             # for WikidPad URL but not for URLs in HTML tags. 
             p = pathnameFromUrl(url)
             url = wx.FileSystem.FileNameToURL(p)
             return url
 
         return wx.html.HTML_OPEN
Ejemplo n.º 2
0
    def BeforeNavigate2(self, this, pDisp, URL, Flags, TargetFrameName,
                        PostData, Headers, Cancel):
                            
        Cancel[0] = False
        if self.passNavigate:
            self.passNavigate -= 1
            return
            
        if (not (Flags[0] and iewin.NAV_Hyperlink)) and \
                self.presenter.getConfig().getboolean("main",
                "html_preview_ieShowIframes", False):
            return

        href = URL[0]


        if self.drivingMoz:
            internaljumpPrefix = u"file://internaljump/"
        else:
            internaljumpPrefix = u"http://internaljump/"
            
        if href.startswith(internaljumpPrefix + u"wikipage/"):

            if self.drivingMoz:
                # Unlike stated, the Mozilla ActiveX control has some
                # differences to the IE control. For instance, it returns
                # here an UTF-8 URL-quoted string, while IE returns the
                # unicode as it is.
                href = utf8Dec(urllib.unquote(href.encode("ascii", "replace")))[0]

            Cancel[0] = True
            # Jump to another wiki page

            # First check for an anchor. In URLs, anchors are always
            # separated by '#' regardless which character is used
            # in the wiki syntax (normally '!')
            try:
                word, anchor = href[len(internaljumpPrefix) + 9:].split("#", 1)
            except ValueError:
                word = href[len(internaljumpPrefix) + 9:]
                anchor = None
            
            # unescape word
            word = urllib.unquote(word) # utf8Dec(urllib.unquote(word))[0]
            if anchor:
                anchor = urllib.unquote(anchor)  # utf8Dec(urllib.unquote(anchor))[0]

            # Now open wiki
            self.presenter.getMainControl().openWikiPage(
                    word, motionType="child", anchor=anchor)

#         elif href.startswith(internaljumpPrefix + u"action/scroll/selfanchor/"):
#             anchorFragment = href[len(internaljumpPrefix + u"action/scroll/selfanchor/"):]
#             self.gotoAnchor(anchorFragment)
#             evt.Cancel = True

        elif href == (internaljumpPrefix + u"action/history/back"):
            # Go back in history
            self.presenter.getMainControl().goBrowserBack()
            Cancel[0] = True

        elif href == (internaljumpPrefix + u"mouse/leftdoubleclick/preview/body"):
            pres = self.presenter
            mc = pres.getMainControl()

            paramDict = {"page": pres.getDocPage(), "presenter": pres,
                    "main control": mc}

            mc.getUserActionCoord().reactOnUserEvent(
                    u"mouse/leftdoubleclick/preview/body", paramDict)
            Cancel[0] = True

        elif href.startswith(u"file:"):
            hrefSplit = href.split("#", 1)
            hrefNoFragment = hrefSplit[0]
            normedPath = os.path.normcase(getLongPath(pathnameFromUrl(hrefNoFragment)))
            if len(hrefSplit) == 2 and normedPath in self.normHtpaths:
                self.gotoAnchor(hrefSplit[1])
                Cancel[0] = True
            else:
                self.presenter.getMainControl().launchUrl(href)
                Cancel[0] = True
        else:
            self.presenter.getMainControl().launchUrl(href)
            Cancel[0] = True
Ejemplo n.º 3
0
    def BeforeNavigate2(self, this, pDisp, URL, Flags, TargetFrameName,
                        PostData, Headers, Cancel):

        Cancel[0] = False
        if self.passNavigate:
            self.passNavigate -= 1
            return

        if (not (Flags[0] and iewin.NAV_Hyperlink)) and \
                self.presenter.getConfig().getboolean("main",
                "html_preview_ieShowIframes", False):
            return

        href = URL[0]

        if self.drivingMoz:
            internaljumpPrefix = u"file://internaljump/"
        else:
            internaljumpPrefix = u"http://internaljump/"

        if href.startswith(internaljumpPrefix + u"wikipage/"):

            if self.drivingMoz:
                # Unlike stated, the Mozilla ActiveX control has some
                # differences to the IE control. For instance, it returns
                # here an UTF-8 URL-quoted string, while IE returns the
                # unicode as it is.
                href = utf8Dec(urllib.unquote(href.encode("ascii",
                                                          "replace")))[0]

            Cancel[0] = True
            # Jump to another wiki page

            # First check for an anchor. In URLs, anchors are always
            # separated by '#' regardless which character is used
            # in the wiki syntax (normally '!')
            try:
                word, anchor = href[len(internaljumpPrefix) + 9:].split("#", 1)
            except ValueError:
                word = href[len(internaljumpPrefix) + 9:]
                anchor = None

            # unescape word
            word = urllib.unquote(word)  # utf8Dec(urllib.unquote(word))[0]
            if anchor:
                anchor = urllib.unquote(
                    anchor)  # utf8Dec(urllib.unquote(anchor))[0]

            # Now open wiki
            self.presenter.getMainControl().openWikiPage(word,
                                                         motionType="child",
                                                         anchor=anchor)

#         elif href.startswith(internaljumpPrefix + u"action/scroll/selfanchor/"):
#             anchorFragment = href[len(internaljumpPrefix + u"action/scroll/selfanchor/"):]
#             self.gotoAnchor(anchorFragment)
#             evt.Cancel = True

        elif href == (internaljumpPrefix + u"action/history/back"):
            # Go back in history
            self.presenter.getMainControl().goBrowserBack()
            Cancel[0] = True

        elif href == (internaljumpPrefix +
                      u"mouse/leftdoubleclick/preview/body"):
            pres = self.presenter
            mc = pres.getMainControl()

            paramDict = {
                "page": pres.getDocPage(),
                "presenter": pres,
                "main control": mc
            }

            mc.getUserActionCoord().reactOnUserEvent(
                u"mouse/leftdoubleclick/preview/body", paramDict)
            Cancel[0] = True

        elif href.startswith(u"file:"):
            hrefSplit = href.split("#", 1)
            hrefNoFragment = hrefSplit[0]
            normedPath = os.path.normcase(
                getLongPath(pathnameFromUrl(hrefNoFragment)))
            if len(hrefSplit) == 2 and normedPath in self.normHtpaths:
                self.gotoAnchor(hrefSplit[1])
                Cancel[0] = True
            else:
                self.presenter.getMainControl().launchUrl(href)
                Cancel[0] = True
        else:
            self.presenter.getMainControl().launchUrl(href)
            Cancel[0] = True