runhey 3 лет назад
Родитель
Сommit
cd370d0f3d

+ 30 - 0
module/base/log_highlighter.py

@@ -0,0 +1,30 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import re
+from html import escape
+
+def highlight_text(input_text):
+    color_mapping = {
+        r'\d{2}:\d{2}:\d{2}\.\d{3}': 'cyan',
+        r'\bTrue\b': 'lime',
+        r'\bFalse\b': 'red',
+        r'DEBUG': 'cyan',
+        r'INFO': 'green',
+        r'WARNING': 'yellow',
+        r'ERROR': 'red',
+        r'CRITICAL': 'darkred'
+    }
+
+    for pattern, color in color_mapping.items():
+        input_text = re.sub(pattern, f'<span style="color: {color}">\\g<0></span>', input_text)
+
+    return input_text + '<br>'
+
+# 测试
+# input_string = 'The time is 13:20:36.411. Is it True or False? DEBUG: This is a debug message. INFO: This is an info message. WARNING: This is a warning message. ERROR: This is an error message. CRITICAL: This is a critical message.'
+# highlighted_text = highlight_text(input_string)
+# html_text = f'<html><body>{highlighted_text}</body></html>'
+# print(html_text)
+
+

+ 3 - 3
module/gui/context/process_manager.py

@@ -21,6 +21,7 @@ from multiprocessing.managers import SyncManager
 # from multiprocessing import Queue
 from threading import Thread
 
+from module.base.log_highlighter import highlight_text
 from module.gui.process.script_process import ScriptProcess
 from module.config.config_menu import ConfigMenu
 from module.gui.context.add import Add
@@ -361,13 +362,13 @@ class ProcessManager(QObject):
             logger.info(f'Script {config_name} is not running')
             return
 
-        # while self.processes[config_name].is_alive():
         while self.log_thread[config_name].is_alive():
             try:
                 log = q.get(timeout=1)
                 if log is None:
                     continue
-                self.log_signal.emit(config_name, str(log))
+                log = highlight_text(str(log))
+                self.log_signal.emit(config_name, log)
 
             except Empty:
                 continue
@@ -403,7 +404,6 @@ class ProcessManager(QObject):
                     continue
 
                 logger.info(f'Update thread get')
-                print(update)
                 for key, value in update.items():
                     if "task" and "pending" and "waiting" in value:
                         self.sig_update_task.emit(key, json.dumps(value["task"]))

+ 147 - 31
module/gui/qml/Component/Overview.qml

@@ -2,10 +2,22 @@ import QtQuick
 import QtQuick.Controls
 import QtQuick.Layouts
 import FluentUI
