Quellcode durchsuchen

feat(gui): replace stackview with swipeview

runhey vor 3 Jahren
Ursprung
Commit
232178f223

+ 5 - 5
module/config/config.py

@@ -17,9 +17,7 @@ from module.config.utils import *
 from module.logger import logger
 
 class Config(ConfigState, ConfigManual, ConfigWatcher, ConfigMenu):
-    """
-    一个配置文件的集成类
-    """
+
     def __init__(self, config_name: str, task=None) -> None:
         """
 
@@ -45,12 +43,12 @@ class Config(ConfigState, ConfigManual, ConfigWatcher, ConfigMenu):
             logger.error(f'can not ask this variable {name}')
             return None  # 或者抛出异常,或者返回其他默认值
 
-    def gui_args(self) -> str:
+    def gui_args(self, task: str) -> str:
         """
         获取给gui显示的参数
         :return:
         """
-        return self.model.gui_task()
+        return self.model.gui_task(task=task)
 
     def get_arg(self, task: str, group: str, argument: str):
         """
@@ -83,5 +81,7 @@ if __name__ == '__main__':
     config = Config(config_name='pydantic')
     print(config.menu)
     print(config.config_name)
+
+    config.script.device.serial = 123
     print(config.script.device.serial)
 

+ 1 - 1
module/config/config_model.py

@@ -78,4 +78,4 @@ if __name__ == "__main__":
         print(e)
         c = ConfigModel()
     print(c.json())
-    # c.write_json('pydantic', json.loads(c.gui_task('Script')))
+    # c.write_json('pydantic', c.schema())

BIN
module/config/i18n/en_US.qm


+ 2 - 2
module/config/i18n/en_US.ts

@@ -16,11 +16,11 @@
     </message>
     <message>
         <source>about</source>
-        <translation>关于</translation>
+        <translation>about</translation>
     </message>
     <message>
         <source>settings</source>
-        <translation>about</translation>
+        <translation>settings</translation>
     </message>
 </context>
 <context>

BIN
module/gui/FluentUI/fluentuiplugin.dll


+ 42 - 1
module/gui/context/process_manager.py

