更新 UpdateFPGA 界面的翻译
This commit is contained in:
+40
-42
@@ -27,7 +27,7 @@ UpdateFPGA::~UpdateFPGA()
|
||||
|
||||
void UpdateFPGA::init()
|
||||
{
|
||||
setWindowTitle("升级工具");
|
||||
setWindowTitle(tr("升级工具"));
|
||||
setMinimumSize(600, 400);
|
||||
|
||||
QLabel* Logo = new QLabel(this);
|
||||
@@ -38,7 +38,7 @@ void UpdateFPGA::init()
|
||||
m_Title = new QLabel(this);
|
||||
m_Title->setStyleSheet("font-family:\"Microsoft YaHei\";color:#333333;font-size:16px;");
|
||||
m_Title->setFixedHeight(25);
|
||||
m_Title->setText("升级工具");
|
||||
m_Title->setText(tr("升级工具"));
|
||||
|
||||
m_CloseBtn = new QPushButton(this);
|
||||
m_CloseBtn->setFixedSize(25, 25);
|
||||
@@ -62,10 +62,10 @@ void UpdateFPGA::init()
|
||||
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout(this);
|
||||
m_UpdateButton = new QPushButton("开始升级", this);
|
||||
m_UpdateButton = new QPushButton(tr("开始升级"), this);
|
||||
m_UpdateButton->setFixedHeight(30);
|
||||
|
||||
logLabel = new QLabel("升级日志:", this);
|
||||
logLabel = new QLabel(tr("升级日志:"), this);
|
||||
logTextEdit = new QTextEdit(this);
|
||||
logTextEdit->setReadOnly(true);
|
||||
|
||||
@@ -95,29 +95,29 @@ void UpdateFPGA::startUpdate()
|
||||
m_CloseBtn->setEnabled(false);
|
||||
if (m_PythonScriptPath.isEmpty())
|
||||
{
|
||||
logTextEdit->append("错误: 脚本为空");
|
||||
logTextEdit->append(tr("错误: 脚本为空"));
|
||||
return;
|
||||
}
|
||||
QFile inputFile(m_PythonScriptPath);
|
||||
if (!inputFile.exists())
|
||||
{
|
||||
logTextEdit->append(QString("错误: 脚本不存在 - %1").arg(m_PythonScriptPath));
|
||||
logTextEdit->append(tr("错误: 脚本不存在 - %1").arg(m_PythonScriptPath));
|
||||
return;
|
||||
}
|
||||
|
||||
logTextEdit->append("开始升级...");
|
||||
logTextEdit->append(QString("文件:%1").arg(m_PythonScriptPath));
|
||||
logTextEdit->append(tr("开始升级..."));
|
||||
logTextEdit->append(tr("文件:%1").arg(m_PythonScriptPath));
|
||||
|
||||
// 自动查找Ubuntu 22.04中可用的Python解释器
|
||||
QString pythonPath = findValidPythonInterpreter();
|
||||
if (pythonPath.isEmpty())
|
||||
{
|
||||
logTextEdit->append("错误: 未找到可用的Python解释器或缺少serial模块");
|
||||
logTextEdit->append(tr("错误: 未找到可用的Python解释器或缺少serial模块"));
|
||||
m_CloseBtn->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
logTextEdit->append(QString("使用Python解释器: %1").arg(pythonPath));
|
||||
logTextEdit->append(tr("使用Python解释器: %1").arg(pythonPath));
|
||||
|
||||
QStringList pythonArgs;
|
||||
pythonArgs << m_PythonScriptPath;
|
||||
@@ -203,7 +203,7 @@ bool UpdateFPGA::isValidPythonWithSerial(const QString& pythonPath)
|
||||
|
||||
if (!testProcess.waitForFinished(3000) || testProcess.exitCode() != 0)
|
||||
{
|
||||
logTextEdit->append(QString("调试: 无效的Python解释器 - %1").arg(pythonPath));
|
||||
logTextEdit->append(tr("调试: 无效的Python解释器 - %1").arg(pythonPath));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -214,17 +214,17 @@ bool UpdateFPGA::isValidPythonWithSerial(const QString& pythonPath)
|
||||
if (testProcess.exitCode() == 0)
|
||||
{
|
||||
QString output = testProcess.readAll().trimmed();
|
||||
logTextEdit->append(QString("调试: %1").arg(output));
|
||||
logTextEdit->append(tr("调试: %1").arg(output));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
logTextEdit->append(QString("调试: %1 缺少serial模块").arg(pythonPath));
|
||||
logTextEdit->append(tr("调试: %1 缺少serial模块").arg(pythonPath));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logTextEdit->append(QString("调试: %1 响应超时").arg(pythonPath));
|
||||
logTextEdit->append(tr("调试: %1 响应超时").arg(pythonPath));
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -235,16 +235,16 @@ QString UpdateFPGA::getErrorDescription(int errorCode)
|
||||
{
|
||||
switch (errorCode)
|
||||
{
|
||||
case 1: return "文件不存在(请检查FPGA固件文件路径)";
|
||||
case 2: return "无可用串口(请检查设备连接)";
|
||||
case 3: return "串口通信错误(可能是波特率不匹配或设备断开)";
|
||||
case 4: return "数据发送失败(尝试重新发送)";
|
||||
case 5: return "数据校验失败(数据传输过程中损坏)";
|
||||
case 6: return "接收数据不完整(可能是传输中断)";
|
||||
case 7: return "文件大小发送失败(协议握手错误)";
|
||||
case 8: return "文件内容发送失败(大文件传输超时)";
|
||||
case 9: return "未知错误(请查看详细日志)";
|
||||
default: return "未定义错误";
|
||||
case 1: return tr("文件不存在(请检查FPGA固件文件路径)");
|
||||
case 2: return tr("无可用串口(请检查设备连接)");
|
||||
case 3: return tr("串口通信错误(可能是波特率不匹配或设备断开)");
|
||||
case 4: return tr("数据发送失败(尝试重新发送)");
|
||||
case 5: return tr("数据校验失败(数据传输过程中损坏)");
|
||||
case 6: return tr("接收数据不完整(可能是传输中断)");
|
||||
case 7: return tr("文件大小发送失败(协议握手错误)");
|
||||
case 8: return tr("文件内容发送失败(大文件传输超时)");
|
||||
case 9: return tr("未知错误(请查看详细日志)");
|
||||
default: return tr("未定义错误");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,23 +254,21 @@ void UpdateFPGA::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
{
|
||||
if (exitCode == 0) // 成功(错误码0)
|
||||
{
|
||||
logTextEdit->append("升级成功!");
|
||||
QMessageBox::information(this, "成功", "FPGA升级完成,请重启QtUI", QMessageBox::Ok);
|
||||
logTextEdit->append(tr("升级成功!"));
|
||||
QMessageBox::information(this, tr("成功"), tr("FPGA升级完成,请重启QtUI"), QMessageBox::Ok);
|
||||
close(); // 成功后关闭界面
|
||||
emit upgradeFPGAFinished();
|
||||
}
|
||||
else // 有错误码的失败
|
||||
{
|
||||
QString errorDesc = getErrorDescription(exitCode);
|
||||
logTextEdit->append(QString("升级失败,错误码: %1,原因: %2")
|
||||
.arg(exitCode).arg(errorDesc));
|
||||
logTextEdit->append(tr("升级失败,错误码: %1,原因: %2").arg(exitCode).arg(errorDesc));
|
||||
|
||||
// 询问用户是否重试(针对可恢复错误)
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this,
|
||||
"升级失败",
|
||||
QString("错误码%1: %2\n是否重新尝试升级?")
|
||||
.arg(exitCode).arg(errorDesc),
|
||||
tr("升级失败"),
|
||||
tr("错误码%1: %2\n是否重新尝试升级?").arg(exitCode).arg(errorDesc),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::Yes)
|
||||
@@ -288,11 +286,11 @@ void UpdateFPGA::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||
}
|
||||
else // 进程异常退出(无错误码)
|
||||
{
|
||||
logTextEdit->append(QString("升级进程异常退出,退出码: %1").arg(exitCode));
|
||||
logTextEdit->append(tr("升级进程异常退出,退出码: %1").arg(exitCode));
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this,
|
||||
"进程异常",
|
||||
"升级过程中程序崩溃,是否重新尝试?",
|
||||
tr("进程异常"),
|
||||
tr("升级过程中程序崩溃,是否重新尝试?"),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
|
||||
if (reply == QMessageBox::Yes)
|
||||
@@ -315,32 +313,32 @@ void UpdateFPGA::processError(QProcess::ProcessError error)
|
||||
switch (error)
|
||||
{
|
||||
case QProcess::FailedToStart:
|
||||
errorMsg = "错误: 无法启动脚本(可能是Python环境未配置)";
|
||||
errorMsg = tr("错误: 无法启动脚本(可能是Python环境未配置)");
|
||||
break;
|
||||
case QProcess::Crashed:
|
||||
errorMsg = "错误: 脚本进程崩溃";
|
||||
errorMsg = tr("错误: 脚本进程崩溃");
|
||||
break;
|
||||
case QProcess::Timedout:
|
||||
errorMsg = "错误: 启动超时(设备无响应)";
|
||||
errorMsg = tr("错误: 启动超时(设备无响应)");
|
||||
break;
|
||||
case QProcess::WriteError:
|
||||
errorMsg = "错误: 写入进程失败(权限不足)";
|
||||
errorMsg = tr("错误: 写入进程失败(权限不足)");
|
||||
break;
|
||||
case QProcess::ReadError:
|
||||
errorMsg = "错误: 读取进程输出失败";
|
||||
errorMsg = tr("错误: 读取进程输出失败");
|
||||
break;
|
||||
case QProcess::UnknownError:
|
||||
default:
|
||||
errorMsg = "错误: 未知错误";
|
||||
errorMsg = tr("错误: 未知错误");
|
||||
break;
|
||||
}
|
||||
|
||||
logTextEdit->append(errorMsg);
|
||||
logTextEdit->append("错误详情: " + conversionProcess->readAllStandardError());
|
||||
logTextEdit->append(tr("错误详情: ") + QString::fromLocal8Bit(conversionProcess->readAllStandardError()));
|
||||
|
||||
// 进程错误时也提示重试
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, "操作错误", errorMsg + "\n是否重新尝试?", QMessageBox::Yes | QMessageBox::No);
|
||||
reply = QMessageBox::question(this, tr("操作错误"), errorMsg + tr("\n是否重新尝试?"), QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply == QMessageBox::Yes)
|
||||
{
|
||||
startUpdate();
|
||||
|
||||
Reference in New Issue
Block a user