OK, here they are.

Here's an example of how they can be used. You have a node and you want to 
have some images that you can display with, say, VR3.  You want to put them 
into an *images* subdir, but you have to navigate there first.  How can you 
do that?  With the *show-current-dir* button you just click it and the 
system's file manager/Windows Explorer window opens on that directory. Now 
you can copy those image files to the *images* subdirectory.

On Wednesday, November 22, 2023 at 11:38:36 AM UTC-5 Edward K. Ream wrote:

> On Wed, Nov 22, 2023 at 9:57 AM Thomas Passin <[email protected]> wrote:
>
> >> Would you like to contribute these scripts to Leo?
>
> > Certainly.  I use them a lot. 
>
> > Where should they go in the Leo code base? 
>
> Please send them to me in a small .leo file. I'll figure it out :-)
>
> Edward
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/42fb9242-808c-4e9a-b6e0-2bbd9434809en%40googlegroups.com.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo: https://leo-editor.github.io/leo-editor/leo_toc.html -->
<leo_file xmlns:leo="https://leo-editor.github.io/leo-editor/namespaces/leo-python-editor/1.1"; >
<leo_header file_format="2"/>
<globals/>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="tom.20231122124043.2"><vh>Tom Passin's Current Directory Buttons</vh>
<v t="tom.20231122124124.1"><vh>@button Show Current Dir</vh></v>
<v t="tom.20231122124135.1"><vh>@button Cmd Window Here</vh></v>
<v t="tom.20231122124205.1"><vh>@button Node Dir to Clip</vh></v>
</v>
</vnodes>
<tnodes>
<t tx="tom.20231122124043.2"></t>
<t tx="tom.20231122124124.1">@language python
"""Open directory for a node, respecting any @path directives and "~"."""

from pathlib import Path
from subprocess import run

pth = Path(c.fullPath(p))
if pth.exists():
    if pth.is_file():
        direc = pth.parent
    else:
        direc = pth
else:
    direc = Path(g.scanAllAtPathDirectives(c, p))

if direc:
    normdir = str(direc.resolve())
    term = 'explorer.exe' if g.isWindows else 'xdg-open'
    run([term, direc])

else:
    g.es(f"Path {direc} doesn't exist", color='red')
</t>
<t tx="tom.20231122124135.1">@language python
"""Open command window at current directory. Expands "~"."""

from pathlib import Path
from subprocess import run

pth = Path(c.fullPath(p))
if pth.exists():
    if pth.is_file():
        direc = pth.parent
    else:
        direc = pth
else:
    direc = Path(g.scanAllAtPathDirectives(c, p))

if direc:
    normdir = str(direc.resolve())
    if g.isWindows:
        cmd = f'start cmd.exe /K "cd {direc}"'
        run(cmd, shell=True)
    else:
        cmd = 'x-terminal-emulator'
        run(cmd, cwd=direc)
else:
    g.es(f"Path {direc} doesn't exist", color='red')</t>
<t tx="tom.20231122124205.1">@language python
"""Copy the effective path of the current node to the clipboard.

This command honors @path directives.
"""
from pathlib import Path

pth = Path(c.fullPath(p))
if pth.exists():
    if pth.is_file():
        direc = pth.parent
    else:
        direc = pth
else:
    direc = Path(g.scanAllAtPathDirectives(c, p))

if direc:
    normdir = str(direc.resolve())
    g.app.gui.replaceClipboardWith(normdir)
else:
    g.es(f"Path {direc} doesn't exist")

</t>
</tnodes>
</leo_file>

Reply via email to