That's a very good fit with a project I'm working on, currently I'm overwhelmed at work to near-panic levels, it won't be right away.
Thanks, Kent On Wed, May 4, 2016 at 2:34 PM, Edward K. Ream <[email protected]> wrote: > On Wed, May 4, 2016 at 12:34 PM, Kent Tenney <[email protected]> wrote: > >> > At present, @auto x.json will only restore properly when the @auto tree >> > was >> > first written with Leo. So it's one-way initially: from Leo to .json. >> >> Ah, didn't know that. I value Leo so much as a tool to aid in making >> sense of complexity via it's capability to parse on import, I was >> hoping the same would be available here. > > > It won't be available automatically, that is, via static commands or > (probably) @auto. However, it would be straightforward to write a script > that would create an outline based on outline structure, per your desires. > > Furthermore, it would be possible to create a customizable class that would > make writing such scripts a simple matter of filling in some vars/settings. > >> json.loads(file.read()) returns a dict consisting of dicts, lists, >> strings, bools. > > Correct. Programming is a snap because all the parsing has already been > done. It's also easy to create Leo nodes on the fly. For example, is a > simplified version (ignoring clones/traces) of JSON_Scanner.create_nodes, in > leo/importers/json.py: > > def create_nodes(self, parent, parent_d): > '''Create the tree of nodes rooted in parent.''' > c, d = self.c, self.gnx_dict > for child_gnx in parent_d.get('children'): > d2 = d.get(child_gnx) > child = parent.insertAsLastChild() > child.h = d2.get('h') or '<**no h**>' > child.b = d2.get('b') or g.u('') > if d2.get('gnx'): > child.v.findIndex = gnx = d2.get('gnx') > if d2.get('ua'): > child.u = d2.get('ua') > self.create_nodes(child, d2) > > Parent is the parent position, parent_d is a dict. As you can see, the > programming is just a matter of handling dict contents. > > The more general case would be more tedious because we have to discover > whether values are dicts, lists or something else. And unless we are willing > to have all lists and dicts to produce children, we will want to specify > which dictionary keys or list items are to create descendants. A little > messy, but clearly doable. > > Here is where the helper class comes in. It would contain all the general > code, asking the "user" to tell it what elements are to create outline > structure, which elements should be ignored, and which elements are to > create headline text, body text, or even may uA's. > > Kent, let's try this. Take a .json file that interests you, and consider > how you would like to have it imported into a Leo file. No need to spend > lots of time on this--just give a shot. Then send me the file and your > thoughts about how you would like it imported. I'll write a JSON_Importer > class to make writing such a script easier. It will be kinda like the class > RecursiveImportController class. > > 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. -- 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.
