mirror of
https://github.com/x-tools-author/x-tools.git
synced 2025-09-15 15:28:40 +08:00
chore: update the file
This commit is contained in:
parent
a0fc00081d
commit
9280b93e66
@ -2,7 +2,7 @@
|
||||
|
||||
while true do
|
||||
print("Current time: " .. os.date("%H:%M:%S"))
|
||||
x_read_write(os.date("%H:%M:%S") .. "\n")
|
||||
x_write(os.date("%H:%M:%S") .. "\n")
|
||||
|
||||
ret = x_is_interruption_requested()
|
||||
if ret then
|
||||
|
||||
@ -106,6 +106,7 @@ Page::Page(ControllerDirection direction, QSettings *settings, QWidget *parent)
|
||||
&QPushButton::clicked,
|
||||
this,
|
||||
&Page::onPushButtonExternalPanelClicked);
|
||||
connect(ui->widgetScripts, &ScriptsManager::invokeWrite, this, &Page::inputBytes);
|
||||
|
||||
if (direction == ControllerDirection::Right) {
|
||||
QHBoxLayout *l = qobject_cast<QHBoxLayout *>(layout());
|
||||
@ -287,8 +288,12 @@ QToolButton *Page::presetToolButton()
|
||||
|
||||
void Page::inputBytes(const QByteArray &bytes)
|
||||
{
|
||||
if (m_deviceController->device()) {
|
||||
m_deviceController->device()->writeBytes(bytes);
|
||||
auto device = m_deviceController ? m_deviceController->device() : nullptr;
|
||||
if (device && device->isRunning()) {
|
||||
device->writeBytes(bytes);
|
||||
} else {
|
||||
QString msg = tr("Error: No device is opened.");
|
||||
ui->textBrowserOutput->append(QString("<span style=\"color:#FF0000;\">%1</span>").arg(msg));
|
||||
}
|
||||
}
|
||||
|
||||
@ -592,6 +597,7 @@ void Page::onBytesRead(const QByteArray &bytes, const QString &from)
|
||||
ui->tabTransfers->inputBytes(cookedBytes);
|
||||
}
|
||||
|
||||
ui->widgetScripts->onBytesRead(bytes);
|
||||
emit bytesRead(cookedBytes, cookedFrom);
|
||||
}
|
||||
|
||||
|
||||
@ -20,16 +20,20 @@ ScriptBase::ScriptBase(QWidget *parent)
|
||||
, ui(new Ui::ScriptBase)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->toolButtonRun->setCheckable(true);
|
||||
|
||||
connect(ui->comboBoxFile,
|
||||
qOverload<int>(&QComboBox::currentIndexChanged),
|
||||
this,
|
||||
&ScriptBase::onScriptComboBoxCurrentIndexChanged);
|
||||
connect(ui->toolButtonOpen, &QToolButton::clicked, this, &ScriptBase::onRunButtonClicked);
|
||||
connect(ui->toolButtonRun, &QToolButton::clicked, this, &ScriptBase::onRunButtonClicked);
|
||||
connect(ui->toolButtonNew, &QToolButton::clicked, this, &ScriptBase::onNewButtonClicked);
|
||||
connect(ui->toolButtonDir, &QToolButton::clicked, this, &ScriptBase::onOpenButtonClicked);
|
||||
connect(ui->toolButtonRefresh, &QToolButton::clicked, this, &ScriptBase::onRefreshButtonClicked);
|
||||
connect(ui->toolButtonHelp, &QToolButton::clicked, this, &ScriptBase::onHelpButtonClicked);
|
||||
connect(ui->textEditScript, &QTextEdit::textChanged, this, &ScriptBase::onScriptTextChanged);
|
||||
|
||||
onRunnerFinished();
|
||||
}
|
||||
|
||||
ScriptBase::~ScriptBase()
|
||||
@ -44,6 +48,13 @@ void ScriptBase::loadScripts()
|
||||
loadScriptsUser();
|
||||
}
|
||||
|
||||
void ScriptBase::onBytesRead(const QByteArray &data)
|
||||
{
|
||||
if (m_runner) {
|
||||
m_runner->onBytesRead(data);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList ScriptBase::ignoredFiles() const
|
||||
{
|
||||
return QStringList();
|
||||
@ -95,7 +106,8 @@ void ScriptBase::onScriptComboBoxCurrentIndexChanged()
|
||||
|
||||
void ScriptBase::onRunButtonClicked(bool checked)
|
||||
{
|
||||
ui->toolButtonOpen->setEnabled(false);
|
||||
qInfo() << "ScriptBase::onRunButtonClicked" << checked;
|
||||
ui->toolButtonRun->setEnabled(false);
|
||||
if (checked) {
|
||||
startRunner();
|
||||
} else {
|
||||
@ -163,15 +175,13 @@ void ScriptBase::startRunner()
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_runner, &QThread::finished, this, [this]() {
|
||||
ui->toolButtonOpen->setEnabled(true);
|
||||
updateUiEnabled(false);
|
||||
});
|
||||
connect(m_runner, &QThread::started, this, [this]() {
|
||||
ui->toolButtonOpen->setEnabled(true);
|
||||
updateUiEnabled(true);
|
||||
});
|
||||
m_runner->start();
|
||||
connect(m_runner, &QThread::finished, this, &ScriptBase::onRunnerFinished);
|
||||
connect(m_runner, &QThread::started, this, &ScriptBase::onRunnerStarted);
|
||||
connect(m_runner, &ScriptRunner::logOutput, ui->textBrowserLog, &QTextBrowser::append);
|
||||
connect(m_runner, &ScriptRunner::invokeWrite, this, &ScriptBase::invokeWrite);
|
||||
|
||||
const QString fileName = ui->comboBoxFile->currentData().toString();
|
||||
m_runner->execute(fileName);
|
||||
}
|
||||
|
||||
void ScriptBase::stopRunner()
|
||||
@ -190,4 +200,40 @@ void ScriptBase::updateUiEnabled(bool running)
|
||||
ui->toolButtonNew->setEnabled(!running);
|
||||
ui->toolButtonRefresh->setEnabled(!running);
|
||||
ui->textEditScript->setEnabled(!running);
|
||||
}
|
||||
|
||||
void ScriptBase::onRunnerStarted()
|
||||
{
|
||||
ui->toolButtonRun->setEnabled(true);
|
||||
updateUiEnabled(true);
|
||||
|
||||
ui->toolButtonRun->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::MediaPlaybackStop));
|
||||
ui->toolButtonRun->setToolTip(tr("Stop the script"));
|
||||
}
|
||||
|
||||
void ScriptBase::onRunnerFinished()
|
||||
{
|
||||
ui->toolButtonRun->setEnabled(true);
|
||||
updateUiEnabled(false);
|
||||
|
||||
ui->toolButtonRun->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::MediaPlaybackStart));
|
||||
ui->toolButtonRun->setToolTip(tr("Run the script"));
|
||||
}
|
||||
|
||||
void ScriptBase::onScriptTextChanged()
|
||||
{
|
||||
QString fileName = ui->comboBoxFile->currentData().toString();
|
||||
QString txt = ui->textEditScript->toPlainText();
|
||||
if (fileName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(fileName);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray ba = txt.toUtf8();
|
||||
file.write(ba);
|
||||
file.close();
|
||||
}
|
||||
@ -23,6 +23,10 @@ public:
|
||||
~ScriptBase() override;
|
||||
|
||||
void loadScripts();
|
||||
void onBytesRead(const QByteArray &data);
|
||||
|
||||
signals:
|
||||
void invokeWrite(const QByteArray &data);
|
||||
|
||||
protected:
|
||||
virtual ScriptRunner *newRunner() = 0;
|
||||
@ -45,6 +49,9 @@ private:
|
||||
void startRunner();
|
||||
void stopRunner();
|
||||
void updateUiEnabled(bool running);
|
||||
void onRunnerStarted();
|
||||
void onRunnerFinished();
|
||||
void onScriptTextChanged();
|
||||
|
||||
private:
|
||||
Ui::ScriptBase *ui = nullptr;
|
||||
|
||||
@ -57,7 +57,7 @@
|
||||
<item row="0" column="1">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="1">
|
||||
<widget class="QToolButton" name="toolButtonOpen">
|
||||
<widget class="QToolButton" name="toolButtonRun">
|
||||
<property name="text">
|
||||
<string notr="true">...</string>
|
||||
</property>
|
||||
|
||||
@ -53,6 +53,8 @@ void ScriptRunnerLua::run()
|
||||
lua_register(m_lua, "x_sleep", &ScriptRunnerLua::luaSleep);
|
||||
lua_register(m_lua, "x_is_interruption_requested", &ScriptRunnerLua::luaIsInterruptionRequested);
|
||||
|
||||
qInfo() << "Executing Lua script:" << m_scriptFile;
|
||||
|
||||
int ret = luaL_dofile(m_lua, m_scriptFile.toUtf8().constData());
|
||||
if (ret != LUA_OK) {
|
||||
const char *errorMsg = lua_tostring(m_lua, -1);
|
||||
|
||||
@ -24,6 +24,9 @@ ScriptsManager::ScriptsManager(QWidget *parent)
|
||||
|
||||
m_lua->loadScripts();
|
||||
m_js->loadScripts();
|
||||
|
||||
connect(m_lua, &ScriptLua::invokeWrite, this, &ScriptsManager::invokeWrite);
|
||||
connect(m_js, &ScriptJs::invokeWrite, this, &ScriptsManager::invokeWrite);
|
||||
}
|
||||
|
||||
ScriptsManager::~ScriptsManager()
|
||||
@ -37,3 +40,9 @@ QJsonObject ScriptsManager::load()
|
||||
}
|
||||
|
||||
void ScriptsManager::save(const QJsonObject &obj) {}
|
||||
|
||||
void ScriptsManager::onBytesRead(const QByteArray &data)
|
||||
{
|
||||
m_lua->onBytesRead(data);
|
||||
m_js->onBytesRead(data);
|
||||
}
|
||||
@ -28,6 +28,11 @@ public:
|
||||
QJsonObject load();
|
||||
void save(const QJsonObject &obj);
|
||||
|
||||
void onBytesRead(const QByteArray &data);
|
||||
|
||||
signals:
|
||||
void invokeWrite(const QByteArray &data);
|
||||
|
||||
private:
|
||||
Ui::ScriptsManager *ui = nullptr;
|
||||
ScriptLua *m_lua = nullptr;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user