def check_connectivity(self): try: top_window = top = self.app.top_window() except Exception as e: print(e) return False try: top_element = findwindows.find_element(handle=top_window.handle) if top_element.name == 'TCP Servers Not Found.\r\nCheck Connection': return False elif top_element.name == 'Check Connection': return False elif top_element.name == 'Searching for TCP Servers...': return False elif top_element.name == 'TCP Servers Not Found.': return False elif top_element.name == 'Check Connection': return False elif top_element.name == 'Connecting...': print('Connecting...') return False elif 'Initializing' in top_element.name: print('Initializing...') return False elif 'Unable to connect' in top_element.name: return False elif top_element.name == 'RS³': return False elif 'was lost' in top_element.name: return False elif top_element.name == '': return True elif top_element.name == 'About': print('About, returning false') return False elif top_element.name == 'Unable to collect at current gain and offset values. Please optimize instrument.': print('Optimize instrument before collecting data.') return True elif top_element.name == 'Type mismatch': return False elif 'Connected to' in top_element.name: return True elif top_element.name == 'RS³ 18483 1': return True else: if 'Initial' in top_element.name: print('Why is this initializing unexpected?') print('unexpected name:') print(top_element.name) return True except Exception as e: print(e) return True
def autoMemorize(self, gui): # クリップボードのコピー内容を消去 clipboard.EmptyClipboard() # 開いているウィンドウのハンドル一覧を取得 windowHandles = self.getWindowHandles() # 最前面にあるウィンドウがブラウザならURLを取得 firstElememt = findwindows.find_element(handle=windowHandles[0]) # Mozilla FirefoxからURL取得 if re_search('Mozilla Firefox', str(firstElememt)) is not None: keyboard.send('ctrl+l,shift,ctrl+c') elif re_search('Google Chrome', str(firstElememt)) is not None: keyboard.send('ctrl+l,shift,ctrl+c') else: # 対応ブラウザでない場合は取得中止 return # 0.5秒までの間にクリップボードにコピーされたら途中で抜ける for t in range(5): if clipboard.GetClipboardFormats() != []: break time_sleep(0.1) # コピーが間に合わなければ0.1秒待つ # クリップボードが空なら中止(フォーマットが取得されないことで判定) if clipboard.GetClipboardFormats() == []: return # クリップボードにコピーしたURLを取得 copiedURL = clipboard.GetData() # print(copiedURL) # 何もコピーされていないなら中止 if len(copiedURL) == 0: return URL_pattern = [] # URL文字数を30から順に区切る if len(copiedURL) >= 15: if len(copiedURL) >= 20: if len(copiedURL) >= 25: if len(copiedURL) >= 30: URL_pattern.append(copiedURL[0:30]) URL_pattern.append(copiedURL[0:25]) URL_pattern.append(copiedURL[0:20]) URL_pattern.append(copiedURL[0:15]) else: URL_pattern.append(copiedURL) # URL文字数を30,25,20,15の順に減らしながら,含まれるアカウントを探す # 該当アカウントが1つだけならユーザID/Mailとパスワードを取得 for i in range(len(URL_pattern)): # print(URL_pattern[i]) IDandPass = gui.cmdEvt.autoFindByURL(URL_pattern[i]) if IDandPass != {}: serviceName = IDandPass['Service'] IDorMail = IDandPass['ID'] passWord = IDandPass['Pass'] # ユーザID/Mailとパスワードの一時保存 # つまり自動memorize gui.cmdEvt.setMemorize(serviceName, IDorMail, passWord) break
def find_THX_handle(name='THX'): if name == 'THX': title = '网上股票交易系统5.0' class_name = 'Afx:400000:b:10003:6:108b3' if name == 'ZS': title = '招商证券V7.08' class_name = 'TdxW_MainFrame_Class' print('--------------开始寻找客户端窗口------------------') handle = find_element(title_re=title, class_name=class_name) print('客户端窗口句柄为:', handle.handle) process = handle.process_id return handle.handle, process
def getWindowHandles(self) -> list: windowList = findwindows.find_windows() # ウィンドウのハンドル値 windowHandles = [] # windowListから余計なウィンドウを省いたリスト # 先頭5個までのウィンドウだけ扱う if len(windowList) > 5: num = 5 else: num = len(windowList) # print('##########################################') for i in range(num): element = findwindows.find_element(handle=windowList[i]) # title='' or 'None'のウィンドウをリストから除外 if re_search('\'\'', str(element)) is None \ and re_search('None', str(element)) is None: windowHandles.append(windowList[i]) # print(str(i) + ':' + str(element)) # debug return windowHandles
def is_selected(self): return find_element().is_selected()
def is_enabled(self): return find_element().is_enabled()
def check_connectivity(self): try: top_window = self.app.top_window() except Exception as e: print("Cannot find top window") print(e) return False try: top_element = findwindows.find_element(handle=top_window.handle) if top_element.name == "TCP Servers Not Found.\r\nCheck Connection": return False elif top_element.name == "Check Connection": return False elif top_element.name == "Searching for TCP Servers...": return False elif top_element.name == "TCP Servers Not Found.": return False elif top_element.name == "Check Connection": return False elif top_element.name == "Connecting...": print("Connecting...") return False elif "Initializing" in top_element.name: print("Initializing...") return False elif "Unable to connect" in top_element.name: return False elif "Address in use" in top_element.name: return False elif top_element.name == "RS³": return False elif "was lost" in top_element.name: return False elif top_element.name == "": return True elif top_element.name == "About": # print('About, returning false') return False elif (top_element.name == "Unable to collect at current gain and offset values. Please optimize instrument." ): print("Optimize instrument before collecting data.") return True elif top_element.name == "Type mismatch": return False elif "Connected to" in top_element.name: return True elif top_element.name == "RS³ 18483 1": return True elif top_element.name == "Spectrum Save": return True elif top_element.name == "Take White Reference Measurement": return True elif top_element.name == "Instrument Configuration": return True elif "Initial" in top_element.name: # This should be redundant with the check for "Initializing" but it catches an extra message return True else: if "Initial" in top_element.name: print("Why is this initializing unexpected?") print("unexpected name:") print(top_element.name) return True except Exception as e: print(e) return True