コード例 #1
0
ファイル: WikiHtmlViewIE.py プロジェクト: gbdu/wikidpad
    def __init__(self, presenter, parent, ID, drivingMoz):
        self.drivingMoz = drivingMoz

        if self.drivingMoz:
#             wx.activex.IEHtmlWindowBase.__init__(self, parent,    # wx.activex.CLSID(
            wx.lib.activex.ActiveXCtrl.__init__(self, parent,
                '{1339B54C-3453-11D2-93B9-000000000000}',
                ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0,
                name='MozHtmlWindow')
            self.LinkConverterForPreview = LinkConverterForPreviewMoz
        else:
#             wx.activex.IEHtmlWindowBase.__init__(self, parent,
            wx.lib.activex.ActiveXCtrl.__init__(self, parent,
#                 '{8856F961-340A-11D0-A96B-00C04FD705A2}',
                'Shell.Explorer.2', 
                ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0,
                name='IEHtmlWindow')
            self.LinkConverterForPreview = LinkConverterForPreviewIe


        self._canGoBack = False
        self._canGoForward = False


        self.presenter = presenter

        self.presenterListener = wxKeyFunctionSink((
                ("loaded current wiki page", self.onLoadedCurrentWikiPage),
                ("reloaded current doc page", self.onReloadedCurrentPage),
                ("opened wiki", self.onOpenedWiki),
                ("closing current wiki", self.onClosingCurrentWiki)
#                 ("options changed", self.onOptionsChanged),
        ), self.presenter.getMiscEvent())

        self.__sinkApp = wxKeyFunctionSink((
                ("options changed", self.onOptionsChanged),
        ), wx.GetApp().getMiscEvent())

        self.__sinkDocPage = wxKeyFunctionSink((
                ("updated wiki page", self.onUpdatedWikiPage),
                ("changed live text", self.onChangedLiveText)
        ), self.presenter.getCurrentDocPageProxyEvent())

        self.visible = False
        self.outOfSync = True   # HTML content is out of sync with live content
        self.deferredScrollPos = None  # Used by scrollDeferred()

        self.currentLoadedWikiWord = None
        self.currentLoadedUrl = None  # Contains the URL of the temporary HTML
                # file without anchors

        self.anchor = None  # Name of anchor to jump to when view gets visible
        self.lastAnchor = None
        self.passNavigate = 0


        # TODO Should be changed to presenter as controller
        self.exporterInstance = PluginManager.getExporterTypeDict(
                self.presenter.getMainControl(), False)[u"html_single"][0]\
                (self.presenter.getMainControl())

        # TODO More elegantly
        if self.drivingMoz:
            self.exporterInstance.exportType = u"html_previewMOZ"
        else:
            self.exporterInstance.exportType = u"html_previewIE"

        self.exporterInstance.tempFileSet = TempFileSet()
        self._updateTempFilePrefPath()

        self.exporterInstance.setWikiDocument(
                self.presenter.getWikiDocument())
        self.exporterInstance.setLinkConverter(
                self.LinkConverterForPreview(self.presenter.getWikiDocument()))

        # Create two temporary html files (IE 7 needs two to work)
        self.htpaths = [None, None]
        self.htpaths[0] = self.exporterInstance.tempFileSet.createTempFile(
                    u"", ".html", relativeTo="").decode("latin-1")
        self.htpaths[1] = self.exporterInstance.tempFileSet.createTempFile(
                    u"", ".html", relativeTo="").decode("latin-1")

        self.normHtpaths = [os.path.normcase(getLongPath(self.htpaths[0])),
                os.path.normcase(getLongPath(self.htpaths[1]))]
                
        self.currentHtpath = 0 # index into self.htpaths

#         iewin.EVT_BeforeNavigate2(self, self.GetId(), self.OnBeforeNavigate)

        wx.EVT_SET_FOCUS(self, self.OnSetFocus)
