I've actually got this working (as a rough proof-of-principle).  I added a 
new command to leoserver: send_outline(self, param). My tiny client sends a 
file path to leoserver, which reads the file and sends the resulting string 
back to the client, which copies it to the clipboard.  The client then 
simulates the "new" command  and then the "paste-retaining-clones"  command 
to that new outline. 

The only thing is that the outline gets pasted in as a sibling of the empty 
node that gets put there when the new outline is created.  There must be 
some simple way to insert at the top of the outline, but I don't know what 
that is yet.  Anyway, in practice we'd probably like to use commander 
methods instead of simulating commands.  But it's almost usable this way, 
modulo error handling and getting the remote file path into the client 
script.

def send_outline(self, param):
    filename = param.get('path', '')
    result = ''
    if filename and os.path.exists(filename):
        with open(filename) as f:
            result = f.read()
    data = {"outline": result}
    return self._make_response(data)

In the client main loop:
# ...
        while n < 6:
            n += 1
            json_s = g.toUnicode(await websocket.recv())
            d = json.loads(json_s)
            id = d.get('id', '??')
            if id != 4:   # the id of my request
                continue
            if 'outline' in d:
                file = d['outline']
                print('outline length:', len(file))
                g.app.gui.replaceClipboardWith(file)
                c.k.simulateCommand('new')
                c1 = g.app.commanders()[-1]
                c1.k.simulateCommand('paste-retaining-clones')
            return
        return

In practice I suppose we wouldn't want to return from the client this way 
because we wouldn't want to shut down the remote leoserver instance.

On Saturday, March 12, 2022 at 8:31:35 AM UTC-5 [email protected] wrote:

> On Saturday, March 12, 2022 at 8:23:14 AM UTC-5 [email protected] wrote:
>
>> It seems to me that almost everything we need already exists except for 
>> the actual  acquire-from-the-leoserver. part.
>>
>
> For instance, once Leo has the bytes from the other computer, loading them 
> is essentially the  existing CreateOutline + PasteAsClone  operations.  
> Sending the changed outline back is essentially copyNode, then SendBytes 
> (the only new part).
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/4b802ee1-7bec-4776-bbb4-e0ca1e630eaan%40googlegroups.com.

Reply via email to