Error passing argument to pyotherside [answered]
I'm stuck on an error in an app I'm writing. It will (eventually) SSH to a server and issue commands which I will generate by tapping buttons on my Jolla C. (The server is a headless bananaPi running the xmms2 music player.)
To issue commands to a command shell I have a python module (based on the SDK python example). I want to send it a command to pass to the shell and have it send stdout back to the qml to display.
I've already tested that tapping the button runs the python function, that it can issue a command to the shell, and that it will send stdout back to the qml and display it. I now want to generalise it by passing the command (ssh, xmms2 play, etc) to the python function as a argument. But I cannot get the argument-passing to work. I expect there's some basic error but I cannot see it.
Here is the relevant qml. The button called Connect will issue an ssh command, though for testing it issues just 'ls'.
Row {
Button {
text: "Connect"
onClicked: python.connect("ls")
}
Python {
id: python
Component.onCompleted: {
addImportPath(Qt.resolvedUrl('.'));
importModule('commander', function(){});
}
function connect(cmd) {
var cmdarg = 'args=["'+cmd+'"]';
console.log(cmdarg);
call('commander.command.issuecommand', cmdarg, function(){});
}
Here is the python module:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import pyotherside
import tempfile
import subprocess
class Command:
def __init__(self):
pass
def issuecommand(self, cmd):
output=""
with tempfile.TemporaryFile() as outfile:
subprocess.call(cmd, stdout=outfile)
outfile.seek(0)
output=outfile.read()
pyotherside.send(output)
command = Command()
And here's the error. The first line is the console.log showing the value of the 2nd argument to the call.
[D] connect:66 - args=["ls"]
[D] unknown:0 - "PyOtherSide error: issuecommand() missing 1 required positional argument: 'cmd'"
[D] onError:72 - python error: Return value of PyObject call is NULL: issuecommand() missing 1 required positional argument: 'cmd'
@cy8aer Many thanks. This works:
call('commander.command.issuecommand', [cmd], function(){});
I had interpreted the spec to mean that args= was a keyword argument:
https://pyotherside.readthedocs.io/en/latest/index.html#call
A supplementary question:
DaveRo ( 2018-10-31 20:28:14 +0200 )editI'm displaying the stdout text in a TextArea field, but it shouldn't be editable. I really want a multi-line display field but I don't see one here:
https://sailfishos.org/develop/docs/silica/sailfish-silica-all.html/#text-display-and-input
What to use?
Use Label? Probably you can find more help with my podqast application: https://gitlab.com/cy8aer/podqast
cy8aer ( 2018-10-31 20:34:15 +0200 )edit