浏览代码

close_other_window

rambo 7 月之前
父节点
当前提交
c7ba8891f9
共有 2 个文件被更改,包括 20 次插入15 次删除
  1. 17 1
      python/api.py
  2. 3 14
      python/mcu/DeviceControl.py

+ 17 - 1
python/api.py

@@ -22,7 +22,8 @@ import importlib
 from service.auto_deal_pics.upload_pic import UploadPic
 from service.OnePicTest import OnePicTest
 import hashlib
-
+import win32api, win32gui, win32con
+from win32gui import EnumWindows, GetWindowText
 
 # from service.AutoDealPics import AutoDealPics
 # for plugin in settings.plugins:
@@ -648,3 +649,18 @@ def delete_logo(params: LogoParamsupdate):
     for logoItem in logo_files:
         logo_list.append(f"{logo_dir}{logoItem}")
     return {"code": 0, "msg": "操作成功", "data": logo_list}
+
+
+@app.post("/close_other_window", description="关闭窗口")
+def close_other_window():
+    hwnd_list = []
+    def callback(hwnd, _):
+        title = GetWindowText(hwnd)
+        if title == "digiCamControl by Duka Istvan":
+            hwnd_list.append(hwnd)
+    EnumWindows(callback, None)
+    if hwnd_list:
+        hwnd = hwnd_list[0]
+        win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
+        return {"code": 0, "msg": "关闭成功", "data": {"status":True}}
+    return {"code": 0, "msg": "关闭失败", "data": {"status": False}}

+ 3 - 14
python/mcu/DeviceControl.py

@@ -15,8 +15,7 @@ from databases import insert_photo_records
 from .McuDeviationSet import McuDeviationSet
 from .OtherSet import OtherSet
 from .DebugUart import DebugUart
-import win32api, win32gui, win32con
-from win32gui import EnumWindows, GetWindowText
+
 # mcu命令
 class DeviceControl(BaseClass, metaclass=SingletonType):
     lock = threading.Lock()
@@ -133,17 +132,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         )
         self.msg_type = "mcu"
 
-    def close_other_window(self):
-        hwnd_list = []
-        def callback(hwnd, _):
-            title = GetWindowText(hwnd)
-            if title == "digiCamControl by Duka Istvan":
-                hwnd_list.append(hwnd)
-        EnumWindows(callback, None)
-        if hwnd_list:
-            hwnd = hwnd_list[0]
-            win32gui.PostMessage(hwnd, win32con.WM_CLOSE, 0, 0)
-            return True
+    
 
     def setOtherMaxMinValue(self,item, value):
         value = int(value)
@@ -193,7 +182,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 self.send_cmd()
                 # time.sleep(0.01)
                 self.get_basic_info_mcu()
-                self.close_other_window()
+                # self.close_other_window()
             except BaseException as e:
                 print("121231298908", e)
                 break