Browse Source

2.0.7.60

master
ming.hong 1 year ago
parent
commit
9e68a43f8c
  1. 92
      Aida/python.html

92
Aida/python.html

@ -186,6 +186,7 @@
<div class="progress" style="background-color:white">
<div class="progress-bar progress-bar-striped" style="min-width: 20px;visibility:hidden;"></div>
</div>
<div style="border:1px gray solid;padding:5px;margin:5px 5px 5px 5px;height: 560px;">
<div id="container" style="height: 100vh; display: flex;">
@ -281,12 +282,10 @@
var getPythonBufferSize = 64;
var getBufferStatusTemp = null;
var getBufferSignal = null;
//var displayDataCounter = 0;
var currentRunningFile = ''; // temp running file name
var g_isPythonRunning = 0;
var pythoncode = ""
var currentFileName = '';
// 初始化為 null,確保 intervalId 定義過
var intervalId = null; // Ming add 2024/08/22
var autoScroll = true; // Ming 2024-08-29
var isUserScrolling = false; // Ming 2024-08-29
@ -295,30 +294,28 @@
// 取得語系
func_get_lang_cookie();
// 當網頁加載完成後自動載入 hello.py
window.onload = function() { // Ming add 2024/08/22
// 修改 window.onload 使用 async/await
window.onload = async function() {
// 確認之前執行狀態
func_enablePythonfile();
await func_enablePythonfile();
// 確認有無回傳的資料
func_getPythonStatus();
// 確認是否有 python 文件正在執行
if (currentRunningFile.endsWith('.py'))
{
func_FileGet(currentRunningFile);
func_getFileList(currentRunningFile);
currentFileName = currentRunningFile;
}
else
{
currentFileName = 'hello.py';
// 加載文件列表並選中 hello.py
func_FileGet(currentFileName);
// 自動加載並顯示 hello.py 的內容
func_getFileList(currentFileName);
}
// 加載文件列表並選中 python
func_FileGet(currentFileName);
// 自動加載並顯示 python 的內容
func_getFileList(currentFileName);
};
// 初始化 CodeMirror
var editor = CodeMirror.fromTextArea(document.getElementById('code-textarea'), {
lineNumbers: true,
@ -776,44 +773,37 @@
});
return false;
}
// 取得 config.json 中 enable_python_file 的值
function func_enablePythonfile() { // Ming 2024-10-04
$.ajax({
url: "/getconfigfile?ch=all",
type: "GET",
async: true,
beforeSend: function (xmlHttp) {
xmlHttp.setRequestHeader("If-Modified-Since", "0");
xmlHttp.setRequestHeader("Cache-Control", "no-cache");
//xmlHttp.setRequestHeader("Authorization", "Basic " + btoa("username:password"));
},
success: function (retdata) {
var jsonbuf = JSON.parse(retdata);
if ("enable_python_file" in jsonbuf["system_setting"]) {
currentRunningFile = jsonbuf["system_setting"]["enable_python_file"];
g_isPythonRunning = 1;
if (currentRunningFile.endsWith('.py'))
{
$('#console').html("Execute unfinished python file !!");
$('#console').append('&#13;&#10;'); // 換行
$('#console').append("Running...");
$('#console').append('&#13;&#10;'); // 換行
console.log("find enable python file !!!!!!!!!!!!!! ");
}
else
{
console.log("not found enable python file !!!!!!!!!!!!!! ");
// 使用 Promise 取得 config.json 中 enable_python_file 的值後返回
function func_enablePythonfile() {
return new Promise((resolve, reject) => {
$.ajax({
url: "/getconfigfile?ch=all",
type: "GET",
async: true,
beforeSend: function (xmlHttp) {
xmlHttp.setRequestHeader("If-Modified-Since", "0");
xmlHttp.setRequestHeader("Cache-Control", "no-cache");
},
success: function (retdata) {
var jsonbuf = JSON.parse(retdata);
if ("enable_python_file" in jsonbuf["system_setting"]) {
currentRunningFile = jsonbuf["system_setting"]["enable_python_file"];
g_isPythonRunning = 1;
if (currentRunningFile.endsWith('.py')) {
$('#console').html("Execute unfinished python file !!");
$('#console').append('&#13;&#10;'); // 換行
$('#console').append("Running...");
$('#console').append('&#13;&#10;'); // 換行
console.log("find enable python file !!!!!!!!!!!!!! ");
}
}
} else {
console.log("not found enable python setting");
resolve(); // 結束後解析 Promise
},
error: function (retdata) {
console.warn(retdata);
reject(retdata); // 發生錯誤時拒絕 Promise
}
},
error: function (retdata) {
// setTimeout(func_enablePythonfile(), 3000);
console.warn(retdata);
}
});
});
}
// 新建檔案

Loading…
Cancel
Save