Scriptomatix add some features to Qml language. They are avaliable from parameters pannel.
- A file read/write class (binding QFile).
- A fork process class (binding QProcess).
- An environment variable reader (bindings getenv and gethostname).
- Internal variables and functions access.
Read/write file
Class : QmlFile 0.1
Properties :
- source : string - File name
- text : string - File content
Signals :
- sourceChanged(string) - Emitted on file name change
- textChanged(string) - Emitted when read data ready
Methods :
- read()
- write()
- exists()
- setSource(string) - Change file name
- setText(string) - Change file content
Example :
import QmlFile 0.1
FileIO { id: io }
function writeFile(filename,content) {
io.setSource(filename);
io.setText(content);
io.write();
}
function readFile(filename) {
io.setSource(filename);
if (io.exists()) {
io.read();
return io.text;
} else {
return "";
}
}
take a look at /usr/share/scriptomatix/examples/Ping-list.qml
Launch process
Class : QmlProcess 0.1
Properties :
- shell : string - Shell name
- command : string - Command line
Signals :
- shellChanged(string) - Emitted when shell name changed
- commandChanged(string) - Emitted when command line changed
- finished(exitcode) - End of execution signal
- readyReadStandardError() - Data ready on stderr
- readyReadStandardOutput() - Data ready on stdout
- started() - Script started signal
Methods :
- start() - Start process
- terminate() - Stop process (SIGTERM)
- kill() - Kill process (SIGKILL)
- running() - Process state
- readAllStandardError() - Read all avaliable data from stderr
- readAllStandardOutput() - Read all avaliable data from stdout
- setShell(string) - Change shell
- setCommand(string) - Change command line
Example :
import QmlProcess 0.1
Process {
id: myprocess
shell: "/bin/bash"
command: "ls *.txt"
onFinished: mytext.text = myprocess.readAllStandardOutput()
}
Text {
id: mytext
anchors.margins: 5
anchors.fill: parent;
}
Component.onCompleted: {
myprocess.start();
}
Environment variables
Class : QmlEnvVars 0.1
Methods :
- getVar(string name) : string - Return environment variable name value
- getHostName() : string - Return host name
Example :
import QmlEnvVars 0.1
ShellEnv { id: environment }
Text {
id: mytext
anchors.margins: 5
anchors.fill: parent;
text: environment.getVar("HOME")
}
take a look at /usr/share/scriptomatix/examples/FileInfo.qml
Internal variables and functions access
- sx_scriptargs - Command line parameters.
- sx_scriptpath - Current path.
- sx_execAction.trigger() - Trigger current script execution.
Example :
sx_scriptargs = str; // Set global variable sx_scriptargs
sx_execAction.trigger(); // Trigger script execution
take a look at /usr/share/scriptomatix/examples/Ping-radio.qml function updateParams