I make my drawings in Krita while I write my report in TexStudio. In Krita I select part of the drawing and put it on the clipboard. I put my cursor in the .tex file at the desired position and run the macro.
The macro takes the current file name and passes it to a python script. The latter converts the clipboard content and saves it in a .png file (not in the python script I added below). The png file name is added to a string starting with \includegraphics ... . The latter string is returned by the python script to the macro. The macro should insert this TeX command string at the cursor position in the current .tex document.
The editor.insertText command DOES NOT insert the text in the open current .tex document where the macro is triggered but it writes the command in the "Messages" box. I added also the command for showing the return string from the Python script in an "alert" but this opens the alert box without content.
My simplified python script follows below:
#!/usr/bin/env python3
import os
import sys
def main(fn):
print(repr(str(fn)+"xxxx"),end="")
if __name__ == "__main__":
main("Hello World")
The macro code is the following:
var proc = system("/home/stefan/ARCHIVE/SCRIPTS/latex_automation/main.py");
proc.waitForFinished();
var output = proc.standardOutput;
// Ensure the editor is focused
app.focusEditor();
// Confirm editor is valid and insert
if (editor) {
editor.insertText(output);
} else {
QMessageBox.information(null, "Error", "No active .tex document found.");
}
alert(output)
cursor.insertText?