Skip to content

Commit

Permalink
Add Run after upload support for JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
MinyazevR committed Feb 27, 2025
1 parent 244004f commit 8f2e890
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ private slots:
/// Reenables buttons when program uploading or robot stopping is complete (sucessfully or with error).
void onProtocolFinished();

/// Runs after upload if needed
void onUploadSuccess();

private:
/// Disables "run", "upload" and "stop" buttons when there is pending command to a robot.
void disableButtons();
Expand Down Expand Up @@ -116,6 +119,8 @@ private slots:

/// Protocol that is used to stop robot.
QScopedPointer<utils::robotCommunication::StopRobotProtocol> mStopRobotProtocol;

QFileInfo mMainFile;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#include <utils/robotCommunication/networkCommunicationErrorReporter.h>
#include <qrgui/textEditor/qscintillaTextEdit.h>
#include <qrgui/textEditor/textManagerInterface.h>

#include <qrkernel/settingsManager.h>
#include <qrutils/widgets/qRealMessageBox.h>
#include "trikQtsMasterGenerator.h"
#include "emptyShell.h"

Expand Down Expand Up @@ -86,7 +87,7 @@ void TrikQtsGeneratorPluginBase::init(const kitBase::KitPluginConfigurator &conf
, this, &TrikQtsGeneratorPluginBase::onProtocolFinished);

connect(mUploadProgramProtocol.data(), &UploadProgramProtocol::success
, this, &TrikQtsGeneratorPluginBase::onProtocolFinished);
, this, &TrikQtsGeneratorPluginBase::onUploadSuccess);
connect(mRunProgramProtocol.data(), &RunProgramProtocol::success
, this, &TrikQtsGeneratorPluginBase::onProtocolFinished);
connect(mStopRobotProtocol.data(), &StopRobotProtocol::success
Expand Down Expand Up @@ -215,6 +216,9 @@ void TrikQtsGeneratorPluginBase::uploadProgram()
}
if (!files.isEmpty()) {
disableButtons();
if (auto code = dynamic_cast<text::QScintillaTextEdit *>(mMainWindowInterface->currentTab())) {
mMainFile = QFileInfo(mTextManager->path(code));
}
mUploadProgramProtocol->run(files);
} else {
mMainWindowInterface->errorReporter()->addError(
Expand Down Expand Up @@ -254,8 +258,41 @@ void TrikQtsGeneratorPluginBase::stopRobot()
}
}

void TrikQtsGeneratorPluginBase::onUploadSuccess()
{
auto runPolicy = static_cast<RunPolicy>(SettingsManager::value("trikRunPolicy").toInt());
switch (runPolicy) {
case RunPolicy::Ask:
if (utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
, tr("The program has been uploaded")
, tr("Do you want to run it?")
) != QMessageBox::Yes) {
break;
}
Q_FALLTHROUGH();
case RunPolicy::AlwaysRun:
if (mMainFile != QFileInfo()) {
if (mRunProgramProtocol) {
mRunProgramProtocol->run(mMainFile);
return;
} else {
QLOG_ERROR() << "Run program protocol is not initialized";
}
} else {
utils::QRealMessageBox::question(mMainWindowInterface->windowWidget()
,tr("Error"), tr("Unknown file to run after upload, please run manually"),
QMessageBox::Ok);
}
break;
case RunPolicy::NeverRun:
break;
}
onProtocolFinished();
}

void TrikQtsGeneratorPluginBase::onProtocolFinished()
{
mMainFile = QFileInfo();
mUploadProgramAction->setEnabled(true);
mRunProgramAction->setEnabled(true);
mStopRobotAction->setEnabled(true);
Expand Down
2 changes: 1 addition & 1 deletion qrtranslations/fr/plugins/robots/interpreterCore_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@
<translation>Aucune extension n&apos;est chargée</translation>
</message>
<message>
<location line="+134"/>
<location line="+138"/>
<source>No robot models available for </source>
<translation>Modèle de robot n&apos;est pas défini dans l&apos;extension</translation>
</message>
Expand Down
24 changes: 22 additions & 2 deletions qrtranslations/fr/plugins/robots/trikPythonGeneratorLibrary_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<context>
<name>trik::python::TrikPythonGeneratorPluginBase</name>
<message>
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+73"/>
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+75"/>
<source>Network operation timed out</source>
<translation type="unfinished"></translation>
</message>
Expand Down Expand Up @@ -118,9 +118,29 @@
<translation type="unfinished"></translation>
</message>
<message>
<location line="+72"/>
<location line="+76"/>
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location line="+51"/>
<source>The program has been uploaded</source>
<translation>Le téléversement du programme est terminé</translation>
</message>
<message>
<location line="+1"/>
<source>Do you want to run it?</source>
<translation>Est-ce que vous voulez l&apos;executer ?</translation>
</message>
<message>
<location line="+15"/>
<source>Error</source>
<translation>Erreur</translation>
</message>
<message>
<location line="+0"/>
<source>Unknown file to run after upload, please run manually</source>
<translation>Fichier inconnu à exécuter après le téléchargement, veuillez l&apos;exécuter manuellement</translation>
</message>
</context>
</TS>
2 changes: 1 addition & 1 deletion qrtranslations/ru/plugins/robots/interpreterCore_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
<translation>Не загружено ни одного плагина с описанием робоплатформы</translation>
</message>
<message>
<location line="+134"/>
<location line="+138"/>
<source>No robot models available for </source>
<translation>Ни одной модели робота не найдено в плагине </translation>
</message>
Expand Down
24 changes: 22 additions & 2 deletions qrtranslations/ru/plugins/robots/trikPythonGeneratorLibrary_ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<context>
<name>trik::python::TrikPythonGeneratorPluginBase</name>
<message>
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+73"/>
<location filename="../../../../plugins/robots/generators/trik/trikPythonGeneratorLibrary/src/trikPythonGeneratorPluginBase.cpp" line="+75"/>
<source>Network operation timed out</source>
<translation>Не удалось получить ответ от робота, проверьте настройки, проверьте, включён ли робот</translation>
</message>
Expand Down Expand Up @@ -118,9 +118,29 @@
<translation>Остановить выполнение программы для TRIK</translation>
</message>
<message>
<location line="+72"/>
<location line="+76"/>
<source>There are no files to upload. You must open or generate at least one *.js or *.py file.</source>
<translation>Нет файлов для загрузки. Вы должны открыть или сгенерировать хотя бы один *.js или *.py файл.</translation>
</message>
<message>
<location line="+51"/>
<source>The program has been uploaded</source>
<translation>Загрузка завершена</translation>
</message>
<message>
<location line="+1"/>
<source>Do you want to run it?</source>
<translation>Хотите ли Вы запустить эту программу?</translation>
</message>
<message>
<location line="+15"/>
<source>Error</source>
<translation>Ошибка</translation>
</message>
<message>
<location line="+0"/>
<source>Unknown file to run after upload, please run manually</source>
<translation>Не удалось запустить программу после загрузки, пожалуйста, попробуйте запустить программу напрямую</translation>
</message>
</context>
</TS>

0 comments on commit 8f2e890

Please sign in to comment.