Exemplo n.º 1
0
def openDevelopmentMode():
    runProgram('ms-settings:developers')
    settings = Desktop(backend="uia")["Settings"]
    btn = settings['For developersGroupBox'].RadioButton3
    btn.click()
    settings['Use developer featuresDialog'].Yes.click()
    settings.close()
Exemplo n.º 2
0
def install_qttabbar():
    print('Installing Qttabbar.....')
    wget.download(
        'http://qttabbar.wdfiles.com/local--files/qttabbar1/QTTabBar_1043.zip',
        rf"{path}\software\QTTabBar.zip")
    os.system(
        rf"{path}\tools\7za.exe x {path}\software\QTTabBar.zip -o{path}\software"
    )
    os.system(rf"{path}\software\QTTabBar.exe /qi")
    qttabbar = False
    for win in Desktop(backend="uia").windows():
        if win.class_name() == "CabinetWClass":
            break
    else:
        qttabbar = True
        Application(backend="uia").start('explorer.exe')
        win = Desktop(backend="uia").window(class_name="CabinetWClass")
    win.set_focus()
    keyboard.send_keys("{VK_MENU}")
    keyboard.send_keys("{V}")
    time.sleep(0.5)
    keyboard.send_keys("{Y}")
    keyboard.send_keys("{DOWN}")
    keyboard.send_keys("{DOWN}")
    keyboard.send_keys("{DOWN}")
    keyboard.send_keys("{ENTER}")
    if qttabbar:
        win.close()
    os.system('cls')
class Win10CalcTest:

    app = None
    dlg = None

    def __init__(self):
        self.app = Application(backend="uia").start('calc.exe')
        self.dlg = Desktop(backend="uia").Calculator

    def keyboard_input(self, input_string):
        self.dlg.type_keys(input_string)

    def validate_result(self, expected_string):
        result = self.dlg.child_window(auto_id="CalculatorResults").texts()[0]
        if str(result) == 'Display is ' + expected_string:
            print(f"Result {result} is the expected one!")
        else:
            raise AssertionError(f"Result {result} is different than expected {expected_string}")

    def press_buttons(self, button_name):
        button = self.dlg.child_window(auto_id=button_name+'Button')
        button.click()

    def close_calculator(self):
        close_button = self.dlg.child_window(auto_id='Close')
        close_button.click()
        self.dlg.close()

    def verify_calculator_is_opened(self, expected):
        try:
            if expected:
                return self.dlg.child_window(auto_id="CalculatorResults").wait('visible', 5)
            else:
                return self.dlg.child_window(auto_id="CalculatorResults").wait_not('visible', 5)
        except ElementNotFoundError:
            if expected:
                return False
            else:
                return True
