Skip to content

Commit

Permalink
[ui] ScriptEditor: Updated Script Editor layout
Browse files Browse the repository at this point in the history
ScriptEditor is now part of a ColumnLayout in an MSplitView allowing more control over what is being viewed.
  • Loading branch information
waaake committed Oct 28, 2024
1 parent 3e0024e commit 22eb380
Showing 1 changed file with 90 additions and 77 deletions.
167 changes: 90 additions & 77 deletions meshroom/ui/qml/GraphEditor/ScriptEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<font color=#868686>" + replace(text, "\n", "<br>") + "</font><br><br>"
}

function formatOutput(text) {
/*
* Formats the text to be displayed as the result of the script executed
*/

// Replace the text to be RichText Supportive
return "<font color=#49a1f3>" + "Result: " + replace(text, "\n", "<br>") + "</font><br><br>"
}

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) {
Expand Down Expand Up @@ -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"

Expand All @@ -97,7 +123,7 @@ Item {
}

MaterialToolButton {
font.pointSize: 13
font.pointSize: 18
text: MaterialIcons.upload
ToolTip.text: "Save Script"

Expand All @@ -112,7 +138,7 @@ Item {

MaterialToolButton {
id: executeButton
font.pointSize: 13
font.pointSize: 18
text: MaterialIcons.slideshow
ToolTip.text: "Execute Script"

Expand All @@ -122,7 +148,7 @@ Item {
}

MaterialToolButton {
font.pointSize: 13
font.pointSize: 18
text: MaterialIcons.cancel_presentation
ToolTip.text: "Clear Output Window"

Expand All @@ -136,7 +162,7 @@ Item {
}

MaterialToolButton {
font.pointSize: 13
font.pointSize: 18
text: MaterialIcons.history
ToolTip.text: "Get Previous Script"

Expand All @@ -151,7 +177,7 @@ Item {
}

MaterialToolButton {
font.pointSize: 13
font.pointSize: 18
text: MaterialIcons.update
ToolTip.text: "Get Next Script"

Expand All @@ -166,7 +192,7 @@ Item {
}

MaterialToolButton {
font.pointSize: 13
font.pointSize: 18
text: MaterialIcons.backspace
ToolTip.text: "Clear History"

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
}
}
Expand All @@ -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
}
}
}
}
}
}

0 comments on commit 22eb380

Please sign in to comment.