And here is the entire client main loop using commander methods instead of
c.k.simulateCommand():
async def client_main_loop(timeout):
uri = f"ws://{wsHost}:{wsPort}"
async with websockets.connect(uri) as websocket: # pylint:
disable=no-member
# Await the startup package.
json_s = g.toUnicode(await websocket.recv())
request_package = {
"id": 4,
"action": '!send_outline', # New command for leoserver
"param": {'path': r'c:\temp\leo\zettel_cmds.leo'}
}
n = 0
request = json.dumps(request_package, separators=(',', ':'))
await websocket.send(request)
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 we are interested in
continue
if 'outline' in d:
file = d['outline']
print('outline length:', len(file))
c1 = c.new()
c1.pasteOutlineRetainingClones(None, file)
break
On Saturday, March 12, 2022 at 3:36:21 PM UTC-5 [email protected] wrote:
> 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/27311040-d2aa-4350-99a7-8c6ddd30a1aan%40googlegroups.com.