Object Explorer (was Re: Leo and Eve)

69 views
Skip to first unread message

Terry Brown

unread,
May 16, 2016, 3:40:06 PM5/16/16
to leo-editor
On Mon, 16 May 2016 06:02:45 -0700 (PDT)
john lunzer <lun...@gmail.com> wrote:

> A common feature in Pharo as well as Spyder and the pudb python
> debugger is the object explorer. This I believe is a useful pillar of
> the live coding environment.

https://github.com/leo-editor/snippets/blob/master/introspect.py
might be an object explorer, depending on your definition.

I just updated it to use vnodes, not positions, when building its
output, makes it 100x or more faster.

Usage:

Put above code in a node and use the script-button button to create a
button to run it.

Insert a new node

With that node selected, click the button. It will say "introspect
what?". `c` is an obvious answer, or c.p or g etc.

To introspect things not part of Leo, execute your code in the
valuespace namespace (c.vs, i.e. execute the code with vs-eval) and answer
`c.vs['myObj']` to the above question, this could be made more
streamlined (i.e. remove the `c.vs['']`) if needed.

Child nodes are created under the selected node listing the members of
the thing you're introspecting, grouped by type. The first node is a
list of the members by name.

To drill down into the object, just select the relevant node, and click
the button again, it doesn't need to be told what to inspect at
this point.

Loops (c.p.v.c == c) are handled by using a bookmark UNL which will
take you back up the tree to where the thing was first seen.

Cheers -Terry

Edward K. Ream

unread,
May 17, 2016, 1:50:33 PM5/17/16
to leo-editor
On Mon, May 16, 2016 at 2:40 PM, 'Terry Brown' via leo-editor <leo-e...@googlegroups.com> wrote:

>
https://github.com/leo-editor/snippets/blob/master/introspect.py might be an object explorer, depending on your definition.

> Put above code in a node and use the script-button button to create a
​ ​
button to run it.

> Insert a new node

> With that node selected, click the button.  It will say "introspect
​ ​
what?".  `c` is an obvious answer, or c.p or g etc.
 
​Many thanks, Terry, for this work.  I'm sure it will be useful.  It's already provocative. Several comments:

​1.The program will crash with Python 3, which is where I spend most of my time these days.  Various types no longer exist in Python 3:

 File "...\leo-editor\leo\test\scriptFile.py", line 112, in <module>
AttributeError: module 'types' has no attribute 'ClassType'

​2.I also got this crash:

Traceback (most recent call last):
 ...
  File "C:\leo.repo\leo-editor\leo\test\scriptFile.py", line 63, in show_obj
    if not seen_already(tnd, nd, iname, o):
  File "C:\leo.repo\leo-editor\leo\test\scriptFile.py", line 102, in seen_already
    nd.b = up.get_UNL(with_file=True, with_proto=True)
AttributeError: 'VNodeBase' object has no attribute 'get_UNL'


>To introspect things not part of Leo, execute your code in the valuespace namespace

​I am going to think about the implications of all this. I find all such browsers kinda scary, but perhaps I am just an odd duck...I never, ever, think about programs at this low level.  If I want to know the ivars defined in a class, for instance, I look in the ctor.

​Edward​

Terry Brown

unread,
May 17, 2016, 2:13:03 PM5/17/16
to leo-e...@googlegroups.com
On Tue, 17 May 2016 12:50:32 -0500
"Edward K. Ream" <edre...@gmail.com> wrote:

> ​Many thanks, Terry, for this work. I'm sure it will be useful. It's
> already provocative. Several comments:
>
> ​1.The program will crash with Python 3, which is where I spend most
> of my time these days. Various types no longer exist in Python 3:

I should try using that at home, not an option at work.

> File "...\leo-editor\leo\test\scriptFile.py", line 112, in <module>
> AttributeError: module 'types' has no attribute 'ClassType'
>
> ​2.I also got this crash:
>
> Traceback (most recent call last):
> ...
> File "C:\leo.repo\leo-editor\leo\test\scriptFile.py", line 63, in
> show_obj if not seen_already(tnd, nd, iname, o):
> File "C:\leo.repo\leo-editor\leo\test\scriptFile.py", line 102, in
> seen_already
> nd.b = up.get_UNL(with_file=True, with_proto=True)
> AttributeError: 'VNodeBase' object has no attribute 'get_UNL'

Something to do with the switch (yesterday or whenever) from position
based tree building, very slow for large objects like `c`, to vnode
based tree building, fast even for large objects.

Probably just needs a vnode -> position lookup for that case, getting
an UNL for a loop in the structure.

> >To introspect things not part of Leo, execute your code in the

I realized you can just introspect `c.vs` to find `myThing`, no need to
type `c.vs['myThing']`.

> ​I am going to think about the implications of all this. I find all
> such browsers kinda scary, but perhaps I am just an odd duck...I
> never, ever, think about programs at this low level. If I want to
> know the ivars defined in a class, for instance, I look in the ctor.

But then you miss all the stuff glued to c after the ctor, which might
be just as well :-), it's a long list.

Will have a quick poke at those bugs.

Cheers -Terry

Edward K. Ream

unread,
Sep 23, 2016, 2:30:25 PM9/23/16
to leo-editor
On Mon, May 16, 2016 at 2:40 PM, 'Terry Brown' via leo-editor <leo-e...@googlegroups.com> wrote:

https://github.com/leo-editor/snippets/blob/master/introspect.py
might be an object explorer, depending on your definition.

​Rev ​
 
​b455d3e adds this script as an @button node to scripts.leo.

Edward
Reply all
Reply to author
Forward
0 new messages