+import "../Global"
 
 Item {
     id: root
     property string configName: ""
+    property var splitPanel: null  // 传入一个主控制的引用
+
+    Timer{
+        id: startInit
+        interval: 2500 // 定时器间隔为一秒
+        repeat: false // 设置为一次性定时器
+        onTriggered: {
+            // 停止定时器
+            setStatus(MainEvent.RunStatus.Free)
+        }
+    }
 
 
     Item{
@@ -36,10 +48,12 @@ Item {
                     onClicked: {
                         showSuccess("Restart"+" "+configName)
                         process_manager.restart(configName)
+                        startStart.selected = true
                         textLog.text = ""
                     }
                 }
                 FluToggleButton{
+                    id: startStart
                     Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
                     Layout.rightMargin: 16
                     text:"Start"
@@ -47,8 +61,7 @@ Item {
                     onClicked: {
                         selected = !selected
                         if(selected){
-                            text = "Start"
-                            textLog.text = ""
+                            text = "Start"                          
                             process_manager.stop_script(root.configName)
                         }else{
                             // 如果按键颜色变灰色
@@ -64,7 +77,7 @@ Item {
             anchors.top: schedulerOpen.bottom
             anchors.topMargin: 10
             width: parent.width
-            height: 120
+            height: 100
             ColumnLayout{
                 width: parent.width
                 spacing: 8
@@ -83,7 +96,11 @@ Item {
                 }
                 Taskmini{
                     id: task_running
+                    visible: false
                     Layout.leftMargin: 16
+                    onClick: {
+                        root.splitPanel.title = task_running.name
+                    }
                 }
             }
         }
@@ -93,35 +110,93 @@ Item {
             anchors.topMargin: 10
             width: parent.width
             height: 240
-            ColumnLayout{
-                width: parent.width
-                spacing: 8
-                FluText{
-                    text: 'Pending'
-                    Layout.leftMargin: 16
-                    Layout.topMargin: 6
-                    font: FluTextStyle.Subtitle
-                }
-                Rectangle{
-                    width: schedulerRunning.width - 20
-                    height: 2
-                    Layout.alignment: Qt.AlignHCenter
-                    color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
-                    radius: 2
+            FluText{
+                id: pendingText
+                anchors{
+                    top: parent.top
+                    topMargin: 6
+
                 }
-                Taskmini{
-                    Layout.leftMargin: 16
+                width: parent.width
+                text: 'Pending'
+                leftPadding: 16
+                font: FluTextStyle.Subtitle
+            }
+            Rectangle{
+                // 这个是一条横线
+                id: linePending
+                anchors{
+                    top: pendingText.bottom
+                    topMargin: 8
+                    horizontalCenter: parent.horizontalCenter
                 }
-                Taskmini{
-                    Layout.leftMargin: 16
+                width: schedulerRunning.width - 20
+                height: 2
+                color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
+                radius: 2
+            }
+            ListView{
+                id: pendingListView
+                anchors{
+                    top: linePending.bottom
+                    topMargin: 8
+                    bottom: parent.bottom
+                    bottomMargin: 8
+                    horizontalCenter: parent.horizontalCenter
                 }
-                Taskmini{
-                    Layout.leftMargin: 16
+
+                width: 225
+                height: 200
+                clip: true
+                spacing: 8
+                model: ListModel{
+                    id: pendingListModel
                 }
-                Taskmini{
-                    Layout.leftMargin: 16
+                delegate: Component{
+                    Taskmini{
+                        name: model.name
+                        nextRun: model.next_run
+                        onClick: {
+                            root.splitPanel.title = model.name
+                        }
+                    }
                 }
             }
+
+//            ColumnLayout{
+//                width: parent.width
+//                spacing: 8
+//                FluText{
+//                    text: 'Pending'
+//                    Layout.leftMargin: 16
+//                    Layout.topMargin: 6
+//                    font: FluTextStyle.Subtitle
+//                }
+//                Rectangle{
+//                    // 这个是一条横线
+//                    width: schedulerRunning.width - 20
+//                    height: 2
+//                    Layout.alignment: Qt.AlignHCenter
+//                    color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
+//                    radius: 2
+//                }
+//                ListView{
+//                    id: pendingListView
+//                    Layout.alignment: Qt.AlignHCenter
+//                    width: 225
+//                    height: 200
+//                    spacing: 8
+//                    model: ListModel{
+//                        id: pendingListModel
+//                    }
+//                    delegate: Component{
+//                        Taskmini{
+//                            name: model.name
+//                            nextRun: model.next_run
+//                        }
+//                    }
+//                }
+//            }
         }
         FluArea{
             id: schedulerWaiting
@@ -129,7 +204,8 @@ Item {
             anchors.topMargin: 10
             anchors.bottom: parent.bottom
             anchors.bottomMargin: 0
-            width: parent.width
+            width: parent.width                  
+
             ColumnLayout{
                 width: parent.width
                 spacing: 8
@@ -148,9 +224,25 @@ Item {
                     color: FluTheme.dark ? Qt.rgba(64/255, 68/255, 75/255, 1) : Qt.rgba(234/255, 236/255, 239/255, 1)
                     radius: 2
                 }
-                Taskmini{
-                    Layout.leftMargin: 16
-                    Layout.fillHeight: false
+                ListView{
+                    id: waitingListView
+                    Layout.fillHeight: true
+                    Layout.alignment: Qt.AlignHCenter
+                    width: 225
+                    clip: true
+                    spacing: 8
+                    model: ListModel{
+                        id: waitingListModel
+                    }
+                    delegate: Component{
+                        Taskmini{
+                            name: model.name
+                            nextRun: model.next_run
+                            onClick: {
+                                root.splitPanel.title = model.name
+                            }
+                        }
+                    }
                 }
             }
         }
@@ -173,6 +265,7 @@ Item {
                 Layout.alignment: Qt.AlignVCenter | Qt.AlignLeft
             }
             OverStatus{
+                id: overStatus
                 Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
             }
             FluToggleButton{
@@ -207,7 +300,8 @@ Item {
             padding: 10
             clip: true
             wrapMode: Text.WordWrap // 设置自动换行模式
-            text: ""
+            textFormat: Text.RichText
+            text: ''
 
             function add_log(config, log){
                 if(config !== root.configName){
@@ -228,6 +322,7 @@ Item {
         process_manager.sig_update_task.connect(update_task)
         process_manager.sig_update_pending.connect(update_pending)
         process_manager.sig_update_waiting.connect(update_waiting)
+        startInit.start()
     }
     function update_task(config, data){
         if(typeof data !== "string"){
@@ -248,6 +343,15 @@ Item {
         if(config !== configName){
             return
         }
+        if(data === "[]"){
+            pendingListModel.clear()
+            return
+        }
+        pendingListModel.clear()
+        const d = JSON.parse(data)
+        for(var item of d){
+            pendingListModel.append(item)
+        }
     }
     function update_waiting(config, data){
         if(typeof data !== "string"){
@@ -257,5 +361,17 @@ Item {
         if(config !== configName){
             return
         }
+        if(data === "[]"){
+            waitingListModel.clear()
+            return
+        }
+        waitingListModel.clear()
+        const d = JSON.parse(data)
+        for(var item of d){
+            waitingListModel.append(item)
+        }
+    }
+    function setStatus(s){
+        overStatus.runStatus = s
     }
 }

+ 11 - 1
module/gui/qml/Component/SplitPanel.qml

@@ -35,6 +35,15 @@ Item {
         anchors.top: parent.top
         anchors.bottom: parent.bottom
         anchors.bottomMargin: 12
+
+        onLoaded: {
+            if(typeof contentDefalut.item.splitPanel === "undefined"){
+                console.debug('还没有属性')
+                return
+            }
+
+            contentDefalut.item.splitPanel = menuArea.parent
+        }
     }
     Loader{
         id: contentLoader
@@ -83,8 +92,9 @@ Item {
 
     //设置固定的部分的具体内容  主要是传一个组件
     function setDefalut(component){
-        contentDefalut.sourceComponent = component
+        contentDefalut.sourceComponent = component 
         showDefalut()
+
     }
     //
     function setLoader(component){

+ 3 - 1
module/gui/qml/Component/Taskmini.qml

@@ -12,6 +12,7 @@ Item {
 
     property alias name: taskName.text
     property alias nextRun: taskTime.text
+    signal click(string title)
 
     FluText{
         id: taskName
@@ -44,7 +45,8 @@ Item {
         }
         text:"setting"
         onClicked: {
-             showSuccess("setting")
+            showSuccess(name)
+            root.click(configName)
         }
     }
     // 使用这个的前提是 data 是字符串

+ 9 - 2
script.py

@@ -218,8 +218,15 @@ class Script:
         if self.gui_update_task is not None:
             self.gui_update_task(data)
 
-
-
+    def _gui_set_status(self, status: str) -> None:
+        """
+        设置给gui显示的状态
+        :param status: 可以在gui中显示的状态 有 "Init", "Empty"(不显示), "Run"(运行中), "Error", "Free"(空闲)
+        :return:
+        """
+        data = {"status": status}
+        if self.gui_update_task is not None:
+            self.gui_update_task(data)
 
     def wait_until(self, future):
         """