I'm all in favor of improving features, but please find a way to make them 
continue to work with existing code.  It seems to me that the easiest way 
to go about this would be to make the code fall back to a document or 
outline-relative path if it can't find the icon files in the other standard 
places it already looks for. 

On Monday, July 18, 2022 at 4:23:06 PM UTC-4 spike wrote:

> g.os_path_exists works with relative paths but 
> c.editCommands.insertIconFromFile forces relative paths to be relative 
> to the Leo theme directory. Document relative paths are rejected.
>
> Running the following command from Leo's Python Console tab fails:
> c.editCommands.insertIconFromFile('./icons/xfsm-lock.png', p=p)
>
> This works, but only for theme icons:
> c.editCommands.insertIconFromFile('light/checkbox_checked.svg', p=p)
>
> This also works, but forces an absolute path:
> import os
>
> c.editCommands.insertIconFromFile(os.path.abspath('./icons/xfsm-lock.png'), 
>
> p=p)
>
> c.editCommands.insertIconFromFile calls appendImageDictToList, which 
> then calls g.app.gui.getTreeImage, which requires relative paths to be 
> relative to the current Leo theme. Document-relative paths are rejected 
> with an unhelpful "can not load image: None" message in the log.
>
> There are three possible use cases for icons, but the current logic only 
> supports two of them.
> 1) Theme relative path. This is used by the "to-do" plugin, which seems 
> to be why the icon feature exists in the first place.
> 2) Document relative path. Useful but unsupported.
> 3) System relative path. Supported, limited use, but not portable.
>
>
> As it stands the current implementation is incomplete. If there are no 
> objections I will work on a fix.
>
> TO DO:
> * The 'relPath' attribute needs to be replaced by an 'isThemeIcon' flag. 
> Old icon data needs to be automatically updated to the new format on 
> file load. Theme paths should also respect the current theme.
>
> * I'm debating adding an option to c.editCommands.insertIconFromFile or 
> making a new insertThemeIconFromFile function for theme icons.
>
> * The insert-icon command should get a companion insert-theme-icon 
> command so that the Open dialog starts in the right folder.
>
> * The to-do plugin needs to be updated to the new API.
>
> * There should also be a visible indicator when an icon file is missing 
> or unreadable. I'm thinking a red 'x' in a white box, like web browsers do.
>
> * Test cases need to be written.
>
> * Then documentation.
>
>
> I'm still new to Leo coding, so I'll probably have questions.
>
> Thank you for your patience.
>
>
> On 2022-07-18 08:04, tbp1...@gmail.com wrote:
> > Typically, either you write code and try different paths depending on
> > whether your file is in one place or another, or a Leo method does the 
> same
> > thing for you, in which case you need to know where Leo is going to look.
> > For example, in the part of the Cheatsheet you mention:
> > 
> > fn = g.os_path_finalize_join(g.app.loadDir,
> > '..', 'Icons', 'Tango', '16x16', 'status', icon)
> > if g.os_path_exists(fn):
> > c.editCommands.insertIconFromFile(path=fn)
> > 
> > g.os_path_exists() works with relative paths as wel as absolute paths.
> > 
> > It would be helpful if you explain just how you are trying to use these
> > icons. If it is via a Leo setting, which settings? If via code you have
> > written, please show the code.
> > On Monday, July 18, 2022 at 5:55:21 AM UTC-4 spike wrote:
> > 
> >> On 2022-07-17 11:29, Félix wrote:
> >>> Thanks for the examples spike, but you replied to me only instead of
> >> reply
> >>> all, so your examples are not showing in the thread.
> >>>
> >>> Here is the example spike provided: (see attachments)
> >>>
> >>> On the other hand, i've looked at the 'unknownattributes' of the nodes,
> >> and
> >>> indeed the paths provided for the icons is not relative to the Leo 
> file,
> >>> but are instead complete paths that will not work anywhere else: such 
> as
> >>> */home/keith/tmp/test/icons/blablabla.png*
> >>>
> >>> instead of *icons/blablabla.png*
> >>>
> >>> Lastly, i tried using / setting / finding out about icons on nodes as I
> >>> was totally unaware that this was a thing... i could not find anything
> >> ...
> >>> Where / how did you get those icons and icon attributes? searching for
> >>> 'icons' in the documentation yields some other unrelated stuff... Like
> >> can
> >>> you take screenshots on how you set those?
> >>>
> >>> (sorry i'm totally ignorant about those 'node icons' that you speak of,
> >>> although i can see they exists in your screenshots and that the
> >> attributes
> >>> are there in the .leo file.)
> >>>
> >>> Félix
> >>>
> >>>
> >>>
> >>> On Sunday, July 17, 2022 at 7:46:03 AM UTC-4 Edward K. Ream wrote:
> >>>
> >>>> On Sat, Jul 16, 2022 at 9:50 PM Robert-Felix <felix...@gmail.com>
> >> wrote:
> >>>>
> >>>> Leo uses relative paths for most stuff so moving the leo file and your
> >>>>> 'project' or 'resources' folder to accompany it along should keep
> >>>>> everything working fine. whatever you had going on...
> >>>>>
> >>>>
> >>>> Leo's path expressions
> >>>> <http://leoeditor.com/directives.html#path-expressions> should 
> suffice
> >>>> for any conceivable purpose :-)
> >>>>
> >>>> Edward
> >>>>
> >>>
> >> Sorry about the misdirected reply. I'll try to do better in future.
> >>
> >> Thanks for reposting test file attachment. I'm posting a shot of the
> >> menu option as well as the 'good.png' and 'bad.png' example screenshots.
> >>
> >>
> >> The documentation is sparse and doesn't give much information. Most of
> >> what I know about this feature comes from trial-and-error and looking at
> >> Leo's source code. I'm still figuring things out.
> >>
> >>
> >> https://leoeditor.com/commands.html#miscellaneous-commands lists four
> >> minibuffer commands that do the same things as the menu options.
> >>
> >> CheatSheet.leo, available from the "Help" menu, has a short example
> >> script under "Learning to be a leo Developer->Code academy->CA: icons"
> > 
>

-- 
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/3ead379e-e12b-40d8-a37d-6dda7ef3c6a0n%40googlegroups.com.

Reply via email to