A recent rev added the p.u property, which you can think of as a synonym
for p.v.unknownAttributes on *both* sides of an assignment.
The example in Leo's documentation for access uA's is *way *too
complicated. In fact, the following suffices to set the 'n' attribute for
test_plugin:
plugin_name = 'test_plugin'
d = p.u.get(plugin_name,{})
d ['n'] = 8
p.u [plugin_name] = d
p.u is the *outer* dictionary. p.u.get.(plugin_name, {}) is the inner
dictionary. The last line is all that is needed to update the outer
dictionary!
It is *very* easy to search for particular uA's. The following script
prints all the keys in the outer-level uA dictionaries:
for p in c.all_unique_positions():
if p.u:
print(p.h, sorted(p.u.keys()))
This is a typical usage of Leo's generators
<http://leoeditor.com/tutorial-scripting.html#generators>. Generators
visit each position (or node) quickly. Even if you aren't going to program
much, you should be aware of how easy it is to get and set the data in each
node. In fact, now would be a great time to read Leo's Scripting Tutorial
<http://leoeditor.com/tutorial-scripting.html> again :-) This will allow
you to "dream bigger" with Leo.
The following script creates a list of all positions having an icon, that
is, an outer uA dict with a 'lineYOffset' key.
aList = [p.copy() for p in c.all_unique_positions() if 'lineYOffset' in p.u]
print('\n'.join([p.h for p in aList]))
Yes, the lineYOffset key is wonky and unhelpful, but it can't be changed
now. Hmm, maybe the code could support an an alternative clearer key, say
str_core_icon. Furthermore, the str_core_* keys should probably be
reserved for Leo's core.
*Important*: If you don't understand these lines, *please *study Python's list
comprehensions <http://www.secnetix.de/olli/Python/list_comprehensions.hawk>.
They are incredibly useful. '\n'.join(aList) is a great idiom to know.
str.join is one of python's most useful string methods
<https://docs.python.org/2/library/stdtypes.html#string-methods>. It
converts between lists and strings.
Imo, Leo should have p.temp_u and v.temp_u properties, so that getting and
setting temp uA's will be as easy as getting and setting uA's. I'll do this
today.
These Code Academy threads are having an immediate impact. Focusing on
simple, practical tasks has revealed rough spots in both Leo's code and
Leo's docs.
As always with the Code Academy, questions and comments are strongly
encouraged. Make *sure* you understand the code examples in this post. They
are the foundation for programming in Leo.
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.