Enhancement Request: Please add insertIconFromFile() to the commander.

Bug #1159500 reported by SegundoBob
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
leo-editor
Confirmed
Wishlist
Edward K. Ream

Bug Description

insertIconFromFile() is currently not used so far as I can tell. I conclude that it was intended for use by Leo-Editor scripts, but this work was not completed.

I want to use it in a Leo-Editor script. It does what I want and it seems to work correctly. Because it is not included in the approved Leo-Editor script API by being callable via the commander I must use the following ugly and probably brittle means:

import leo.core.leoEditCommands as lec

icon1 = '/home/ldi/bzr/LeoLatest/leo/Icons/cleo/pri1.png'

lec.editCommandsClass.insertIconFromFile(c.editCommands, icon1, p)

-------
Is there currently a better way for me to use insertIconFromFile()? Or a better function for a Leo-Editor script to use to insert an icon on a node?

Revision history for this message
SegundoBob (bhossley) wrote :

I also want to use insertIconFromFile() in a Python script that uses leoBridge to modify a Leo-Editor file.
This does not work. Importing module leo.core.leoEditCommands fails because this module does not allow g.app to be None. I'm not qualified to say whether or not this should be considered a bug.

Can anyone please tell me how to use leoBridge to insert an icon on a node in a Leo-Editor file?

Attached is a simple test case. The pathnames in this test case need to be modified to run in your environment. Then you can run the test case as shown below:

2013-03-24 17:51:26 /home/ldi/bzr/leo_diff
$ python setIcon.py
Traceback (most recent call last):
  File "setIcon.py", line 2, in <module>
    import leo.core.leoEditCommands as lec
  File "/home/ldi/bzr/LeoLatest/leo/core/leoEditCommands.py", line 220, in <module>
    @g.command('open-url')
  File "/home/ldi/bzr/LeoLatest/leo/core/leoGlobals.py", line 2743, in __call__
    g.error('@command decorator inside leoGlobals.py')
  File "/home/ldi/bzr/LeoLatest/leo/core/leoGlobals.py", line 2866, in error
    g.es_print(color=g.actualColor('red'),*args,**keys)
  File "/home/ldi/bzr/LeoLatest/leo/core/leoGlobals.py", line 2799, in actualColor
    if not g.app.log:
AttributeError: 'NoneType' object has no attribute 'log'
2013-03-24 17:51:29 /home/ldi/bzr/leo_diff
$
----------
I use Xubuntu 12.04 (precise)
Kernel 3.2.0-39-generic

Leo Log Window
Leo 4.11 devel, build 5639, 2013-03-24 11:01:23
Python 2.7.3, qt version 4.8.1
linux2
setting leoID from os.getenv('USER'): 'bob05'
load dir: /home/ldi/bzr/LeoLatest/leo/core
global config dir: /home/ldi/bzr/LeoLatest/leo/config

Revision history for this message
Edward K. Ream (edreamleo) wrote : Re: [Bug 1159500] [NEW] Enhancement Request: Please add insertIconFromFile() to the commander.

On Sun, Mar 24, 2013 at 2:25 PM, SegundoBob <email address hidden>wrote:

> Public bug reported:
>
> insertIconFromFile() is currently not used so far as I can tell. I
> conclude that it was intended for use by Leo-Editor scripts, but this work
> was not completed.
>
> I want to use it in a Leo-Editor script.

Are you aware that anything you do in an @button or @command node is
available to scripts?

Edward

Revision history for this message
SegundoBob (bhossley) wrote :

Edward K. Ream (edreamleo) wrote on 2013-03-25:

Are you aware that anything you do in an @button or @command node is
available to scripts?
------

Thank you for responding.

To answer your question: Yes--and NO. I have been aware of this claim for a long time. I've also read:

http://webpages.charter.net/edreamleo/scripting.html#invoking-commands-from-scripts

Perhaps I don't understand. Perhaps, there are exceptions to this generalization.

For example, consider the standard "button" Cmds - Icons - Insert-Icon. While there is a mini-buffer command insert-icon, I can't find any attribute of the commander that might correspond to insert-icon. Hence, I'm unable to use the "Invoking Commands from Scripts" recipe.

I'm also aware of this scheme:

https://groups.google.com/forum/?fromgroups=#!topic/leo-editor/3YjB8RjUbr0

And in fact, this scheme does work in this case for a Leo-Editor script:

c.executeMinibufferCommand('insert-icon')

But it does NOT do what I want to do. It pops up a file browser and it requires the user to pick an icon. I want to assign icons that I pick when I write my script. I want unattended script operation.

When I use this scheme from a Python script that uses leoBridge, the script does nothing and does not report any error. Of course, it doesn't have any hope of doing what I want, because there is no way for my Python script to specify the icon to be used.

Revision history for this message
SegundoBob (bhossley) wrote :

Bitten by the one attachment limitation. Here is the leoBridge using script.

Changed in leo-editor:
status: New → Confirmed
assignee: nobody → Edward K. Ream (edreamleo)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.