runhey 3 лет назад
Родитель
Сommit
5003f140eb
7 измененных файлов с 82 добавлено и 1 удалено
  1. 7 1
      gui.py
  2. 15 0
      module/gui/Bridge.py
  3. 35 0
      module/gui/fluent_app.py
  4. 12 0
      module/gui/qml/app.qml
  5. BIN
      module/gui/res/logo.ico
  6. 10 0
      module/gui/utils.py
  7. 3 0
      module/logger.py

+ 7 - 1
gui.py

@@ -2,4 +2,10 @@
 # @author runhey
 # github https://github.com/runhey
 
-print("this gui.py")
+from module.gui.fluent_app import FluentApp
+
+if __name__ == "__main__":
+    # 检查是不是以管理员身份运行,脚本启动的其他进程会继承权限
+    # 启动一个UI交互的线程,因为信号槽不可跨进程
+    # 启动一个GUI
+    FluentApp().run()

+ 15 - 0
module/gui/Bridge.py

@@ -0,0 +1,15 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+
+from PySide6.QtCore import Qt, QObject
+
+class Bridge(QObject):
+    def __init__(self):
+        super().__init__()
+
+
+
+
+
+bridge = Bridge()

+ 35 - 0
module/gui/fluent_app.py

@@ -0,0 +1,35 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+import sys
+import os
+
+from PySide6.QtGui import QGuiApplication, QIcon
+from PySide6.QtQml import QQmlApplicationEngine
+from PySide6.QtCore import Qt, QObject
+from pathlib import Path
+
+from module.gui.utils import get_work_path
+from module.gui.Bridge import bridge
+
+class FluentApp():
+    app = None
+    engine = None
+
+    def __init__(self):
+        super().__init__()
+        # 适配高分辨率、声明、设置Logo、设置软件名字
+        QGuiApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.Round)
+        FluentApp.app = QGuiApplication(sys.argv)
+        QGuiApplication.setWindowIcon(QIcon(os.fspath(Path(__file__).resolve().parent / "res/logo.ico")))
+        QGuiApplication.setApplicationName("oas")
+        QGuiApplication.setOrganizationName("oas")
+
+
+    def run(self):
+        FluentApp.engine = QQmlApplicationEngine()
+        # FluentApp.engine.rootContext().setContextProperty("bridge", bridge)
+        FluentApp.engine.load(os.fspath(Path(get_work_path() / 'module' / 'gui' / 'qml' / 'app.qml')))
+        if not FluentApp.engine.rootObjects():
+            sys.exit(-1)
+        sys.exit(FluentApp.app.exec())

+ 12 - 0
module/gui/qml/app.qml

@@ -0,0 +1,12 @@
+import QtQuick 2.12
+import QtQuick.Controls 2.12
+import QtQuick.Window 2.12
+
+Window {
+    id:rootWindow
+    width: 700+8
+    height: 700+8 // +8是因为外阴影一边用了4
+    minimumWidth: 400
+    minimumHeight: 400
+    visible: true
+}

BIN
module/gui/res/logo.ico


+ 10 - 0
module/gui/utils.py

@@ -0,0 +1,10 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey
+from pathlib import Path
+
+def get_work_path() -> Path:
+    """
+    返回程序工作的目录如果没有问题的就是根目录
+    """
+    return Path.cwd()

+ 3 - 0
module/logger.py

@@ -0,0 +1,3 @@
+# This Python file uses the following encoding: utf-8
+# @author runhey
+# github https://github.com/runhey