Beispiel #1
0
    def get_fn (self,s,tag):
        
        pc = self
        c = pc.c
        fn = s or c.p.h[len(tag):]
        fn = fn.strip()
        
        # Similar to code in g.computeFileUrl
        if fn.startswith('~'):
            # Expand '~' and handle Leo expressions.
            fn = fn[1:]
            fn = g.os_path_expanduser(fn)
            fn = g.os_path_expandExpression(fn,c=c)
            fn = g.os_path_finalize(fn)
        else:
            # Handle Leo expressions.
            fn = g.os_path_expandExpression(fn,c=c)
            # Handle ancestor @path directives.
            if c and c.openDirectory:
                base = c.getNodePath(c.p)
                fn = g.os_path_finalize_join(c.openDirectory,base,fn)
            else:
                fn = g.os_path_finalize(fn)

        ok = g.os_path_exists(fn)
        return ok,fn
Beispiel #2
0
    def get_fn (self,s,tag):
        
        pc = self
        c = pc.c
        fn = s or c.p.h[len(tag):]
        fn = fn.strip()
        
        # Similar to code in g.computeFileUrl
        if fn.startswith('~'):
            # Expand '~' and handle Leo expressions.
            fn = fn[1:]
            fn = g.os_path_expanduser(fn)
            fn = g.os_path_expandExpression(fn,c=c)
            fn = g.os_path_finalize(fn)
        else:
            # Handle Leo expressions.
            fn = g.os_path_expandExpression(fn,c=c)
            # Handle ancestor @path directives.
            if c and c.openDirectory:
                base = c.getNodePath(c.p)
                fn = g.os_path_finalize_join(c.openDirectory,base,fn)
            else:
                fn = g.os_path_finalize(fn)

        ok = g.os_path_exists(fn)
        return ok,fn
Beispiel #3
0
def onUrl1 (tag,keywords):
    """Redefine the @url functionality of Leo Core: allows jumping to URL _and UNLs_.
    Spaces are now allowed in URLs."""
    trace = False and not g.unitTesting
    c = keywords.get("c")
    p = keywords.get("p")
    v = keywords.get("v")
    # The url key is new in 4.3 beta 2.
    # The url ends with the first blank, unless either single or double quotes are used.
    url = keywords.get('url') or ''
    url = url.replace('%20',' ')

#@+at Most browsers should handle the following urls:
#   ftp://ftp.uu.net/public/whatever.
#   http://localhost/MySiteUnderDevelopment/index.html
#   file://home/me/todolist.html
#@@c
    try:
        try:
            urlTuple = urlparse.urlsplit(url)
            if trace: logUrl(urlTuple)
        except:
            g.es("exception interpreting the url " + url)
            g.es_exception()
            return False

        if not urlTuple[0]:
            urlProtocol = "file" # assume this protocol by default
        else:
            urlProtocol = urlTuple[0]

        if urlProtocol == "file":
            if urlTuple[2].endswith(".leo"):
                if hasattr(c.frame.top, 'update_idletasks'):
                    # this is Tk only - TNB
                    c.frame.top.update_idletasks()
                        # Clear remaining events, so they don't interfere.
                filename = os.path.expanduser(urlTuple[2])
                filename = g.os_path_expandExpression(filename,c=c)
                    # 2011/01/25: bogomil
    
                if not os.path.isabs(filename):
                    filename = os.path.normpath(os.path.join(c.getNodePath(p),filename))

                ok,frame = g.openWithFileName(filename, c)
                if ok:
                    #@+<< go to the node>>
                    #@+node:ekr.20110602070710.3433: *3* <<go to the node>>
                    c2 = frame.c

                    if urlTuple [4]: # we have a UNL!
                        recursiveUNLSearch(urlTuple[4].split("-->"), c2)

                    # Disable later call to c.onClick so the focus stays in c2.
                    c.doubleClickFlag = True
                    #@-<< go to the node>>
            elif urlTuple[0] == "":
                #@+<< go to node in present outline >>
                #@+node:ekr.20110602070710.3434: *3* << go to node in present outline >>
                if urlTuple [2]:
                    recursiveUNLSearch(urlTuple[2].split("-->"), c)
                #@-<< go to node in present outline >>
            else:
                #@+<<invoke external browser>>
                #@+node:ekr.20110602070710.3435: *3* <<invoke external browser>>
                import webbrowser

                # Mozilla throws a weird exception, then opens the file!
                try:
                    webbrowser.open(url)
                except:
                    pass
                #@-<<invoke external browser>>
        else:
            #@+<<invoke external browser>>
            #@+node:ekr.20110602070710.3435: *3* <<invoke external browser>>
            import webbrowser

            # Mozilla throws a weird exception, then opens the file!
            try:
                webbrowser.open(url)
            except:
                pass
            #@-<<invoke external browser>>
        return True
            # PREVENTS THE EXECUTION OF LEO'S CORE CODE IN
            # Code-->Gui Base classes-->@thin leoFrame.py-->class leoTree-->tree.OnIconDoubleClick (@url)
    except:
        g.es("exception opening " + url)
        g.es_exception()
        return False
