def start_from_tray(self, tray_icon): tray_icon.wrapper_object().click_input() tray_icon_menu = Desktop(backend="uia").window( **self.configs['TaskBar']['teacher_menu']['id']) tray_icon_menu.wait('visible', timeout=10) tray_icon_menu.window(**self.configs['TaskBar']['teacher_menu'] ['display_win']).wrapper_object().click_input() main_win = Desktop(backend="uia").window( **self.configs['teachermain']['main']['id']) main_win.exists(timeout=5)
def logon_process(self): ''' 登录处理 ''' logon_win = Desktop(backend="uia").window( **self.configs['logon_win']['id']) if logon_win.exists(timeout=5): user = logon_win.window(**self.configs['logon_win'] ['user']).wrapper_object().get_value() self.logger.debug("Logon User: %s" % user) if user != self.configs['teachermain']['login']['user']: logon_win.window( **self.configs['logon_win']['user']).type_keys( configs['teachermain']['login']['user']) logon_win.window(**self.configs['logon_win']['passwd']).type_keys( self.configs['teachermain']['login']['passwd']) logon_win.window(**self.configs['logon_win']['logon_btn']).click() reg_win = Desktop(backend="uia").window( **self.configs['teachermain']['main']['id']) reg_btn = reg_win.window( **self.configs['teachermain']['main']['try_btn']) if (reg_btn.exists(2)): self.logger.info('Current Version: Try, not registered.') reg_btn.click()
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()
def Install(): Popen(r'D:\Client\DuoLaBao\Setup-DLB-1.4.12.1.exe', shell=True) time.sleep(1) dlg = Desktop(backend="win32").window(title=u"安装 - 哆啦宝") # 界面一 您将把哆啦宝安装在哪里? # 界面一 您将把哆啦宝安装在哪里? time.sleep(1) # 获取路径输入框 dlg.window(class_name="TEdit") edit = dlg['TEdit'] # 输入路径 edit.set_text(r'D:\Program Files\DuoLaBao') # 发送快捷键 下一步 dlg.type_keys("%N") # 文件夹已经存在 # 文件夹已经存在 time.sleep(2) exeits = Desktop(backend="win32").window(title=u"文件夹已经存在") #判断窗体是否存在 if exeits.exists(): exeits.type_keys("%Y") # 界面二 您想选择哪个附加任务? # 界面二 您想选择哪个附加任务? # 发送快捷键 下一步 time.sleep(2) dlg.type_keys("%N") # 界面三 安装程序开始在您的电脑中安装哆啦宝. # 界面三 安装程序开始在您的电脑中安装哆啦宝. time.sleep(2) dlg.type_keys("%I") #界面四 哆啦宝安装完成F #界面四 哆啦宝安装完成F time.sleep(2) dlgss = Desktop(backend="win32").window(title=u"安装 - 哆啦宝") dlgss.type_keys("%F") # 界面五 初始化激活提示 # 界面五 初始化激活提示 time.sleep(3) dlgcc = Desktop(backend="uia").window(title=u"初始化激活提示") # 获取窗体坐标 idc = FromPostion.GetZuoBiao(dlgcc) # print idc # 获取屏幕大小 screenWidth, screenHeight = pyautogui.size() # 获取当前鼠标位置 currentMouseX, currentMouseY = pyautogui.position() # 激活对话框窗体操作 # 激活对话框窗体操作 def TuiChu(): time.sleep(1) # 移动鼠标到指定位置 pyautogui.moveTo(idc[0] + 130, idc[1] + 150) # 鼠标点击事件 pyautogui.click() return TuiChu() return
break 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:
def is_visible_main(self, timeout=2): main_win = Desktop(backend="uia").window( **self.configs['teachermain']['main']['id']) return main_win.exists(timeout=timeout)