From 34491829675033e41715648b1e92f339bf2f35d1 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 25 八月 2022 17:51:10 +0800
Subject: [PATCH] Changes

---
 trade_gui.py |   81 ++++++++++++++++++++++++++++++----------
 1 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/trade_gui.py b/trade_gui.py
index 9d6bf51..1d39863 100644
--- a/trade_gui.py
+++ b/trade_gui.py
@@ -6,7 +6,13 @@
 import win32api
 import win32con
 from log import *
+from threading import Thread
 
+def async_call(fn):
+    def wrapper(*args, **kwargs):
+        Thread(target=fn, args=args, kwargs=kwargs).start()
+
+    return wrapper
 
 class THSGuiTrade(object):
     __instance = None
@@ -29,6 +35,12 @@
     def refresh_hwnds(self):
         self.cancel_win = self.__instance.getCancelBuyWin()
         self.buy_win_list = self.get_buy_wins();
+
+    # 鎵撳紑浜ゆ槗鐜
+    def open_trade_env(self):
+        # 鎵撳紑浜ゆ槗鐣岄潰锛團12锛�
+
+        pass
 
     def get_available_buy_win(self):
         self.buy_lock.acquire()
@@ -234,24 +246,43 @@
             win32gui.PostMessage(win, win32con.WM_KEYDOWN, 66, 0);
 
             logger_trade_gui.info("鎵ц涔板叆缁撴潫锛歝ode-{} 鑰楁椂:{}".format(code, int(round(time.time() * 1000)) - start))
+            self.close_delegate_success_dialog()
             # 寰幆璇诲彇涓嬪崟缁撴灉,鏈�澶氱瓑寰�10s
-            for i in range(0, 50):
-                hwnd = self.getTradeResultWin()
-                if hwnd > 0:
-                    time.sleep(0.2)
-                    code_str = self.getTradeSuccessCode(hwnd)
-                    t = time.time()
-                    print(t)
-                    end = int(round(t * 1000))
-                    print("涔板叆鑰楁椂锛�", end - start)
-                    logger_trade_gui.info("鑾峰彇濮旀墭鍗曞彿锛歝ode-{} 鍗曞彿-{} 鏁翠綋鑰楁椂:{}".format(code, code_str, end - start))
-                    # 鍏抽棴浜ゆ槗缁撴灉寮规
-                    self.closeTradeResultDialog(hwnd)
-                    return code, code_str
-                time.sleep(0.02)
-            raise Exception("鑾峰彇浜ゆ槗缁撴灉鍑洪敊")
+            # for i in range(0, 50):
+            #     hwnd = self.getTradeResultWin()
+            #     if hwnd > 0:
+            #         time.sleep(0.2)
+            #         code_str = self.getTradeSuccessCode(hwnd)
+            #         t = time.time()
+            #         print(t)
+            #         end = int(round(t * 1000))
+            #         print("涔板叆鑰楁椂锛�", end - start)
+            #         logger_trade_gui.info("鑾峰彇濮旀墭鍗曞彿锛歝ode-{} 鍗曞彿-{} 鏁翠綋鑰楁椂:{}".format(code, code_str, end - start))
+            #         # 鍏抽棴浜ゆ槗缁撴灉寮规
+            #         self.closeTradeResultDialog(hwnd)
+            #         return code, code_str
+            #     time.sleep(0.02)
+            return code,""
+            # raise Exception("鑾峰彇浜ゆ槗缁撴灉鍑洪敊")
         finally:
             self.using_buy_wins.discard(win)
+
+    @async_call
+    def close_delegate_success_dialog(self):
+        for i in range(0, 50):
+            hwnd = self.getTradeResultWin()
+            if hwnd > 0:
+                time.sleep(0.2)
+                code_str = self.getTradeSuccessCode(hwnd)
+                t = time.time()
+                print(t)
+                end = int(round(t * 1000))
+                # logger_trade_gui.info("鑾峰彇濮旀墭鍗曞彿锛歝ode-{} 鍗曞彿-{} 鏁翠綋鑰楁椂:{}".format(code, code_str, end - start))
+                # 鍏抽棴浜ゆ槗缁撴灉寮规
+                self.closeTradeResultDialog(hwnd)
+                break
+                # return code, code_str
+            time.sleep(0.02)
 
     # 鎾ら攢纭妗�
     def getCancelBuySureWin(self):
@@ -275,8 +306,8 @@
 
     # 鎾や拱
     def cancel_buy(self, code):
-
         self.buy_cancel_lock.acquire()
+        global code_input
         try:
             logger_trade_gui.info("寮�濮嬫挙鍗曪細code-{}".format(code))
             win = self.cancel_win
@@ -289,6 +320,11 @@
             # 杈撳叆妗嗘帶浠禝D 0x000003E9
             code_input = win32gui.GetDlgItem(win, 0x00000996)
             code_input = win32gui.FindWindowEx(code_input, 0, "Edit", None)
+            # 鍒锋柊鍙ユ焺
+            if code_input <= 0:
+                self.refresh_hwnds()
+                code_input = win32gui.GetDlgItem(win, 0x00000996)
+                code_input = win32gui.FindWindowEx(code_input, 0, "Edit", None)
 
             code_result = "-"
             retry_count = 0
@@ -310,7 +346,10 @@
 
             # 鎾ゅ崟蹇嵎閿甔
             time.sleep(0.01)
-            win32gui.PostMessage(win, win32con.WM_KEYDOWN, 0x00000058, 0);
+            win32gui.PostMessage(win, win32con.WM_KEYDOWN, 0x00000058, 0x002D001);
+            win32gui.PostMessage(win, win32con.WM_CHAR, 0x00000078, 0x002D001);
+            win32gui.PostMessage(win, win32con.WM_KEYUP, 0x00000058, 0x002D001);
+            #win32gui.PostMessage(win, win32con.WM_KEYUP, 0x00000058, 0);
             t = time.time()
             print(t)
             end = int(round(t * 1000))
@@ -325,16 +364,16 @@
 
 if __name__ == '__main__':
     try:
-        THSGuiTrade.checkEnv();
-        print("鐜姝e父")
+        # THSGuiTrade.checkEnv();
+        # print("鐜姝e父")
         trade = THSGuiTrade();
         print(id(trade))
         # win = trade.get_available_buy_win()
         # if win < 1:
         #     raise Exception("鏃犲彲鐢ㄧ殑浜ゆ槗绐楀彛")
-        result = trade.buy("002564", "7.26")
+        # result = trade.buy("002564", "7.26")
         # # print("浜ゆ槗鎴愬姛")
         # time.sleep(0.2)
-        trade.cancel_buy("002564")
+        trade.cancel_buy("000716")
     except Exception as e:
         print(e)

--
Gitblit v1.8.0