Exemplo n.º 4
0
    def OnSend(self, event):
        try:
            self.m_send.Disable()
            if not hyhr_key.Hyhr_key.IsKeyValid(hyhr_key.KEY.Key):
                logger.error(hyhr_def.HYHR_KEY_ERROR)
                wx.MessageBox(hyhr_def.HYHR_KEY_ERROR)
                return
            else:
                logger.info(hyhr_def.HYHR_KEY_VALID)
            #check key exists
            # if not os.path.isfile(key):
            # 	wx.MessageBox('认证码不存在,请先到菜单文件--认证中输入认证码')
            # 	logger.error('认证码不存在')
            # 	return
            # else:
            # 	with open(key, 'r', encoding='utf-8') as k:
            # 		data = k.read()
            # 		key_date = datetime.datetime.strptime(hyhr_encrypt.Decrypt(data.encode()),hyhr_def.HYHR_KEY_FORMAT)
            # 		if hyhr_encrypt.Global_Cur_Date:
            # 			cur_date = datetime.datetime.strptime(hyhr_encrypt.Global_Cur_Date,hyhr_def.HYHR_KEY_FORMAT)
            # 		else:
            # 			cur_date = datetime.datetime.strptime(hyhr_encrypt.GetCurDate(),hyhr_def.HYHR_KEY_FORMAT)
            # 		if cur_date > key_date:
            # 			wx.MessageBox(hyhr_def.HYHR_KEY_EXPIRED)
            # 			logger.error(hyhr_def.HYHR_KEY_EXPIRED)
            # 			return
            # 		else:
            # 			logger.info('认证码有效!')
            self.msg = self.m_richText3.GetValue()
            if len(self.names) == 0 or (len(self.msg) == 0
                                        and len(self.file) == 0):
                wx.MessageBox(hyhr_def.HYHR_NAME_MSG_FILE_EMPTY)
                logger.error(hyhr_def.HYHR_NAME_MSG_FILE_EMPTY)
                return

            if not os.path.isfile(wechat):
                wx.MessageBox(hyhr_def.HYHR_WECHAT_NOT_INSTALLED)
                logger.error(hyhr_def.HYHR_WECHAT_NOT_INSTALLED)
                return
            app = Application(backend='uia').start(wechat)
            try:
                dlg = Desktop(backend='uia').window(
                    class_name=wechat_class_name)
                dlg.set_focus()
            except Exception as ex:
                wx.MessageBox(hyhr_def.HYHR_WECHAT_NOT_STARTED)
                logger.error(f'{hyhr_def.HYHR_WECHAT_NOT_STARTED} {ex}')
                return
            wrapper = dlg.wrapper_object()
            wrapper.click_input(coords=(searchbox_x, searchbox_y))

            counter = 0
            for info in self.names:
                name = None
                data = []
                vals = []
                validData = True
                info = info.strip()
                if not len(info):
                    continue
                vals = re.split(r'\s+', info)
                length = len(vals)
                if length >= 1:
                    name = vals[0]
                else:
                    logger.warning('异常数据,忽略.')
                    counter += 1
                    continue

                if len(self.msg):
                    for i in range(1, length):
                        try:
                            fee = float(vals[i])
                            data.append(fee)
                        except Exception as ex:
                            logger.warning('异常数值:{}!暂不发送,请核对后重试!'.format(info))
                            validData = False
                            break

                if not validData:
                    counter += 1
                    continue

                try:
                    wrapper.click_input(coords=(searchbox_x, searchbox_y))
                    wrapper.type_keys(name)
                    time.sleep(1.5)
                    wrapper.click_input(coords=(searchbox_x, searchResult_y))
                    noFoundDlg = Desktop(backend='uia').window(
                        class_name=wechat_notFound_class_name)
                    #time.sleep(0.5)
                    if noFoundDlg.exists(timeout=2):
                        noFoundDlg.close()
                        logger.warning('{} 不存在,请手工确认'.format(name))
                        time.sleep(1)
                        counter += 1
                        continue

                    if len(self.msg):
                        if len(data) == 0:
                            dlg.type_keys(self.msg.replace('{', '').replace(
                                '}', ''),
                                          with_spaces=True)
                        else:
                            if '{}' in self.msg:
                                if self.msg.count('{}') == len(data):
                                    dlg.type_keys(self.msg.format(*data),
                                                  with_spaces=True)
                                else:
                                    logger.warning(
                                        f'{name} 数据数目和消息格式不匹配,忽略该条记录!')
                                    counter += 1
                                    continue
                            else:
                                dlg.type_keys(self.msg, with_spaces=True)
                        dlg.type_keys('%{s}')
                        logger.info('发送消息给{}成功'.format(name))

                    if len(self.file):
                        #try to send file
                        #for f in os.listdir(self.file):
                        wrapper.click_input(coords=(sendfile_x, sendfile_y))
                        #pywinauto.keyboard.send_keys(self.file)
                        pywinauto.keyboard.send_keys(self.file)
                        pywinauto.keyboard.send_keys('{ENTER 1}')
                        dlg.type_keys('%{s}')
                        logger.info('发送文件{}给{}成功'.format(self.file, name))

                    self.m_namesList.SetItem(counter, 1, '✔')
                    self.m_namesList.SetItemTextColour(counter, wx.GREEN)
                    self.m_namesList.itemDataMap[counter] = (name, '✔')
                    counter += 1

                except Exception as ex:
                    #wx.MessageBox('发送错误!{}.'.format(ex))
                    logger.warning(f'{hyhr_def.HYHR_SEND_ERROR}{ex}.')
                    counter += 1
        except Exception as ex:
            wx.MessageBox(f'{hyhr_def.HYHR_SEND_ERROR}{ex}.')
            logger.error(f'{hyhr_def.HYHR_SEND_ERROR} {ex}.')
        finally:
            self.m_send.Enable()
        event.Skip()
Exemplo n.º 5
0
        if not validData:
            continue
        try:
            wrapper.click_input(coords=(width, height))
            #time.sleep(0.5)
            if dlg['3'].exists(timeout=2):
                dlg['3'].type_keys(name)
                #dlg['3'].type_keys('{ENTER 1}')
                time.sleep(0.5)
                wrapper.click_input(coords=(width, height + 70))
                noFoundDlg = Desktop(backend='uia').window(
                    class_name='FTSMsgSearchWnd')
                #time.sleep(0.5)
                if noFoundDlg.exists(timeout=2):
                    noFoundDlg.close()
                    print('{} 不存在,请手工确认'.format(name))
                    time.sleep(1)
                    continue

                if bNeedSendMsg:
                    if len(data) == 0:
                        dlg.type_keys(message.replace('{',
                                                      '').replace('}', ''),
                                      with_spaces=True)
                    else:
                        if '{}' in message:
                            dlg.type_keys(message.format(*data),
                                          with_spaces=True)
                        else:
                            dlg.type_keys(message, with_spaces=True)