Re: cool things: python-fire

2018-11-16 Thread Edward K. Ream
On Sun, Nov 4, 2018 at 12:10 PM Matt Wilkie  wrote:

> Drop this in the "cool things seen out there" and "probably room for this
> in my toolkit" bins:
>
> *Python-fire  -*
> *a library for automatically generating command line interfaces (CLIs)
> from absolutely any Python object. *
>

Interesting. I've added it to my long list of urls in the tools folder.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: OMG: the LeoApp class needs no outline data!

2018-11-16 Thread Edward K. Ream
On Tue, Nov 13, 2018 at 7:52 PM pimgeek  wrote:

> Sounds very promising!
>
> A related question to ask:
>
> Can I turn Leo Editor App into a Leo Data Server by install the leoflexx
> plugin? (and then in theory I can access the data via Web Browser from
> every machine on the internet) :-O
>
> Recently I try to bind Leo Data to a one-page WebApp via package eel
> , and I also noticed package flexx
> . Is that related to leoflexx.py? :-)
>

Yes.  leoflexx uses flexx.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: leoflexx.py: Wow: the Root class crosses the Py/JS divide

2018-11-16 Thread Edward K. Ream
On Friday, November 16, 2018 at 6:40:13 AM UTC-6, Edward K. Ream wrote:

All of the wrapper classes will instantiate their own instances of Root.  
> This will allow them to call flx.actions as needed. In fact, the wrappers 
> will need to call only these actions:
>
> - Redraw the screen.
> - Update the body text.
> - Write something to the log.
> - Update the status line.
>

I forgot what is arguably the most important action: selecting a position.

Here is how this plays out.  The following is tested code, at rev b5572fcea.

The LeoBrowserTree wrapper overrides NullTree.select, which is actually the 
all-important (and hairy) LeoTree.select method. 

def select(self, p):
'''Override NullTree.select, which is actually LeoTree.select.'''
# Call LeoTree.select.'''
super().select(p)
# Call app.select_p.
self.root.select_p(p)

app.select_p is in the LeoApp class.  It is:

@flx.action
def select_p(self, p):
'''
Select the position in the tree.

Called from LeoBrowserTree.select,
so do *not* call c.frame.tree.select.
'''
print('app.select_p', repr(p.h))
w = self.main_window
ap = self.p_to_ap(p)
w.tree.select_ap(ap)

And finally, LeoFlexxTree.select_ap should actually select the headline.  A 
complete redraw would work.  At present, it simply prints the requested ap:

@flx.action
def select_ap(self, ap):
print('tree.select_ap', self.root.dump_ap(ap))

Executing "select" command in the minibuffer executes this code:

h = 'Active Unit Tests'
p = g.findTopLevelNode(c, h, exact=True)
self.gui.frame.tree.select(p)

And the output is:

app.select_p 'Active Unit Tests'
JS: tree.select_ap
ap: childIndex: 3   v: ekr.20101220161557.6016 stack: [] Active Unit 
Tests

*Summary*

This working example illustrates the scale of the remaining work.

Only a few new methods in all the wrappers will need to be overridden. They 
will be as simple as LeoBrowserTree.select, and they will call simple 
actions in LeoApp.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


leoflexx.py: Wow: the Root class crosses the Py/JS divide

2018-11-16 Thread Edward K. Ream
A previous post 
 shows 
how Leo's wrapper classes can *use* flx.PyComponents without *being* 
components themselves.  So Leo's wrappers are *plain python classes *that 
inherit from Leo's base classes.  It's a huge collapse in complexity.

In this post, I'll show how Leo's wrappers can access *all* the actions on 
*both* sides of the Py/JS divide. It's an amazing pattern that every flexx 
programmer should know.

Here is the present LeoBrowserGui wrapper class. To repeat, this class is 
*not* a flexx component:

class LeoBrowserGui(leoGui.NullGui):

def __init__ (self, c):
super().__init__(guiName='BrowserGui')
self.c = c
self.last_frame = LeoBrowserFrame(c)
self.root = Root()

def echo(self):
self.root.echo('From LeoBrowser Gui')

def tree_echo(self):
self.root.main_window.tree.echo('From LeoBrowser Gui')

Using the Root class, the *plain *echo and tree_echo methods can 
successfully call the echo *actions* in the LeoApp class (a 
flx.PyComponent) and the LeoFlexxTree class (a flx.Widget) !!

Wow. Think about that for a moment or three.

And here is the Root class:

class Root(flx.PyComponent):
'''
This class allows *plain* python classes
to access *component* classes.
'''

def __getattr__ (self, attr):
return getattr(self.root, attr)

*Example*

Executing "echo" from the minibuffer executes this code in app.do_command:

print('app.do_command: %s' % command)
self.gui.echo()
self.gui.tree_echo()

The resulting output is:

app.do_command: echo
= echo = From LeoBrowser Gui
  ## Output from the Py side.
JS: = tree echo = From LeoBrowser Gui
  ## Output from the JS side.

*Discussion*

__getattr__ is a standard technique. By itself, it's no big deal.

But the effect is spectacular.  The Root class allows *plain *python 
methods to execute flexx actions on either side of the Py/JS divide. 

The "echo" and "tree_echo" *methods *become *pseudo-actions*. That's why 
the Root class is in The Book.

All of the wrapper classes will instantiate their own instances of Root.  
This will allow them to call flx.actions as needed. In fact, the wrappers 
will need to call only these actions:

- Redraw the screen.
- Update the body text.
- Write something to the log.
- Update the status line.

The LeoWapp project is nearing completion.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.


Re: Wow: take a look at leoflexx.py

2018-11-16 Thread Edward K. Ream
On Thu, Nov 15, 2018 at 7:54 PM lewis  wrote:

> Running commit 90ab77da2f1a
> C:\~\AppData\Local\Programs\Python\Python37>python
> N:\git\leo-editor\leo\plugins\leoflexx.py --flexx-webruntime=edge-browser
>
> I see this traceback:
> Traceback (most recent call last):
>   File "N:\git\leo-editor\leo\plugins\leoflexx.py", line 14, in 
> import leo.core.leoBridge as leoBridge
> ModuleNotFoundError: No module named 'leo'
>
> Has been happening since commit f23e799ca.
>

I doubt this commit is at fault.  Make sure you run your test script from a
directory in which import leo succeeds. You can test this by opening python
and trying the import above.

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 leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.