<commit_before>"""
扯线木偶界面自动化应用编程接口(Puppet UIAutomation API)
技术群：624585416
"""
__author__ = "睿瞳深邃(https://github.com/Raytone-D)"
__project__ = 'Puppet'
__version__ = "0.4.31"
__license__ = 'MIT'

# coding: utf-8
import ctypes
from functools import reduce
import time
import sys

try:
    import pyperclip
except ImportError as e:
    print("{}\n请先在命令行下运行：pip install pyperclip，再使用puppet！".format(e))

MSG = {'WM_SETTEXT': 12,
       'WM_GETTEXT': 13,
       'WM_KEYDOWN': 256,
       'WM_KEYUP': 257,
       'WM_COMMAND': 273,
       'BM_CLICK': 245,
       'CB_GETCOUNT': 326,
       'CB_SETCURSEL': 334,
       'CBN_SELCHANGE': 1,
       'COPY_DATA': 57634}

INIT = {'买入': 161, '卖出': 162, '撤单': 163}

NODE = {'FRAME': (59648, 59649),
        'FORM': (59648, 59649, 1047, 200, 1047),
        'ACCOUNT': (59392, 0, 1711),
        'COMBO': (59392, 0, 2322),
        'BUY': (1032, 1033, 1034, '买入[B]', 1036, 1018),
        'SELL':(1032, 1033, 1034, '卖出[S]', 1036, 1038),
        'CANCEL': (3348, '查询代码', '撤单'),
        'ENTRUSTMENT': 168,
        '撤单': 163,
        '双向委托': 512,
        '新股申购': 554,
        '中签查询': 1070}

TWO_WAY = {'买入代码': 1032,
           '买入价格': 1033,
           '买入数量': 1034,
           '买入': 1006,
           '卖出代码': 1035,
           '卖出价格': 1058,
           '卖出数量': 1039,
           '卖出': 1008,
           '可用余额': 1038,
           '刷新': 32790,
           '报表': 1047}

NEW = {'新股代码': 1032,
       '新股名称': 1036,
       '申购价格': 1033,
       '可申购数量': 1018,
       '申购数量': 1034,
       '申购': 1006}

RAFFLE = ['新股代码', '证券代码', '申购价格']# , '申购上限']

VKCODE = {'F1': 112,
          'F2': 113,
          'F3': 114,
          'F4': 115,
          'F5': 116,
          'F6': 117}

op = ctypes.windll.user32

def switch_combo(index, idCombo, hCombo):
    op.SendMessageW(hCombo, MSG['CB_SETCURSEL'], index, 0)
    op.SendMessageW(op.GetParent(hCombo), MSG['WM_COMMAND'], MSG['CBN_SELCHANGE']<<16|idCombo, hCombo)

def click_button(dialog, label):
    handle = op.FindWindowExW(dialog, 0, 0, label)
    id_btn = op.GetDlgCtrlID(handle)
    op.PostMessageW(dialog, MSG['WM_COMMAND'], id_btn, 0)

def fill_in(container, _id_item, _str):
    op.SendDlgItemMessageW(container, _id_item, MSG['WM_SETTEXT'], 0, _str)

def kill_popup(hDlg, name='是(&Y)'):
    for x in range(100):
        time.sleep(0.01)
        popup = op.GetLastActivePopup(hDlg)
        if popup != hDlg and op.IsWindowVisible(popup):
            yes = op.FindWindowExW(popup, 0, 0, name)
            idYes = op.GetDlgCtrlID(yes)
            op.PostMessageW(popup, MSG['WM_COMMAND'], idYes, 0)
            print('popup has killed.')
            break


class Puppet:
    """
    界面自动化操控包装类
    # 方法 # '委买': buy(), '委卖': sell(), '撤单': cancel(), '打新': raffle(),
    # 属性 # '帐号': account, '可用余额': balance, '持仓': position, '成交': deals, '可撤委托': cancelable, 
    #      # '新股': new, '中签': bingo, 
    """
    def __init__(self, main=None, title='网上股票交易系统5.0'):

        print('木偶: 欢迎使用Puppet TraderApi, version {}'.format(__version__))
        self._main = main or op.FindWindowW(0, title)
        self.buff = ctypes.create_unicode_buffer(32)
        self.switch = lambda node: op.SendMessageW(self._main, MSG['WM_COMMAND'], node, 0)
        if self._main:
            self._container = {label: self._get_item(_id) for label, _id in INIT.items()}

        self._position, self._cancelable, self._entrustment = None, None, None

        self.switch(NODE['双向委托'])
        time.sleep(0.5)

        self.two_way = reduce(op.GetDlgItem, NODE['FRAME'], self._main)
        self.members = {k: op.GetDlgItem(self.two_way, v) for k, v in TWO_WAY.items()}<commit_msg>增加平台和Python版本信息。<commit_after>"""
扯线木偶界面自动化应用编程接口(Puppet UIAutomation API)
技术群：624585416
"""
__author__ = "睿瞳深邃(https://github.com/Raytone-D)"
__project__ = 'Puppet'
__version__ = "0.4.32"
__license__ = 'MIT'

