Sugar API Documentation (Advanced)
Advanced tips and tricks
Getting the lists interface
To get the lists interface in a plugin or otherwise outside of main, you could of course
just import lists from main, but this is unwise.
Instead we recommend:
from sugar import sugarapi lists = sugarapi.lists()
This doesn’t regenerate the lists API (this would be a mistake), but just grabs the (singleton) instance of lists.
You can however reinitialize the lists API (when testing, or for some weird reason of your own)
lists._reinit()
Note however that you need to ensure that sugar lists are inited at some point.
This is done for you in sugar_loader.py,
but you may need to do this yourself in a specific load script:
lists = sugarapi.lists(ensureInited=True)
Translating itemset code
You can use lists.convertCode to convert itemsets/gets to sugar forms:
lists.convertCode("""print itemget("obj1", "OBJ_CULL_TOG")""")