コード例 #2
0
    def __init__(self, presenter, parent, ID, drivingMoz):
        self.drivingMoz = drivingMoz

        if self.drivingMoz:
            #             wx.activex.IEHtmlWindowBase.__init__(self, parent,    # wx.activex.CLSID(
            wx.lib.activex.ActiveXCtrl.__init__(
                self,
                parent,
                '{1339B54C-3453-11D2-93B9-000000000000}',
                ID,
                pos=wx.DefaultPosition,
                size=wx.DefaultSize,
                style=0,
                name='MozHtmlWindow')
            self.LinkConverterForPreview = LinkConverterForPreviewMoz
        else:
            #             wx.activex.IEHtmlWindowBase.__init__(self, parent,
            wx.lib.activex.ActiveXCtrl.__init__(
                self,
                parent,
                #                 '{8856F961-340A-11D0-A96B-00C04FD705A2}',
                'Shell.Explorer.2',
                ID,
                pos=wx.DefaultPosition,
                size=wx.DefaultSize,
                style=0,
                name='IEHtmlWindow')
            self.LinkConverterForPreview = LinkConverterForPreviewIe

        self._canGoBack = False
        self._canGoForward = False

        self.presenter = presenter

        self.presenterListener = wxKeyFunctionSink(
            (("loaded current wiki page", self.onLoadedCurrentWikiPage),
             ("reloaded current doc page", self.onReloadedCurrentPage),
             ("opened wiki", self.onOpenedWiki),
             ("closing current wiki", self.onClosingCurrentWiki)
             #                 ("options changed", self.onOptionsChanged),
             ),
            self.presenter.getMiscEvent())

        self.__sinkApp = wxKeyFunctionSink(
            (("options changed", self.onOptionsChanged), ),
            wx.GetApp().getMiscEvent())

        self.__sinkDocPage = wxKeyFunctionSink(
            (("updated wiki page", self.onUpdatedWikiPage),
             ("changed live text", self.onChangedLiveText)),
            self.presenter.getCurrentDocPageProxyEvent())

        self.visible = False
        self.outOfSync = True  # HTML content is out of sync with live content
        self.deferredScrollPos = None  # Used by scrollDeferred()

        self.currentLoadedWikiWord = None
        self.currentLoadedUrl = None  # Contains the URL of the temporary HTML
        # file without anchors

        self.anchor = None  # Name of anchor to jump to when view gets visible
        self.lastAnchor = None
        self.passNavigate = 0

        # TODO Should be changed to presenter as controller
        self.exporterInstance = PluginManager.getExporterTypeDict(
                self.presenter.getMainControl(), False)[u"html_single"][0]\
                (self.presenter.getMainControl())

        # TODO More elegantly
        if self.drivingMoz:
            self.exporterInstance.exportType = u"html_previewMOZ"
        else:
            self.exporterInstance.exportType = u"html_previewIE"

        self.exporterInstance.tempFileSet = TempFileSet()
        self._updateTempFilePrefPath()

        self.exporterInstance.setWikiDocument(self.presenter.getWikiDocument())
        self.exporterInstance.setLinkConverter(
            self.LinkConverterForPreview(self.presenter.getWikiDocument()))

        # Create two temporary html files (IE 7 needs two to work)
        self.htpaths = [None, None]
        self.htpaths[0] = self.exporterInstance.tempFileSet.createTempFile(
            u"", ".html", relativeTo="").decode("latin-1")
        self.htpaths[1] = self.exporterInstance.tempFileSet.createTempFile(
            u"", ".html", relativeTo="").decode("latin-1")

        self.normHtpaths = [
            os.path.normcase(getLongPath(self.htpaths[0])),
            os.path.normcase(getLongPath(self.htpaths[1]))
        ]

        self.currentHtpath = 0  # index into self.htpaths

        #         iewin.EVT_BeforeNavigate2(self, self.GetId(), self.OnBeforeNavigate)

        wx.EVT_SET_FOCUS(self, self.OnSetFocus)
コード例 #3
0
ファイル: WikiHtmlViewIE.py プロジェクト: gbdu/wikidpad
    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
コード例 #4
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