From 22eb38029377ffc1833cac022639be6767533d70 Mon Sep 17 00:00:00 2001 From: waaake Date: Mon, 28 Oct 2024 15:48:26 +0530 Subject: [PATCH] [ui] ScriptEditor: Updated Script Editor layout ScriptEditor is now part of a ColumnLayout in an MSplitView allowing more control over what is being viewed. --- meshroom/ui/qml/GraphEditor/ScriptEditor.qml | 167 ++++++++++--------- 1 file changed, 90 insertions(+), 77 deletions(-) diff --git a/meshroom/ui/qml/GraphEditor/ScriptEditor.qml b/meshroom/ui/qml/GraphEditor/ScriptEditor.qml index 35c5a85bda..f283b331c1 100644 --- a/meshroom/ui/qml/GraphEditor/ScriptEditor.qml +++ b/meshroom/ui/qml/GraphEditor/ScriptEditor.qml @@ -11,19 +11,49 @@ import QtQuick.Dialogs 1.3 Item { id: root + function replace(text, string, replacement) { + /* + * Replaces all occurences of the string in the text + * @param text - overall text + * @param string - the string to be replaced in the text + * @param replacement - the replacement of the string + */ + // Split with the string + let lines = text.split(string) + // Return the overall text joined with the replacement + return lines.join(replacement) + } + function formatInput(text) { - var lines = text.split("\n") - for (let i = 0; i < lines.length; ++i) { - lines[i] = ">>> " + lines[i] - } - return lines.join("\n") + /* + * Formats the text to be displayed as the input script executed + */ + + // Replace the text to be RichText Supportive + return "" + replace(text, "\n", "
") + "


" + } + + function formatOutput(text) { + /* + * Formats the text to be displayed as the result of the script executed + */ + + // Replace the text to be RichText Supportive + return "" + "Result: " + replace(text, "\n", "
") + "


" } - function processScript() { - output.clear() - var ret = ScriptEditorManager.process(input.text) - output.text = formatInput(input.text) + "\n\n" + ret - input.clear() + function processScript(text = "") { + // Use either the provided/selected or the entire script + text = text || input.text + + // Execute the process and fetch back the return for it + var ret = ScriptEditorManager.process(text) + + // Append the input script and the output result to the output console + output.append(formatInput(text) + formatOutput(ret)) + + // Save the entire script after executing the commands + ScriptEditorManager.saveScript(input.text) } function loadScript(fileUrl) { @@ -82,12 +112,8 @@ Item { RowLayout { Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter - Item { - Layout.fillWidth: true - } - MaterialToolButton { - font.pointSize: 13 + font.pointSize: 18 text: MaterialIcons.download ToolTip.text: "Load Script" @@ -97,7 +123,7 @@ Item { } MaterialToolButton { - font.pointSize: 13 + font.pointSize: 18 text: MaterialIcons.upload ToolTip.text: "Save Script" @@ -112,7 +138,7 @@ Item { MaterialToolButton { id: executeButton - font.pointSize: 13 + font.pointSize: 18 text: MaterialIcons.slideshow ToolTip.text: "Execute Script" @@ -122,7 +148,7 @@ Item { } MaterialToolButton { - font.pointSize: 13 + font.pointSize: 18 text: MaterialIcons.cancel_presentation ToolTip.text: "Clear Output Window" @@ -136,7 +162,7 @@ Item { } MaterialToolButton { - font.pointSize: 13 + font.pointSize: 18 text: MaterialIcons.history ToolTip.text: "Get Previous Script" @@ -151,7 +177,7 @@ Item { } MaterialToolButton { - font.pointSize: 13 + font.pointSize: 18 text: MaterialIcons.update ToolTip.text: "Get Next Script" @@ -166,7 +192,7 @@ Item { } MaterialToolButton { - font.pointSize: 13 + font.pointSize: 18 text: MaterialIcons.backspace ToolTip.text: "Clear History" @@ -182,31 +208,50 @@ Item { } } - RowLayout { - Label { - text: "Input" - font.bold: true - horizontalAlignment: Text.AlignHCenter - Layout.fillWidth: true - } + MSplitView { + id: topBottomSplit + Layout.fillHeight: true + Layout.fillWidth: true - Label { - text: "Output" - font.bold: true - horizontalAlignment: Text.AlignHCenter - Layout.fillWidth: true - } - } + orientation: Qt.Vertical + + // Output Text Area -- Shows the output for the executed script(s) + Rectangle { + id: outputArea - RowLayout { - Layout.fillWidth: true - Layout.fillHeight: true - width: root.width + // Has a minimum height + SplitView.minimumHeight: 80 + + color: palette.base + + Flickable { + width: parent.width + height: parent.height + contentWidth: width + contentHeight: ( output.lineCount + 5 ) * output.font.pixelSize // + 5 lines for buffer to be scrolled and visibility + + ScrollBar.vertical: MScrollBar {} + + TextArea.flickable: TextArea { + id: output + readOnly: true + selectByMouse: true + padding: 0 + Layout.fillHeight: true + Layout.fillWidth: true + wrapMode: Text.WordWrap + + textFormat: Text.RichText + } + } + } + + // Input Text Area -- Holds the input scripts to be executed Rectangle { id: inputArea - Layout.fillHeight: true - Layout.fillWidth: true + + SplitView.fillHeight: true color: palette.base @@ -253,7 +298,7 @@ Item { width: parent.width height: parent.height contentWidth: width - contentHeight: height + contentHeight: ( input.lineCount + 5 ) * input.font.pixelSize // + 5 lines for buffer to be scrolled and visibility anchors.left: lineNumbers.right anchors.top: parent.top @@ -265,13 +310,8 @@ Item { TextArea.flickable: TextArea { id: input - text: { - var str = "from meshroom.ui import uiInstance\n\n" - str += "graph = uiInstance.activeProject.graph\n" - str += "for node in graph.nodes:\n" - str += " print(node.name)" - return str - } + text: ScriptEditorManager.loadLastScript() + font: lineNumbers.textMetrics.font Layout.fillHeight: true Layout.fillWidth: true @@ -286,7 +326,7 @@ Item { Keys.onPressed: { if ((event.key === Qt.Key_Enter || event.key === Qt.Key_Return) && event.modifiers === Qt.ControlModifier) { - processScript() + processScript(input.selectedText) } } } @@ -298,33 +338,6 @@ Item { } } } - - Rectangle { - id: outputArea - Layout.fillHeight: true - Layout.fillWidth: true - - color: palette.base - - Flickable { - width: parent.width - height: parent.height - contentWidth: width - contentHeight: height - - ScrollBar.vertical: MScrollBar {} - - TextArea.flickable: TextArea { - id: output - - readOnly: true - selectByMouse: true - padding: 0 - Layout.fillHeight: true - Layout.fillWidth: true - } - } - } } } } \ No newline at end of file