@@ -124,4 +124,45 @@ class ProcessManager(QObject):
         """
         for config in self.processes:
             self.processes[config].restart()
-        logger.info(f'restart all script')
+        logger.info(f'restart all script')
+
+    def get_client(self, config: str) -> zerorpc.Client:
+        """
+        get_client
+        :param config:
+        :return:
+        """
+        if config in self.clients:
+            return self.clients[config]
+        else:
+            logger.info(f'script {config} is not running')
+            return None
+
+    @Slot(str, result="QString")
+    def gui_menu(self, config: str) -> str:
+        """
+        get_gui_menu
+        :param config:
+        :return:
+        """
+        if config in self.clients:
+            return self.clients[config].gui_menu()
+        else:
+            logger.info(self.clients)
+            logger.info(f'script {config} is not running')
+            return None
+
+    @Slot(str, str, result="QString")
+    def gui_args(self, config: str, task: str) -> str:
+        """
+        获取显示task的gui参数
+        :param config:
+        :param task:
+        :return:
+        """
+        if config in self.clients:
+            return self.clients[config].gui_args(task)
+        else:
+            logger.info(f'script {config} is not running')
+            return None
+

+ 17 - 1
module/gui/qml/Component/ScriptItem.qml

@@ -6,6 +6,22 @@ FluPaneItem{
     title: "home"
     icon:FluentIcons.Play36
     onTap:{
-        navigationView.push(Qt.resolvedUrl("../../qml/Page/ScriptView.qml"))
+//        var component = Qt.createComponent("../../qml/Page/ScriptView.qml")
+//        if (component.status === Component.Ready) {
+//            var object = component.createObject(navigationView);
+
+//            if (object !== null) {
+//                object.configName = title
+//                // 创建成功,可以进行操作
+//                console.debug('创建成功')
+//                navigationView.push(object)
+
+//            }else{
+//                // 创建失败
+//            }
+//        }else{
+//            // 组件加载失败
+//        }
+    navigationView.pushScript(Qt.resolvedUrl("../../qml/Page/ScriptView.qml"), title)
     }
 }

+ 3 - 0
module/gui/qml/Component/SplitPanel.qml

@@ -57,6 +57,9 @@ Item {
             }else{
                 var da = []
                 for(var item in data[items]){
+                    if (typeof data[items][item] !== "string") {
+                      continue
+                    }
                     da.push(menu_tree.createItem(qsTr(data[items][item]), false))
                 }
                 datas.push(menu_tree.createItem(qsTr(items), true, da))

+ 2 - 1
module/gui/qml/Global/ItemsFooter.qml

@@ -32,7 +32,8 @@ FluObject{
         icon:FluentIcons.Settings
         onTap:{
             Qt.Pa
-            navigationView.push(Qt.resolvedUrl("../../qml/Page/O_Settings.qml"))
+//            navigationView.push(Qt.resolvedUrl("../../qml/Page/O_Settings.qml"))
+            navigationView.pushScript(Qt.resolvedUrl("../../qml/Page/O_Settings.qml"), "settings")
         }
     }
 

+ 2 - 1
module/gui/qml/Global/ItemsOriginal.qml

@@ -12,7 +12,8 @@ FluObject{
         title: qsTr("home")
         icon:FluentIcons.Home
         onTap:{
-            navigationView.push(Qt.resolvedUrl("../../qml/Page/O_Home.qml"))
+//            navigationView.push(Qt.resolvedUrl("../../qml/Page/O_Home.qml"))
+            navigationView.pushScript(Qt.resolvedUrl("../../qml/Page/O_Home.qml"), "home")
         }
     }
     function getRecentlyAddedData(){

+ 1 - 0
module/gui/qml/Page/Home.qml

@@ -4,6 +4,7 @@ import FluentUI
 
 FluScrollablePage{
     spacing: 6
+
     Image {
         id: name
         Layout.preferredHeight: 40

+ 2 - 0
module/gui/qml/Page/O_Home.qml

@@ -9,6 +9,8 @@ import "../Component"
 
 SplitPanel{
 
+    property string configName: ""
+
     onTitleChanged: {
         if(title === qsTr("Home")){
             var comp = Qt.createComponent("../../qml/Page/Home.qml")

+ 2 - 0
module/gui/qml/Page/O_Settings.qml

@@ -12,6 +12,8 @@ FluScrollablePage{
     bottomPadding:20
     spacing: 0
 
+    property string configName: ""
+
     FluArea{
         Layout.fillWidth: true
         Layout.topMargin: 0

+ 15 - 3
module/gui/qml/Page/ScriptView.qml

@@ -7,6 +7,7 @@ import "../Global"
 SplitPanel{
 
     property string configName: ""
+
     onTitleChanged: {
         if(title === qsTr("Overview")){
             showDefalut()
@@ -21,17 +22,28 @@ SplitPanel{
         }
     }
 
+    onConfigNameChanged: {
+        if(configName === ""){
+            console.info('configname is emtry')
+            return
+        }
+        var data = JSON.parse(process_manager.gui_menu(configName))
+        create(data)
+    }
+
 
     Component.onCompleted:{
-        var data = {'Overview':[], 'Script': ['Script', 'General', 'Restart']}
-        create(data)
+
+
+//        var data = {'Overview':[], 'Script': ['Script', 'General', 'Restart']}
+
 
         var component = Qt.createComponent("../../qml/Component/Overview.qml")
         if (component.status === Component.Ready) {
             setDefalut(component)
         } else {
             // 组件加载失败
-            console.debug('组件加载失败')
+            console.debug('组件!加载失败')
         }
     }
 }

+ 15 - 0
script.py

@@ -61,3 +61,18 @@ class Script:
         """
         self.server.run()
 
+    def gui_args(self, task: str) -> str:
+        """
+        获取给gui显示的参数
+        :return:
+        """
+        return self.config.gui_args(task=task)
+
+    def gui_menu(self) -> str:
+        """
+        获取给gui显示的菜单
+        :return:
+        """
+        return self.config.gui_menu
+
+