Re: A Script To Insert An Image

2024-03-09 Thread Thomas Passin
I seem to remember that somewhere in the code base, Leo code to capture the 
screen has already been worked out.  If that's the case we're in clover.

On Saturday, March 9, 2024 at 3:09:24 PM UTC-5 jkn wrote:

> The way I have been using the Obsidian feature is to paste image bytes 
> (eg. from a screen region capture). So Obsidian saves a file:
>
> /path/to/attachments/ 
>
> Pasted image 20240228230106.png
>
>
> Where /path/to/attachments is an Obsidian setting, and the name of the 
> file is clearly a timestamp.
>
>
> Obsidian only uses markdown, so it inserts 
>
>
> ![[Pasted image 20240228230106.png]]
>
>
> into the 'node being edited'
>
>
> I think you can also drag and drop files into a 'node'.
>
>
> There would clearly have to be some work to make this generally useful in 
> a Leo context...
>
>
>
> On Saturday, March 9, 2024 at 7:35:15 PM UTC tbp1...@gmail.com wrote:
>
>> Shouldn't be hard.  What would be on the clipboard?  Image bytes?  Or an 
>> image filename?  I often select an image in a file manager window, copy it 
>> to an "images" subdirectory of the current outline, then write the 
>> embedding code into and "images" child node.  That would be easy to write a 
>> script for.
>>
>> On Saturday, March 9, 2024 at 2:14:41 PM UTC-5 jkn wrote:
>>
>>> This looks interesting and useful, thanks Thomas. I confess I 
>>> rarely/never use Leo with images, I really should experiment a little.
>>>
>>> Recently I have been using Obsidian as a note-taking app (Joplin is 
>>> similar). Neither are as capable as Leo, in many ways, but they have their 
>>> niceties.
>>> One that is handy when note-taking is the ability to paste *from the 
>>> clipboard*. You can setup an area (directory0 in an Obsidian 'vault' - then 
>>> 'paste from clipboard' will
>>> (a) create a unique filename within the image directory, and put the 
>>> clipboard contents in there as eg. a .png file
>>> (b) add a (markdown) reference to the new image in the 'note' that you 
>>> are in.
>>>
>>> It'd be nice to have something similar in Leo... ;-)
>>>
>>> Regards, Jon N
>>>
>>> On Saturday, March 9, 2024 at 7:04:19 PM UTC tbp1...@gmail.com wrote:
>>>
 We can't directly insert an image into a standard Leo node because they 
 are text-only.  I find this very annoying sometimes, especially when I am 
 writing a note and want to include an image.  

 But we can do the next best thing - insert an ReStructuredText (RsT) 
 instruction to display an image so that we can view it with the 
 viewrendered3 plugin (VR3). The instruction is short and easy, but it's 
 still annoying to type and I usually forget the exact details. I have a 
 button that toggles VR3 on and off so that it's easy to view an embedded 
 image once the RsT instruction is there. An embedding command would make 
 embedding with Leo as easy as embedding an image in a word processor.  
  Aha, this is Leo, let's write a script!

 Here is a script that pops up a file dialog and inserts a relative path 
 to the chosen file.  There are several small variations which I discuss 
 after the code.

 """Insert RsT code at cursor to display an image.

 The path to the image file will come from a file dialog.
 This action is undoable.
 """
 PATH = g.app.gui.runOpenFileDialog(c,
 title="Import File",
 filetypes=[("All files", "*"),],
 defaultextension=".*",
 multiple=False)

 if PATH:
 from os.path import relpath
 PATH = relpath(PATH)
 PATH = PATH.replace('\\', '/').replace('"', '').replace("'", '')
 IMAGE_TEMPLATE = f'''

 .. figure:: {PATH}
 :scale: 50%

 '''
 w = c.frame.body.wrapper
 p = c.p
 s = p.b
 u = c.undoer

 start, _ = w.getSelectionRange()

 undoType = 'insert-rst-image-code'
 undoData = u.beforeChangeNodeContents(p)

 head, tail = s[:start], s[start:]
 p.b = head + IMAGE_TEMPLATE + tail

 c.setChanged()
 p.setDirty()
 u.afterChangeNodeContents(p, undoType, undoData)
 c.redraw()

 Variations:
 1.  If you want an absolute path instead of a relative path, delete the 
 lines
 from os.path import relpath
 PATH = relpath(PATH)
 with

 2. If you  want to get the path from the clipboard instead of a file 
 dialog, replace the lines

 PATH = g.app.gui.runOpenFileDialog(c,
 title="Import File",
 filetypes=[("All files", "*"),],
 defaultextension=".*",
 multiple=False)

 with the line 

 PATH = g.app.gui.getTextFromClipboard()

 3. If you want the embedded image to be full width instead of 50%, 
 delete the line

 :scale: 50%

 4. You can make this work with Markdown or Asciidoc by using their 
 embedding instruction in the TEMPLATE instead of 

A Script To Insert An Image

2024-03-09 Thread Thomas Passin
We can't directly insert an image into a standard Leo node because they are 
text-only.  I find this very annoying sometimes, especially when I am 
writing a note and want to include an image.  

But we can do the next best thing - insert an ReStructuredText (RsT) 
instruction to display an image so that we can view it with the 
viewrendered3 plugin (VR3). The instruction is short and easy, but it's 
still annoying to type and I usually forget the exact details. I have a 
button that toggles VR3 on and off so that it's easy to view an embedded 
image once the RsT instruction is there. An embedding command would make 
embedding with Leo as easy as embedding an image in a word processor.  
 Aha, this is Leo, let's write a script!

Here is a script that pops up a file dialog and inserts a relative path to 
the chosen file.  There are several small variations which I discuss after 
the code.

"""Insert RsT code at cursor to display an image.

The path to the image file will come from a file dialog.
This action is undoable.
"""
PATH = g.app.gui.runOpenFileDialog(c,
title="Import File",
filetypes=[("All files", "*"),],
defaultextension=".*",
multiple=False)

if PATH:
from os.path import relpath
PATH = relpath(PATH)
PATH = PATH.replace('\\', '/').replace('"', '').replace("'", '')
IMAGE_TEMPLATE = f'''

.. figure:: {PATH}
:scale: 50%

'''
w = c.frame.body.wrapper
p = c.p
s = p.b
u = c.undoer

start, _ = w.getSelectionRange()

undoType = 'insert-rst-image-code'
undoData = u.beforeChangeNodeContents(p)

head, tail = s[:start], s[start:]
p.b = head + IMAGE_TEMPLATE + tail

c.setChanged()
p.setDirty()
u.afterChangeNodeContents(p, undoType, undoData)
c.redraw()

Variations:
1.  If you want an absolute path instead of a relative path, delete the 
lines
from os.path import relpath
PATH = relpath(PATH)
with

2. If you  want to get the path from the clipboard instead of a file 
dialog, replace the lines

PATH = g.app.gui.runOpenFileDialog(c,
title="Import File",
filetypes=[("All files", "*"),],
defaultextension=".*",
multiple=False)

with the line 

PATH = g.app.gui.getTextFromClipboard()

3. If you want the embedded image to be full width instead of 50%, delete 
the line

:scale: 50%

4. You can make this work with Markdown or Asciidoc by using their 
embedding instruction in the TEMPLATE instead of the RsT one.

I have added the command to my own local menu.  VR3 can open in a tab in 
the log pane; the command for toggling in a tab is *vr3-toggle-tab. * I 
usually like opening it in the log pane instead of in its own separate pane.

If you would like to create a local menu of your own and don't know how, 
it's easy.  Just ask and I'll show what to add to myLeoSettings,leo.

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/e5055411-b63b-4c0e-b36b-82859c935488n%40googlegroups.com.


Re: A Script To Insert An Image

2024-03-09 Thread jkn
This looks interesting and useful, thanks Thomas. I confess I rarely/never 
use Leo with images, I really should experiment a little.

Recently I have been using Obsidian as a note-taking app (Joplin is 
similar). Neither are as capable as Leo, in many ways, but they have their 
niceties.
One that is handy when note-taking is the ability to paste *from the 
clipboard*. You can setup an area (directory0 in an Obsidian 'vault' - then 
'paste from clipboard' will
(a) create a unique filename within the image directory, and put the 
clipboard contents in there as eg. a .png file
(b) add a (markdown) reference to the new image in the 'note' that you are 
in.

It'd be nice to have something similar in Leo... ;-)

Regards, Jon N

On Saturday, March 9, 2024 at 7:04:19 PM UTC tbp1...@gmail.com wrote:

> We can't directly insert an image into a standard Leo node because they 
> are text-only.  I find this very annoying sometimes, especially when I am 
> writing a note and want to include an image.  
>
> But we can do the next best thing - insert an ReStructuredText (RsT) 
> instruction to display an image so that we can view it with the 
> viewrendered3 plugin (VR3). The instruction is short and easy, but it's 
> still annoying to type and I usually forget the exact details. I have a 
> button that toggles VR3 on and off so that it's easy to view an embedded 
> image once the RsT instruction is there. An embedding command would make 
> embedding with Leo as easy as embedding an image in a word processor.  
>  Aha, this is Leo, let's write a script!
>
> Here is a script that pops up a file dialog and inserts a relative path to 
> the chosen file.  There are several small variations which I discuss after 
> the code.
>
> """Insert RsT code at cursor to display an image.
>
> The path to the image file will come from a file dialog.
> This action is undoable.
> """
> PATH = g.app.gui.runOpenFileDialog(c,
> title="Import File",
> filetypes=[("All files", "*"),],
> defaultextension=".*",
> multiple=False)
>
> if PATH:
> from os.path import relpath
> PATH = relpath(PATH)
> PATH = PATH.replace('\\', '/').replace('"', '').replace("'", '')
> IMAGE_TEMPLATE = f'''
>
> .. figure:: {PATH}
> :scale: 50%
>
> '''
> w = c.frame.body.wrapper
> p = c.p
> s = p.b
> u = c.undoer
>
> start, _ = w.getSelectionRange()
>
> undoType = 'insert-rst-image-code'
> undoData = u.beforeChangeNodeContents(p)
>
> head, tail = s[:start], s[start:]
> p.b = head + IMAGE_TEMPLATE + tail
>
> c.setChanged()
> p.setDirty()
> u.afterChangeNodeContents(p, undoType, undoData)
> c.redraw()
>
> Variations:
> 1.  If you want an absolute path instead of a relative path, delete the 
> lines
> from os.path import relpath
> PATH = relpath(PATH)
> with
>
> 2. If you  want to get the path from the clipboard instead of a file 
> dialog, replace the lines
>
> PATH = g.app.gui.runOpenFileDialog(c,
> title="Import File",
> filetypes=[("All files", "*"),],
> defaultextension=".*",
> multiple=False)
>
> with the line 
>
> PATH = g.app.gui.getTextFromClipboard()
>
> 3. If you want the embedded image to be full width instead of 50%, delete 
> the line
>
> :scale: 50%
>
> 4. You can make this work with Markdown or Asciidoc by using their 
> embedding instruction in the TEMPLATE instead of the RsT one.
>
> I have added the command to my own local menu.  VR3 can open in a tab in 
> the log pane; the command for toggling in a tab is *vr3-toggle-tab. * I 
> usually like opening it in the log pane instead of in its own separate pane.
>
> If you would like to create a local menu of your own and don't know how, 
> it's easy.  Just ask and I'll show what to add to myLeoSettings,leo.
>

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/555b3f5c-24a8-4529-adb4-ebf2d945098cn%40googlegroups.com.


Re: A Script To Insert An Image

2024-03-09 Thread jkn
I would expect that to be somewhat os-dependant (I mostly use Linux), but 
perhaps it is there. I will try to take a look for clipboard-paste 
functions.



On Saturday, March 9, 2024 at 8:22:44 PM UTC tbp1...@gmail.com wrote:

> I seem to remember that somewhere in the code base, Leo code to capture 
> the screen has already been worked out.  If that's the case we're in clover.
>
> On Saturday, March 9, 2024 at 3:09:24 PM UTC-5 jkn wrote:
>
>> The way I have been using the Obsidian feature is to paste image bytes 
>> (eg. from a screen region capture). So Obsidian saves a file:
>>
>> /path/to/attachments/ 
>>
>> Pasted image 20240228230106.png
>>
>>
>> Where /path/to/attachments is an Obsidian setting, and the name of the 
>> file is clearly a timestamp.
>>
>>
>> Obsidian only uses markdown, so it inserts 
>>
>>
>> ![[Pasted image 20240228230106.png]]
>>
>>
>> into the 'node being edited'
>>
>>
>> I think you can also drag and drop files into a 'node'.
>>
>>
>> There would clearly have to be some work to make this generally useful in 
>> a Leo context...
>>
>>
>>
>> On Saturday, March 9, 2024 at 7:35:15 PM UTC tbp1...@gmail.com wrote:
>>
>>> Shouldn't be hard.  What would be on the clipboard?  Image bytes?  Or an 
>>> image filename?  I often select an image in a file manager window, copy it 
>>> to an "images" subdirectory of the current outline, then write the 
>>> embedding code into and "images" child node.  That would be easy to write a 
>>> script for.
>>>
>>> On Saturday, March 9, 2024 at 2:14:41 PM UTC-5 jkn wrote:
>>>
 This looks interesting and useful, thanks Thomas. I confess I 
 rarely/never use Leo with images, I really should experiment a little.

 Recently I have been using Obsidian as a note-taking app (Joplin is 
 similar). Neither are as capable as Leo, in many ways, but they have their 
 niceties.
 One that is handy when note-taking is the ability to paste *from the 
 clipboard*. You can setup an area (directory0 in an Obsidian 'vault' - 
 then 
 'paste from clipboard' will
 (a) create a unique filename within the image directory, and put the 
 clipboard contents in there as eg. a .png file
 (b) add a (markdown) reference to the new image in the 'note' that you 
 are in.

 It'd be nice to have something similar in Leo... ;-)

 Regards, Jon N

 On Saturday, March 9, 2024 at 7:04:19 PM UTC tbp1...@gmail.com wrote:

> We can't directly insert an image into a standard Leo node because 
> they are text-only.  I find this very annoying sometimes, especially when 
> I 
> am writing a note and want to include an image.  
>
> But we can do the next best thing - insert an ReStructuredText (RsT) 
> instruction to display an image so that we can view it with the 
> viewrendered3 plugin (VR3). The instruction is short and easy, but it's 
> still annoying to type and I usually forget the exact details. I have a 
> button that toggles VR3 on and off so that it's easy to view an embedded 
> image once the RsT instruction is there. An embedding command would make 
> embedding with Leo as easy as embedding an image in a word processor.  
>  Aha, this is Leo, let's write a script!
>
> Here is a script that pops up a file dialog and inserts a relative 
> path to the chosen file.  There are several small variations which I 
> discuss after the code.
>
> """Insert RsT code at cursor to display an image.
>
> The path to the image file will come from a file dialog.
> This action is undoable.
> """
> PATH = g.app.gui.runOpenFileDialog(c,
> title="Import File",
> filetypes=[("All files", "*"),],
> defaultextension=".*",
> multiple=False)
>
> if PATH:
> from os.path import relpath
> PATH = relpath(PATH)
> PATH = PATH.replace('\\', '/').replace('"', '').replace("'", '')
> IMAGE_TEMPLATE = f'''
>
> .. figure:: {PATH}
> :scale: 50%
>
> '''
> w = c.frame.body.wrapper
> p = c.p
> s = p.b
> u = c.undoer
>
> start, _ = w.getSelectionRange()
>
> undoType = 'insert-rst-image-code'
> undoData = u.beforeChangeNodeContents(p)
>
> head, tail = s[:start], s[start:]
> p.b = head + IMAGE_TEMPLATE + tail
>
> c.setChanged()
> p.setDirty()
> u.afterChangeNodeContents(p, undoType, undoData)
> c.redraw()
>
> Variations:
> 1.  If you want an absolute path instead of a relative path, delete 
> the lines
> from os.path import relpath
> PATH = relpath(PATH)
> with
>
> 2. If you  want to get the path from the clipboard instead of a file 
> dialog, replace the lines
>
> PATH = g.app.gui.runOpenFileDialog(c,
> title="Import File",
> filetypes=[("All files", "*"),],
> 

Re: A Script To Insert An Image

2024-03-09 Thread jkn
I am really thinking of the situation where I have already captured an 
image to the clipboard (using some other app...), and then want to paste 
into Leo. But there will undoubtably be something useful in what Terry has 
done

On Saturday, March 9, 2024 at 8:34:45 PM UTC tbp1...@gmail.com wrote:

> Yup, Terry Brown has already done most of it for us in the screen_capture 
> plugin.  Here's the docstring:
>
> """
> screen_capture.py
> =
>
> Capture screen shots - single frames are useful.  The
> `Recorder` class can also capture frames continuously but that's not
> really useful, it doesn't handle audio or video encoding, and can't 
> maintain
> a 30 fps frame rate.  The code for doing so is not hooked up in this 
> plugin.
>
> Screen captures are saved in ``~/.leo/screen_captures`` with
> timestamps in the filenames.
>
> Commands
> 
>
> ``screen-capture-5sec``
>   Wait five seconds, then take a screen shot.
> ``screen-capture-now``
>   Take a screen shot.
>
> Settings
> 
>
> ``@string screen-capture-save-path``
>   Save screen shots here instead of ~/.leo/screen_captures
>
> Terry Brown, terry_...@yahoo.com, Fri Apr 19 16:33:45 2013
> """
>
> The code may need to be updated for Qt6, since it was originally written 
> for Qt4 in 2013. Or just the key capture part of the code could be used, 
> since the entire plugin is more complicated than necessary.  Also it 
> doesn't capture a part of the screen as best as I can see, only the whole.
> On Saturday, March 9, 2024 at 3:27:30 PM UTC-5 jkn wrote:
>
>> I would expect that to be somewhat os-dependant (I mostly use Linux), but 
>> perhaps it is there. I will try to take a look for clipboard-paste 
>> functions.
>>
>>
>>
>> On Saturday, March 9, 2024 at 8:22:44 PM UTC tbp1...@gmail.com wrote:
>>
>>> I seem to remember that somewhere in the code base, Leo code to capture 
>>> the screen has already been worked out.  If that's the case we're in clover.
>>>
>>> On Saturday, March 9, 2024 at 3:09:24 PM UTC-5 jkn wrote:
>>>
 The way I have been using the Obsidian feature is to paste image bytes 
 (eg. from a screen region capture). So Obsidian saves a file:

 /path/to/attachments/ 

 Pasted image 20240228230106.png


 Where /path/to/attachments is an Obsidian setting, and the name of the 
 file is clearly a timestamp.


 Obsidian only uses markdown, so it inserts 


 ![[Pasted image 20240228230106.png]]


 into the 'node being edited'


 I think you can also drag and drop files into a 'node'.


 There would clearly have to be some work to make this generally useful 
 in a Leo context...



 On Saturday, March 9, 2024 at 7:35:15 PM UTC tbp1...@gmail.com wrote:

> Shouldn't be hard.  What would be on the clipboard?  Image bytes?  Or 
> an image filename?  I often select an image in a file manager window, 
> copy 
> it to an "images" subdirectory of the current outline, then write the 
> embedding code into and "images" child node.  That would be easy to write 
> a 
> script for.
>
> On Saturday, March 9, 2024 at 2:14:41 PM UTC-5 jkn wrote:
>
>> This looks interesting and useful, thanks Thomas. I confess I 
>> rarely/never use Leo with images, I really should experiment a little.
>>
>> Recently I have been using Obsidian as a note-taking app (Joplin is 
>> similar). Neither are as capable as Leo, in many ways, but they have 
>> their 
>> niceties.
>> One that is handy when note-taking is the ability to paste *from the 
>> clipboard*. You can setup an area (directory0 in an Obsidian 'vault' - 
>> then 
>> 'paste from clipboard' will
>> (a) create a unique filename within the image directory, and put the 
>> clipboard contents in there as eg. a .png file
>> (b) add a (markdown) reference to the new image in the 'note' that 
>> you are in.
>>
>> It'd be nice to have something similar in Leo... ;-)
>>
>> Regards, Jon N
>>
>> On Saturday, March 9, 2024 at 7:04:19 PM UTC tbp1...@gmail.com wrote:
>>
>>> We can't directly insert an image into a standard Leo node because 
>>> they are text-only.  I find this very annoying sometimes, especially 
>>> when I 
>>> am writing a note and want to include an image.  
>>>
>>> But we can do the next best thing - insert an ReStructuredText (RsT) 
>>> instruction to display an image so that we can view it with the 
>>> viewrendered3 plugin (VR3). The instruction is short and easy, but it's 
>>> still annoying to type and I usually forget the exact details. I have a 
>>> button that toggles VR3 on and off so that it's easy to view an 
>>> embedded 
>>> image once the RsT instruction is there. An embedding command would 
>>> make 
>>> embedding with Leo as easy as embedding an image in a word processor.  

Re: A Script To Insert An Image

2024-03-09 Thread jkn
The way I have been using the Obsidian feature is to paste image bytes (eg. 
from a screen region capture). So Obsidian saves a file:

/path/to/attachments/ 

Pasted image 20240228230106.png


Where /path/to/attachments is an Obsidian setting, and the name of the file 
is clearly a timestamp.


Obsidian only uses markdown, so it inserts 


![[Pasted image 20240228230106.png]]


into the 'node being edited'


I think you can also drag and drop files into a 'node'.


There would clearly have to be some work to make this generally useful in a 
Leo context...



On Saturday, March 9, 2024 at 7:35:15 PM UTC tbp1...@gmail.com wrote:

> Shouldn't be hard.  What would be on the clipboard?  Image bytes?  Or an 
> image filename?  I often select an image in a file manager window, copy it 
> to an "images" subdirectory of the current outline, then write the 
> embedding code into and "images" child node.  That would be easy to write a 
> script for.
>
> On Saturday, March 9, 2024 at 2:14:41 PM UTC-5 jkn wrote:
>
>> This looks interesting and useful, thanks Thomas. I confess I 
>> rarely/never use Leo with images, I really should experiment a little.
>>
>> Recently I have been using Obsidian as a note-taking app (Joplin is 
>> similar). Neither are as capable as Leo, in many ways, but they have their 
>> niceties.
>> One that is handy when note-taking is the ability to paste *from the 
>> clipboard*. You can setup an area (directory0 in an Obsidian 'vault' - then 
>> 'paste from clipboard' will
>> (a) create a unique filename within the image directory, and put the 
>> clipboard contents in there as eg. a .png file
>> (b) add a (markdown) reference to the new image in the 'note' that you 
>> are in.
>>
>> It'd be nice to have something similar in Leo... ;-)
>>
>> Regards, Jon N
>>
>> On Saturday, March 9, 2024 at 7:04:19 PM UTC tbp1...@gmail.com wrote:
>>
>>> We can't directly insert an image into a standard Leo node because they 
>>> are text-only.  I find this very annoying sometimes, especially when I am 
>>> writing a note and want to include an image.  
>>>
>>> But we can do the next best thing - insert an ReStructuredText (RsT) 
>>> instruction to display an image so that we can view it with the 
>>> viewrendered3 plugin (VR3). The instruction is short and easy, but it's 
>>> still annoying to type and I usually forget the exact details. I have a 
>>> button that toggles VR3 on and off so that it's easy to view an embedded 
>>> image once the RsT instruction is there. An embedding command would make 
>>> embedding with Leo as easy as embedding an image in a word processor.  
>>>  Aha, this is Leo, let's write a script!
>>>
>>> Here is a script that pops up a file dialog and inserts a relative path 
>>> to the chosen file.  There are several small variations which I discuss 
>>> after the code.
>>>
>>> """Insert RsT code at cursor to display an image.
>>>
>>> The path to the image file will come from a file dialog.
>>> This action is undoable.
>>> """
>>> PATH = g.app.gui.runOpenFileDialog(c,
>>> title="Import File",
>>> filetypes=[("All files", "*"),],
>>> defaultextension=".*",
>>> multiple=False)
>>>
>>> if PATH:
>>> from os.path import relpath
>>> PATH = relpath(PATH)
>>> PATH = PATH.replace('\\', '/').replace('"', '').replace("'", '')
>>> IMAGE_TEMPLATE = f'''
>>>
>>> .. figure:: {PATH}
>>> :scale: 50%
>>>
>>> '''
>>> w = c.frame.body.wrapper
>>> p = c.p
>>> s = p.b
>>> u = c.undoer
>>>
>>> start, _ = w.getSelectionRange()
>>>
>>> undoType = 'insert-rst-image-code'
>>> undoData = u.beforeChangeNodeContents(p)
>>>
>>> head, tail = s[:start], s[start:]
>>> p.b = head + IMAGE_TEMPLATE + tail
>>>
>>> c.setChanged()
>>> p.setDirty()
>>> u.afterChangeNodeContents(p, undoType, undoData)
>>> c.redraw()
>>>
>>> Variations:
>>> 1.  If you want an absolute path instead of a relative path, delete the 
>>> lines
>>> from os.path import relpath
>>> PATH = relpath(PATH)
>>> with
>>>
>>> 2. If you  want to get the path from the clipboard instead of a file 
>>> dialog, replace the lines
>>>
>>> PATH = g.app.gui.runOpenFileDialog(c,
>>> title="Import File",
>>> filetypes=[("All files", "*"),],
>>> defaultextension=".*",
>>> multiple=False)
>>>
>>> with the line 
>>>
>>> PATH = g.app.gui.getTextFromClipboard()
>>>
>>> 3. If you want the embedded image to be full width instead of 50%, 
>>> delete the line
>>>
>>> :scale: 50%
>>>
>>> 4. You can make this work with Markdown or Asciidoc by using their 
>>> embedding instruction in the TEMPLATE instead of the RsT one.
>>>
>>> I have added the command to my own local menu.  VR3 can open in a tab in 
>>> the log pane; the command for toggling in a tab is *vr3-toggle-tab. * I 
>>> usually like opening it in the log pane instead of in its own separate pane.
>>>
>>> If you would like to create a local menu of your own and don't know how, 
>>> it's easy.  Just ask and 

Re: A Script To Insert An Image

2024-03-09 Thread Thomas Passin
Yup, Terry Brown has already done most of it for us in the screen_capture 
plugin.  Here's the docstring:

"""
screen_capture.py
=

Capture screen shots - single frames are useful.  The
`Recorder` class can also capture frames continuously but that's not
really useful, it doesn't handle audio or video encoding, and can't maintain
a 30 fps frame rate.  The code for doing so is not hooked up in this plugin.

Screen captures are saved in ``~/.leo/screen_captures`` with
timestamps in the filenames.

Commands


``screen-capture-5sec``
  Wait five seconds, then take a screen shot.
``screen-capture-now``
  Take a screen shot.

Settings


``@string screen-capture-save-path``
  Save screen shots here instead of ~/.leo/screen_captures

Terry Brown, terry_n_br...@yahoo.com, Fri Apr 19 16:33:45 2013
"""

The code may need to be updated for Qt6, since it was originally written 
for Qt4 in 2013. Or just the key capture part of the code could be used, 
since the entire plugin is more complicated than necessary.  Also it 
doesn't capture a part of the screen as best as I can see, only the whole.
On Saturday, March 9, 2024 at 3:27:30 PM UTC-5 jkn wrote:

> I would expect that to be somewhat os-dependant (I mostly use Linux), but 
> perhaps it is there. I will try to take a look for clipboard-paste 
> functions.
>
>
>
> On Saturday, March 9, 2024 at 8:22:44 PM UTC tbp1...@gmail.com wrote:
>
>> I seem to remember that somewhere in the code base, Leo code to capture 
>> the screen has already been worked out.  If that's the case we're in clover.
>>
>> On Saturday, March 9, 2024 at 3:09:24 PM UTC-5 jkn wrote:
>>
>>> The way I have been using the Obsidian feature is to paste image bytes 
>>> (eg. from a screen region capture). So Obsidian saves a file:
>>>
>>> /path/to/attachments/ 
>>>
>>> Pasted image 20240228230106.png
>>>
>>>
>>> Where /path/to/attachments is an Obsidian setting, and the name of the 
>>> file is clearly a timestamp.
>>>
>>>
>>> Obsidian only uses markdown, so it inserts 
>>>
>>>
>>> ![[Pasted image 20240228230106.png]]
>>>
>>>
>>> into the 'node being edited'
>>>
>>>
>>> I think you can also drag and drop files into a 'node'.
>>>
>>>
>>> There would clearly have to be some work to make this generally useful 
>>> in a Leo context...
>>>
>>>
>>>
>>> On Saturday, March 9, 2024 at 7:35:15 PM UTC tbp1...@gmail.com wrote:
>>>
 Shouldn't be hard.  What would be on the clipboard?  Image bytes?  Or 
 an image filename?  I often select an image in a file manager window, copy 
 it to an "images" subdirectory of the current outline, then write the 
 embedding code into and "images" child node.  That would be easy to write 
 a 
 script for.

 On Saturday, March 9, 2024 at 2:14:41 PM UTC-5 jkn wrote:

> This looks interesting and useful, thanks Thomas. I confess I 
> rarely/never use Leo with images, I really should experiment a little.
>
> Recently I have been using Obsidian as a note-taking app (Joplin is 
> similar). Neither are as capable as Leo, in many ways, but they have 
> their 
> niceties.
> One that is handy when note-taking is the ability to paste *from the 
> clipboard*. You can setup an area (directory0 in an Obsidian 'vault' - 
> then 
> 'paste from clipboard' will
> (a) create a unique filename within the image directory, and put the 
> clipboard contents in there as eg. a .png file
> (b) add a (markdown) reference to the new image in the 'note' that you 
> are in.
>
> It'd be nice to have something similar in Leo... ;-)
>
> Regards, Jon N
>
> On Saturday, March 9, 2024 at 7:04:19 PM UTC tbp1...@gmail.com wrote:
>
>> We can't directly insert an image into a standard Leo node because 
>> they are text-only.  I find this very annoying sometimes, especially 
>> when I 
>> am writing a note and want to include an image.  
>>
>> But we can do the next best thing - insert an ReStructuredText (RsT) 
>> instruction to display an image so that we can view it with the 
>> viewrendered3 plugin (VR3). The instruction is short and easy, but it's 
>> still annoying to type and I usually forget the exact details. I have a 
>> button that toggles VR3 on and off so that it's easy to view an embedded 
>> image once the RsT instruction is there. An embedding command would make 
>> embedding with Leo as easy as embedding an image in a word processor.  
>>  Aha, this is Leo, let's write a script!
>>
>> Here is a script that pops up a file dialog and inserts a relative 
>> path to the chosen file.  There are several small variations which I 
>> discuss after the code.
>>
>> """Insert RsT code at cursor to display an image.
>>
>> The path to the image file will come from a file dialog.
>> This action is undoable.
>> """
>> PATH = g.app.gui.runOpenFileDialog(c,
>> 

Re: A Script To Insert An Image

2024-03-09 Thread Thomas Passin
Shouldn't be hard.  What would be on the clipboard?  Image bytes?  Or an 
image filename?  I often select an image in a file manager window, copy it 
to an "images" subdirectory of the current outline, then write the 
embedding code into and "images" child node.  That would be easy to write a 
script for.

On Saturday, March 9, 2024 at 2:14:41 PM UTC-5 jkn wrote:

> This looks interesting and useful, thanks Thomas. I confess I rarely/never 
> use Leo with images, I really should experiment a little.
>
> Recently I have been using Obsidian as a note-taking app (Joplin is 
> similar). Neither are as capable as Leo, in many ways, but they have their 
> niceties.
> One that is handy when note-taking is the ability to paste *from the 
> clipboard*. You can setup an area (directory0 in an Obsidian 'vault' - then 
> 'paste from clipboard' will
> (a) create a unique filename within the image directory, and put the 
> clipboard contents in there as eg. a .png file
> (b) add a (markdown) reference to the new image in the 'note' that you are 
> in.
>
> It'd be nice to have something similar in Leo... ;-)
>
> Regards, Jon N
>
> On Saturday, March 9, 2024 at 7:04:19 PM UTC tbp1...@gmail.com wrote:
>
>> We can't directly insert an image into a standard Leo node because they 
>> are text-only.  I find this very annoying sometimes, especially when I am 
>> writing a note and want to include an image.  
>>
>> But we can do the next best thing - insert an ReStructuredText (RsT) 
>> instruction to display an image so that we can view it with the 
>> viewrendered3 plugin (VR3). The instruction is short and easy, but it's 
>> still annoying to type and I usually forget the exact details. I have a 
>> button that toggles VR3 on and off so that it's easy to view an embedded 
>> image once the RsT instruction is there. An embedding command would make 
>> embedding with Leo as easy as embedding an image in a word processor.  
>>  Aha, this is Leo, let's write a script!
>>
>> Here is a script that pops up a file dialog and inserts a relative path 
>> to the chosen file.  There are several small variations which I discuss 
>> after the code.
>>
>> """Insert RsT code at cursor to display an image.
>>
>> The path to the image file will come from a file dialog.
>> This action is undoable.
>> """
>> PATH = g.app.gui.runOpenFileDialog(c,
>> title="Import File",
>> filetypes=[("All files", "*"),],
>> defaultextension=".*",
>> multiple=False)
>>
>> if PATH:
>> from os.path import relpath
>> PATH = relpath(PATH)
>> PATH = PATH.replace('\\', '/').replace('"', '').replace("'", '')
>> IMAGE_TEMPLATE = f'''
>>
>> .. figure:: {PATH}
>> :scale: 50%
>>
>> '''
>> w = c.frame.body.wrapper
>> p = c.p
>> s = p.b
>> u = c.undoer
>>
>> start, _ = w.getSelectionRange()
>>
>> undoType = 'insert-rst-image-code'
>> undoData = u.beforeChangeNodeContents(p)
>>
>> head, tail = s[:start], s[start:]
>> p.b = head + IMAGE_TEMPLATE + tail
>>
>> c.setChanged()
>> p.setDirty()
>> u.afterChangeNodeContents(p, undoType, undoData)
>> c.redraw()
>>
>> Variations:
>> 1.  If you want an absolute path instead of a relative path, delete the 
>> lines
>> from os.path import relpath
>> PATH = relpath(PATH)
>> with
>>
>> 2. If you  want to get the path from the clipboard instead of a file 
>> dialog, replace the lines
>>
>> PATH = g.app.gui.runOpenFileDialog(c,
>> title="Import File",
>> filetypes=[("All files", "*"),],
>> defaultextension=".*",
>> multiple=False)
>>
>> with the line 
>>
>> PATH = g.app.gui.getTextFromClipboard()
>>
>> 3. If you want the embedded image to be full width instead of 50%, delete 
>> the line
>>
>> :scale: 50%
>>
>> 4. You can make this work with Markdown or Asciidoc by using their 
>> embedding instruction in the TEMPLATE instead of the RsT one.
>>
>> I have added the command to my own local menu.  VR3 can open in a tab in 
>> the log pane; the command for toggling in a tab is *vr3-toggle-tab. * I 
>> usually like opening it in the log pane instead of in its own separate pane.
>>
>> If you would like to create a local menu of your own and don't know how, 
>> it's easy.  Just ask and I'll show what to add to myLeoSettings,leo.
>>
>

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/0aecddc9-6a24-44f7-8a75-1520ed20436bn%40googlegroups.com.


Re: LeoJS - How To Write To File System And Run External Programs

2024-03-09 Thread Félix
I'm still working on this! Thanks for your patience :) 
  
(The latest LeoJS 0.2.12 release is the result of trying to capture many 
features for that video tutorial, and realizing that they needed a bit of 
polishing!)

Félix

On Wednesday, January 3, 2024 at 7:18:33 PM UTC-5 tbp1...@gmail.com wrote:

> Yay!
>
> On Wednesday, January 3, 2024 at 7:12:26 PM UTC-5 Félix wrote:
>
>> I'm going to take a coding break by doing a tutorial exactly about that!
>>
>> On Wednesday, January 3, 2024 at 4:56:12 PM UTC-5 tbp1...@gmail.com 
>> wrote:
>>
>>> Now That leoJS is getting into pretty good shape - and Felix must need a 
>>> month's vacation! - I am thinking about plugins and scripts that can do 
>>> things that are easy to do from within Leo. Specifically, scripts that can 
>>> read and write files from the file system, and files that do the equivalent 
>>> of subprocess.run() or subprocess.Popen().  In addition (or maybe it's in 
>>> the same group), scripts that launch a web browser on a specified file.
>>>
>>> Is there somewhere we can read up on these things, that is, how a leoJS 
>>> script can do them in javascript/typescript?
>>>
>>

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/920a648f-9a81-4142-aec1-5a2e8546fbe4n%40googlegroups.com.


Re: ✨LeoJS beta 0.2.12 Released!

2024-03-09 Thread Thomas Passin
A great achievement, Felix!  So much work, too!

I see this update isn't in the marketplace for vscodium yet.  Coming soon, 
I imagine?  It updated successfully in VScode.

On Saturday, March 9, 2024 at 9:40:56 PM UTC-5 Félix wrote:

> Introducing LeoJS Beta 0.2.12
> Félix here, ecstatic to unveil the latest milestone in our coding 
> odyssey—LeoJS 
> Beta 0.2.12 
> !
> [image: leojs-alien2.png]
> What's New in 0.2.12?
>
>- *Enhanced Help Commands:* I've revamped the help commands, 
>transitioning from markdown preview panes to more interactive HTML 
>webviews, ensuring you get the guidance you need, right when you need it.
>- *VSCode Api access for scripts: *A pivotal update (note: it's a 
>breaking change) - the VSCode instance is now accessible via g.vscode 
>instead of the previous g.app.vscode, simplifying your interaction with 
> the 
>editor.
>- *More scripting helpers: *Dive deeper with more external libraries 
>like SQL, pako, showdown, and JSZip now at your fingertips through the 
>global 'g' object. Plus, essential OS path-related constants such as 
>extensionContext, extensionUri, and workspaceUri are also readily 
>accessible to help you read & write to files easily.
>- *Feature-Rich Commands & Fixes:* Discover the new 
>'show-recent-files' command, along with the improved Find-Panel, and 
>explore fixes and additions across the board, including 'open-aside' 
>command enhancements and a new, intuitive UNL status bar button.
>- *Polished Experience:* I've removed the 'font-size & zoom' related 
>settings in favor of VSCode's new zoom settings API, added XML language 
>colorization support, and introduced UNL relative path support for a more 
>refined experience.
>- *Improved UI behavior and fixes: *@buttons panel now refreshes 
>properly after a 'revert-to-saved'command, the 'Goto' panel's navigation 
>stability issues are resolved, the startup process properly ask for a 
> LeoID 
>if none exist, among many other bugfixes.
>
> Your Feedback Fuels Improvement!
>
> Your input is invaluable. Don't hesitate to share your thoughts, report 
> issues, or to suggest enhancements on the 'issues' section 
>  of the repository.
>
> Join the Journey!
>
> Ready to try out LeoJS Beta 0.2.12 
> ? Dive 
> in now and discover how this latest version can transform your programming 
> workflow. (also available on open-vsx.org 
> )
>
> Or to try online in VSCode for the web, simply visit* a GitHub repository 
> that you own*, press '.' (period) to switch to the web editor 
> ,
>  
> install LeoJS from the extension panel, and you're set! 
>
> Here's to many more code adventures together!
>
> Happy coding, 
> Félix
> [image: explorer-futurist.jpg]
>
>

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/b2c4cef6-8ff9-490b-96b3-550802527084n%40googlegroups.com.


Re: LeoJS - How To Write To File System And Run External Programs

2024-03-09 Thread Thomas Passin
I don't know if you got around to thinking about it yet (you've got so much 
else going on!), but the command I wrote to run external files is in 
LeoPyRef and it's called *execute-external-file*.  It has some trickiness 
because it has to run on Linux as well as Windows, and the terminal 
commands to launch programs differ among the distros. The code has to try 
some empirical hacks to figure it all out. But it ought to port to TS 
pretty easily, I would think.

On Saturday, March 9, 2024 at 9:46:57 PM UTC-5 Félix wrote:

> I'm still working on this! Thanks for your patience :) 
>   
> (The latest LeoJS 0.2.12 release is the result of trying to capture many 
> features for that video tutorial, and realizing that they needed a bit of 
> polishing!)
>
> Félix
>
> On Wednesday, January 3, 2024 at 7:18:33 PM UTC-5 tbp1...@gmail.com wrote:
>
>> Yay!
>>
>> On Wednesday, January 3, 2024 at 7:12:26 PM UTC-5 Félix wrote:
>>
>>> I'm going to take a coding break by doing a tutorial exactly about that!
>>>
>>> On Wednesday, January 3, 2024 at 4:56:12 PM UTC-5 tbp1...@gmail.com 
>>> wrote:
>>>
 Now That leoJS is getting into pretty good shape - and Felix must need 
 a month's vacation! - I am thinking about plugins and scripts that can do 
 things that are easy to do from within Leo. Specifically, scripts that can 
 read and write files from the file system, and files that do the 
 equivalent 
 of subprocess.run() or subprocess.Popen().  In addition (or maybe it's in 
 the same group), scripts that launch a web browser on a specified file.

 Is there somewhere we can read up on these things, that is, how a leoJS 
 script can do them in javascript/typescript?

>>>

-- 
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 leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/1d5176ef-3bc9-4175-97e5-7bc8f5606da2n%40googlegroups.com.