Beispiel #1
0
def getFilesFromClipboard():
    """
    Retrieve bitmap from clipboard if available
    """
    from StringOps import utf8Dec
    cb = wx.TheClipboard
    cb.Open()
    try:
        dataob = wx.FileDataObject()

        if cb.GetData(dataob):
            filenames = dataob.GetFilenames()
            if filenames:
                if SystemInfo.isLinux():
                    # On Linux, at least Ubuntu, fn may be a UTF-8 encoded unicode(!?)
                    # string
                    try:
                        filenames = [utf8Dec(fn.encode("latin-1"))[0]
                                for fn in filenames]
                    except (UnicodeEncodeError, UnicodeDecodeError):
                        pass

                return filenames
            else:
                return None
        return None
    finally:
        cb.Close()
Beispiel #2
0
    def get(self, section, option, default=None):
        """
        Return a configuration value returned as string/unicode which
        is entered in given section and has specified option key.
        """
        if type(section) is unicode:
            section = utf8Enc(section)[0]

        if type(option) is unicode:
            option = utf8Enc(option)[0]

        result = None

        if self.isOptionAllowed(section, option):
            if self.configParserObject.has_option(section, option):
                result = self.configParserObject.get(section, option)
            else:
                result = self.configDefaults[(section, option)]
        else:
            raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)

        if result is None:
            return default

        try:
            result = utf8Dec(result)[0]
        except UnicodeError:
            # Result is not Utf-8 -> try mbcs
            try:
                result = mbcsDec(result)[0]
            except UnicodeError:
                # Result can't be converted
                result = default

        return result
Beispiel #3
0
def getFilesFromClipboard():
    """
    Retrieve bitmap from clipboard if available
    """
    from StringOps import utf8Dec
    cb = wx.TheClipboard
    cb.Open()
    try:
        dataob = wx.FileDataObject()

        if cb.GetData(dataob):
            filenames = dataob.GetFilenames()
            if filenames:
                if SystemInfo.isLinux():
                    # On Linux, at least Ubuntu, fn may be a UTF-8 encoded unicode(!?)
                    # string
                    try:
                        filenames = [
                            utf8Dec(fn.encode("latin-1"))[0]
                            for fn in filenames
                        ]
                    except (UnicodeEncodeError, UnicodeDecodeError):
                        pass

                return filenames
            else:
                return None
        return None
    finally:
        cb.Close()
Beispiel #4
0
    def get(self, section, option, default=None):
        """
        Return a configuration value returned as string/unicode which
        is entered in given section and has specified option key.
        """
        if type(section) is unicode:
            section = utf8Enc(section)[0]

        if type(option) is unicode:
            option = utf8Enc(option)[0]
            
        result = None

        if self.isOptionAllowed(section, option):
            if self.configParserObject.has_option(section, option):
                result = self.configParserObject.get(section, option)
            else:
                result = self.configDefaults[(section, option)]
        else:
            raise UnknownOptionException, _(u"Unknown option %s:%s") % (section, option)

        if result is None:
            return default

        try:
            result = utf8Dec(result)[0]
        except UnicodeError:
            # Result is not Utf-8 -> try mbcs
            try:
                result = mbcsDec(result)[0]
            except UnicodeError:
                # Result can't be converted
                result = default

        return result
Beispiel #5
0
 def serUniUtf8(self, us):
     """
     Serialize unicode string, encoded as UTF-8
     """
     if self.isReadMode():
         return utf8Dec(self.serString(""), "replace")[0]
     else:
         self.serString(utf8Enc(us)[0])
         return us
Beispiel #6
0
 def serUniUtf8(self, us):
     """
     Serialize unicode string, encoded as UTF-8
     """
     if self.isReadMode():
         return utf8Dec(self.serString(""), "replace")[0]
     else:
         self.serString(utf8Enc(us)[0])
         return us
Beispiel #7
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
Beispiel #8
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