# coding: utf-8
import ctypes
from functools import reduce
import time
import sys
import platform

try:
    import pyperclip
except ImportError as e:
    print("{}\n请先在命令行下运行：pip install pyperclip，再使用puppet！".format(e))

MSG = {'WM_SETTEXT': 12,
       'WM_GETTEXT': 13,
       'WM_KEYDOWN': 256,
       'WM_KEYUP': 257,
       'WM_COMMAND': 273,
       'BM_CLICK': 245,
       'CB_GETCOUNT': 326,
       'CB_SETCURSEL': 334,
       'CBN_SELCHANGE': 1,
       'COPY_DATA': 57634}

INIT = {'买入': 161, '卖出': 162, '撤单': 163}

NODE = {'FRAME': (59648, 59649),
        'FORM': (59648, 59649, 1047, 200, 1047),
        'ACCOUNT': (59392, 0, 1711),
        'COMBO': (59392, 0, 2322),
        'BUY': (1032, 1033, 1034, '买入[B]', 1036, 1018),
        'SELL':(1032, 1033, 1034, '卖出[S]', 1036, 1038),
        'CANCEL': (3348, '查询代码', '撤单'),
        'ENTRUSTMENT': 168,
        '撤单': 163,
        '双向委托': 512,
        '新股申购': 554,
        '中签查询': 1070}

TWO_WAY = {'买入代码': 1032,
           '买入价格': 1033,
           '买入数量': 1034,
           '买入': 1006,
           '卖出代码': 1035,
           '卖出价格': 1058,
           '卖出数量': 1039,
           '卖出': 1008,
           '可用余额': 1038,
           '刷新': 32790,
           '报表': 1047}

NEW = {'新股代码': 1032,
       '新股名称': 1036,
       '申购价格': 1033,
       '可申购数量': 1018,
       '申购数量': 1034,
       '申购': 1006}

RAFFLE = ['新股代码', '证券代码', '申购价格']# , '申购上限']

VKCODE = {'F1': 112,
          'F2': 113,
          'F3': 114,
          'F4': 115,
          'F5': 116,
          'F6': 117}

op = ctypes.windll.user32

def switch_combo(index, idCombo, hCombo):
    op.SendMessageW(hCombo, MSG['CB_SETCURSEL'], index, 0)
    op.SendMessageW(op.GetParent(hCombo), MSG['WM_COMMAND'], MSG['CBN_SELCHANGE']<<16|idCombo, hCombo)

def click_button(dialog, label):
    handle = op.FindWindowExW(dialog, 0, 0, label)
    id_btn = op.GetDlgCtrlID(handle)
    op.PostMessageW(dialog, MSG['WM_COMMAND'], id_btn, 0)

def fill_in(container, _id_item, _str):
    op.SendDlgItemMessageW(container, _id_item, MSG['WM_SETTEXT'], 0, _str)

def kill_popup(hDlg, name='是(&Y)'):
    for x in range(100):
        time.sleep(0.01)
        popup = op.GetLastActivePopup(hDlg)
        if popup != hDlg and op.IsWindowVisible(popup):
            yes = op.FindWindowExW(popup, 0, 0, name)
            idYes = op.GetDlgCtrlID(yes)
            op.PostMessageW(popup, MSG['WM_COMMAND'], idYes, 0)
            print('popup has killed.')
            break


class Puppet:
    """
    界面自动化操控包装类
    # 方法 # '委买': buy(), '委卖': sell(), '撤单': cancel(), '打新': raffle(),
    # 属性 # '帐号': account, '可用余额': balance, '持仓': position, '成交': deals, '可撤委托': cancelable, 
    #      # '新股': new, '中签': bingo, 
    """
    def __init__(self, main=None, title='网上股票交易系统5.0'):

        print('木偶: 欢迎使用Puppet TraderApi, version {}'.format(__version__))
        print('{}\nPython version: {}'.format(platform.platform(), platform.python_version()))
        self._main = main or op.FindWindowW(0, title)
        self.buff = ctypes.create_unicode_buffer(32)
        self.switch = lambda node: op.SendMessageW(self._main, MSG['WM_COMMAND'], node, 0)
        if self._main:
            self._container = {label: self._get_item(_id) for label, _id in INIT.items()}

        self._position, self._cancelable, self._entrustment = None, None, None

        self.switch(NODE['双向委托'])
        time.sleep(0.5)

        self.two_way = reduce(op.GetDlgItem, NODE['FRAME'], self._main)
        self.members = {k: op.GetDlgItem(self.two_way, v) for k, v in TWO_WAY.items()}
{'fraction_non_alphanumeric': 0.17178998911860718, 'fraction_numerical': 0.0764417845484222, 'mean_word_length': 2.6026457618814307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2087296', 'n_tokens_mistral': 3482, 'n_tokens_neox': 3234, 'n_words': 625}