Skip to content

Commit b5e26c7

Browse files
Import pyOverrides before script (#1309)
* Import pyOverrides before script * Update translations * Always add overrides before script * Delete useless method * Update translations Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 3185b03 commit b5e26c7

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,25 +104,15 @@ void trik::TrikTextualInterpreter::interpretCommand(const QString &script)
104104
mScriptRunner.runDirectCommand(script);
105105
}
106106
107-
QString trik::TrikTextualInterpreter::addCodeAfterImport(const QString &script, const QString &addCode) const
108-
{
109-
QString updatedScript = script;
110-
int lastIndexOfImport = updatedScript.lastIndexOf(QRegularExpression("^import .*"
111-
, QRegularExpression::MultilineOption));
112-
int indexOf = updatedScript.indexOf(QRegularExpression("$", QRegularExpression::MultilineOption)
113-
, lastIndexOfImport);
114-
updatedScript.insert(indexOf + 1, addCode);
115-
return updatedScript;
116-
}
117-
118107
void trik::TrikTextualInterpreter::interpretScript(const QString &script, const QString &languageExtension)
119108
{
120109
mRunning = true;
121110
mBrick.processSensors(true);
122111
if (languageExtension.contains("js")) {
123112
mScriptRunner.run(jsOverrides + script);
124113
} else if (languageExtension.contains("py")) {
125-
mScriptRunner.run(addCodeAfterImport(script, pyOverrides), "dummyFile.py");
114+
auto updatedScript = script;
115+
mScriptRunner.run(updatedScript.insert(0, pyOverrides), "dummyFile.py");
126116
} else {
127117
reportError(tr("Unsupported script file type"));
128118
}
@@ -137,7 +127,8 @@ void trik::TrikTextualInterpreter::interpretScriptExercise(const QString &script
137127
if (languageExtension.contains("js")) {
138128
mScriptRunner.run(jsOverrides + "script.writeToFile = null;\n" + script);
139129
} else if (languageExtension.contains("py")) {
140-
mScriptRunner.run(addCodeAfterImport(script, pyOverrides + "\nscript.writeToFile = None\n"), "dummyFile.py");
130+
auto updatedScript = script;
131+
mScriptRunner.run(updatedScript.insert(0, pyOverrides + "\nscript.writeToFile = None\n"), "dummyFile.py");
141132
} else {
142133
reportError(tr("Unsupported script file type"));
143134
}

qrtranslations/fr/plugins/robots/trikKitInterpreterCommon_fr.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<context>
55
<name>QObject</name>
66
<message>
7-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+201"/>
7+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+192"/>
88
<source>Bogus input values</source>
99
<translation type="unfinished"></translation>
1010
</message>
@@ -230,8 +230,8 @@
230230
<context>
231231
<name>trik::TrikTextualInterpreter</name>
232232
<message>
233-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-96"/>
234-
<location line="+15"/>
233+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-97"/>
234+
<location line="+16"/>
235235
<source>Unsupported script file type</source>
236236
<translation type="unfinished"></translation>
237237
</message>

qrtranslations/ru/plugins/robots/trikKitInterpreterCommon_ru.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<context>
55
<name>QObject</name>
66
<message>
7-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+201"/>
7+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="+192"/>
88
<source>Bogus input values</source>
99
<translation>Неподходящие значения аргументов</translation>
1010
</message>
@@ -291,8 +291,8 @@
291291
<context>
292292
<name>trik::TrikTextualInterpreter</name>
293293
<message>
294-
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-96"/>
295-
<location line="+15"/>
294+
<location filename="../../../../plugins/robots/interpreters/trikKitInterpreterCommon/src/trikTextualInterpreter.cpp" line="-97"/>
295+
<location line="+16"/>
296296
<source>Unsupported script file type</source>
297297
<translation>Неверный формат файла</translation>
298298
</message>

0 commit comments

Comments
 (0)