def ConnectWindow(self, selector, foreground=False): if foreground: time.sleep(1) self.root = UIAuto.GetForegroundControl() return True handleSetList = [] if 'title' in selector: handleSetList.append(self.ConnectWindowsByTitle(selector['title'])) if 'handle' in selector: handleSetList.append(self.ConnectWindowsByHandle(selector['handle'])) if "title_re" in selector: handleSetList.append(self.ConnectWindowsByTitleRe(selector['title_re'])) while -1 in handleSetList: handleSetList.remove(-1) if len(handleSetList) == 0: return False handleSet = handleSetList[0] for s in handleSetList: handleSet = s & handleSet if len(handleSet) == 0: return False elif len(handleSet) != 1: raise NonuniqueSurfaceException(selector) else: hn = handleSet.pop() if hn: self.root = UIAuto.ControlFromHandle(hn) return True else: return False
def main(args): if args.time > 0: time.sleep(args.time) start = time.clock() if args.active: c = automation.GetForegroundControl() elif args.cursor or args.up: c = automation.ControlFromCursor() elif args.fullscreen: c = automation.GetRootControl() CaptureControl(c, args.path, args.up) automation.Logger.WriteLine('cost time: {:.3f} s'.format(time.clock() - start))
def main(args): if args.time > 0: time.sleep(args.time) start = time.time() if args.active: c = auto.GetForegroundControl() CaptureControl(c, args.path, args.up) elif args.cursor or args.up: c = auto.ControlFromCursor() CaptureControl(c, args.path, args.up) elif args.fullscreen: c = auto.GetRootControl() rects = auto.GetMonitorsRect() dot = args.path.rfind('.') for i, rect in enumerate(rects): path = args.path[:dot] + '_' * i + args.path[dot:] c.CaptureToImage(path, rect.left, rect.top, rect.width(), rect.height()) auto.Logger.WriteLine('capture image: ' + path) auto.Logger.WriteLine('cost time: {:.3f} s'.format(time.time() - start))
def WalkCurrentWindow(): window = automation.GetForegroundControl().GetTopWindow() for control, depth in automation.WalkControl(window, True): print(' ' * depth * 4 + str(control))
def getCurrentApplication(): # Getting Chrome Tab code copied with minor modification from stack overflow: # https://stackoverflow.com/questions/11645123/how-do-i-get-the-url-of-the-active-google-chrome-tab-in-windows # Thanks @proggeo(https://stackoverflow.com/users/7594271/proggeo) control = automation.GetForegroundControl() # If the current window is chromium based if (control.ClassName == "Chrome_WidgetWin_1"): address_control = automation.FindControl( control, lambda c, d: isinstance(c, automation.EditControl) and "Address and search bar" in c.Name) # Yeah its Google Chrome if (address_control): url = address_control.CurrentValue() domain = urlparse(url).netloc # We are on youtube if (domain == "www.youtube.com"): yt_control = automation.FindControl( control, lambda c, d: isinstance(c, automation.TabItemControl ) and "- YouTube" in c.Name) # Probably on a video if (yt_control): video_name = yt_control.Name[:-10] return "YouTube - " + video_name # Might not be on a video else: # Nevermind actually in a video if ("/watch?v=" in url): return "YouTube - Unknown Video" # Probably on the youtube homepage or something else: return "YouTube" else: return domain # Not Google Chrome else: if ("— Atom" in control.Name): return "Atom" elif ("Slack -" in control.Name): return "Slack" elif ("- Discord" in control.Name): return "Discord" else: return control.Name # Other type of chromium based app elif (control.ClassName == "Chrome_WidgetWin_0"): spotify_test = automation.FindControl( control, lambda c, d: isinstance(c, automation.DocumentControl) and "Spotify" in c.Name) # Spotify if (spotify_test): return "Spotify" else: return control.Name # Not a chromium based window else: if (control.ClassName == "CabinetWClass"): file_exp_test = automation.FindControl( control, lambda c, d: isinstance(c, automation.TreeItemControl) and "OneDrive" in c.Name) if (file_exp_test and "This PC" in file_exp_test.GetNextSiblingControl().Name): return "File Explorer" else: return control.Name # Probably Native Microsoft Application elif (control.ClassName == "ApplicationFrameWindow"): enc_name = control.Name.encode("utf-8") if (b"- Mail" in enc_name): return "Mail" if (b"Microsoft Store" in enc_name): return "Microsoft Store" # Don't know what it is else: return str(enc_name)[2:-1] elif (control.ClassName == "vguiPopupWindow"): return control.Name else: if ("- paint.net" in control.Name): return "Paint.net" else: return control.ClassName