Beispiel #4
0
def onUrl1(tag, keywords):
    """Redefine the @url functionality of Leo Core: allows jumping to URL _and UNLs_.
    Spaces are now allowed in URLs."""
    trace = False and not g.unitTesting
    c = keywords.get("c")
    p = keywords.get("p")
    v = keywords.get("v")
    # The url key is new in 4.3 beta 2.
    # The url ends with the first blank, unless either single or double quotes are used.
    url = keywords.get('url') or ''
    url = url.replace('%20', ' ')

    #@+at Most browsers should handle the following urls:
    #   ftp://ftp.uu.net/public/whatever.
    #   http://localhost/MySiteUnderDevelopment/index.html
    #   file://home/me/todolist.html
    #@@c
    try:
        try:
            urlTuple = urlparse.urlsplit(url)
            if trace: logUrl(urlTuple)
        except:
            g.es("exception interpreting the url " + url)
            g.es_exception()
            return False

        if not urlTuple[0]:
            urlProtocol = "file"  # assume this protocol by default
        else:
            urlProtocol = urlTuple[0]

        if urlProtocol == "file":
            if urlTuple[2].endswith(".leo"):
                if hasattr(c.frame.top, 'update_idletasks'):
                    # this is Tk only - TNB
                    c.frame.top.update_idletasks()
                    # Clear remaining events, so they don't interfere.
                filename = os.path.expanduser(urlTuple[2])
                filename = g.os_path_expandExpression(filename, c=c)
                # 2011/01/25: bogomil

                if not os.path.isabs(filename):
                    filename = os.path.normpath(
                        os.path.join(c.getNodePath(p), filename))

                ok, frame = g.openWithFileName(filename, c)
                if ok:
                    #@+<< go to the node>>
                    #@+node:ekr.20110602070710.3433: *3* <<go to the node>>
                    c2 = frame.c

                    if urlTuple[4]:  # we have a UNL!
                        recursiveUNLSearch(urlTuple[4].split("-->"), c2)

                    # Disable later call to c.onClick so the focus stays in c2.
                    c.doubleClickFlag = True
                    #@-<< go to the node>>
            elif urlTuple[0] == "":
                #@+<< go to node in present outline >>
                #@+node:ekr.20110602070710.3434: *3* << go to node in present outline >>
                if urlTuple[2]:
                    recursiveUNLSearch(urlTuple[2].split("-->"), c)
                #@-<< go to node in present outline >>
            else:
                #@+<<invoke external browser>>
                #@+node:ekr.20110602070710.3435: *3* <<invoke external browser>>
                import webbrowser

                # Mozilla throws a weird exception, then opens the file!
                try:
                    webbrowser.open(url)
                except:
                    pass
                #@-<<invoke external browser>>
        else:
            #@+<<invoke external browser>>
            #@+node:ekr.20110602070710.3435: *3* <<invoke external browser>>
            import webbrowser

            # Mozilla throws a weird exception, then opens the file!
            try:
                webbrowser.open(url)
            except:
                pass
            #@-<<invoke external browser>>
        return True
        # PREVENTS THE EXECUTION OF LEO'S CORE CODE IN
        # Code-->Gui Base classes-->@thin leoFrame.py-->class leoTree-->tree.OnIconDoubleClick (@url)
    except:
        g.es("exception opening " + url)
        g.es_exception()
        return False