def test_connect_process(self): """Test that connect_() works with a process""" app1 = Application() app1.start(_notepad_exe()) app_conn = Application() app_conn.connect(process=app1.process) self.assertEqual(app1.process, app_conn.process) app_conn.UntitledNotepad.MenuSelect('File->Exit')
def test_connect_handle(self): """Test that connect_() works with a handle""" app1 = Application() app1.start(_notepad_exe()) handle = app1.UntitledNotepad.handle app_conn = Application() app_conn.connect(handle=handle) self.assertEqual(app1.process, app_conn.process) app_conn.UntitledNotepad.MenuSelect('File->Exit')
def defocus(self): target_name = "제목 없음 - 메모장" print(target_name) app = Application() app.connect(title_re=".*%s.*" % target_name) # Access app's window object app_dialog = app.top_window_() app_dialog.Minimize() app_dialog.Restore() app_dialog.SetFocus()
class PcDriver(object): def __init__(self): self.app = Application(backend="uia") def start(self, path): self.app.start(path) def connect(self,title): self.app.connect(title=title) def close(self, window_name): """ 关闭应用程序 """ self.app[window_name].Close() def max_window(self, window_name): """ 最大化窗口 """ self.app[window_name].Maximize() def menu_click(self, window_name, menulist): """ 菜单点击 """ self.app[window_name].MenuSelect(menulist) def input(self, window_name, controller, content): """ 输入内容 """ self.app[window_name][controller].TypeKeys(content) def click(self, window_name, controller): """ 鼠标左键点击 example: 下面两个功能相同,下面支持正则表达式 app[u'关于“记事本”'][u'确定'].Click() app.window_(title_re = u'关于“记事本”').window_(title_re = u'确定').Click() """ self.app[window_name][controller].Click() def double_click(self, window_name, controller, x = 0,y = 0): """ 鼠标左键点击(双击) """ self.app[window_name][controller].DoubleClick(button = "left", pressed = "", coords = (x, y))
def login_app_connectable(self): app = Application(backend='win32') count = 0 while count < 10: try: app.connect(title='Open API Login') print('Login app is connected') return True except: count += 1 print('Login app is not yet connectable ... trial({})'.format( count)) time.sleep(1) print('Login app connection failed') return False
def main(argv): driver = test_util.create_chrome_webdriver() try: application = Application(backend="uia") application.connect(title_re='.*Chrome|.*Chromium') print("Looking for apps shortcut...") for desc in application.top_window().descendants(): print(desc.window_text()) if "Apps" == desc.window_text(): print("TRUE") return print("FALSE") finally: driver.quit()
def tearDown(self): "Close the application after tests" try: notepad = Application.connect(path=_notepad_exe()) notepad.kill_() except ProcessNotFoundError: pass # notepad already closed
def tearDown(self): """Close the application after tests""" self.dlg.send_message(win32defines.WM_CLOSE) self.dlg.wait_not('ready') # cleanup additional unclosed sampleapps l = pywinauto.actionlogger.ActionLogger() try: for i in range(2): l.log("Look for unclosed sample apps") app = Application() app.connect(path="TrayMenu.exe") l.log("Forse closing a leftover app: {0}".format(app)) app.kill() except(ProcessNotFoundError): l.log("No more leftovers. All good.")
def run(self): app = Application(backend='win32') if not self.login_app_connectable(): sys.exit() app.connect(title='Open API Login') dlg = app.window(title='Open API Login') # dlg.Edit1.get_focus() # dlg.Edit1.type_keys(self.login_id) dlg.Edit2.get_focus() dlg.Edit2.type_keys(self.login_password) # dlg.Edit3.get_focus() # dlg.Edit3.type_keys(self.certificate_password) dlg.Button1.click_input() self.event_loop.exit()
def test_connect_path_timeout(self): """Test that connect_() works with a path with timeout""" app1 = Application() def delayed_launch(): time.sleep(2) app1.start(_notepad_exe()) thread = Thread(target=delayed_launch) thread.start() app_conn = Application() app_conn.connect(path=_notepad_exe(), timeout=3) self.assertEqual(app1.process, app_conn.process) accessible_modules = process_get_modules() accessible_process_names = [os.path.basename(name.lower()) for process, name, cmdline in accessible_modules] self.assertEquals('notepad.exe' in accessible_process_names, True) app1.UntitledNotepad.MenuSelect('File->Exit')
def test_connect_windowspec(self): """Test that connect_() works with a windowspec""" app1 = Application() app1.start(_notepad_exe()) #unused var: handle = app1.UntitledNotepad.handle app_conn = Application() try: app_conn.connect(title="Untitled - Notepad") except findwindows.WindowAmbiguousError: wins = findwindows.find_elements(active_only=True, title="Untitled - Notepad") app_conn.connect(handle=wins[0].handle) except findwindows.ElementNotFoundError: WaitUntil( 30, 0.5, lambda: len( findwindows.find_elements(active_only=True, title="Untitled - Notepad")) > 0) wins = findwindows.find_elements(active_only=True, title="Untitled - Notepad") app_conn.connect(handle=wins[0].handle) self.assertEqual(app1.process, app_conn.process) app_conn.UntitledNotepad.MenuSelect('File->Exit')
def test_only_full_dumps(fix): # pycharm должен быть запущен от имени администратора, иначе не может запустить процесс m = dt.datetime.now() app = Application(backend="uia").start(path) file_name, file_name1, file_name2, file_name3 = set_file_name_with_datetime( m) time.sleep(2) app.connect(title=title) dlg = app.window(title=title) dlg1 = dlg.child_window(auto_id="1003") value = dlg1.get_value() time.sleep(2) assert value == file_name or value == file_name1 or value == file_name2 or value == file_name3 #проверка чек-боксов по дефолту dlg2 = dlg.child_window(auto_id="1009") value2 = dlg2.get_toggle_state() assert value2 == 1 dlg3 = dlg.child_window(auto_id="1011") value3 = dlg3.get_toggle_state() assert value3 == 0 dlg4 = dlg.child_window(auto_id="1010") value4 = dlg4.get_toggle_state() assert value4 == 0 time.sleep(3) dlg.Пуск.click() time.sleep(290) new_dlg = app.top_window() time.sleep(1) new_dlg.Открытьдиректорию.click() time.sleep(1) # воркспейс для дженкинса, в пайчареме надо заменить на devel\ app = Application().connect(title=title_window) window = app.window(title=title_window) #app = Application().connect(title=r"C:\Devel\test_issinfo\test") #window = app.window(title=r"C:\Devel\test_issinfo\test") time.sleep(1) window.close() delete_issinfo(file_name, file_name1, file_name2, file_name3) dlg.close()
def testConnectWarning3264(self): if not is_x64_OS(): self.defaultTestResult() return app = Application.start(self.sample_exe) warnings.filterwarnings('always', category=UserWarning, append=True) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") app2 = Application.connect(path=self.sample_exe) app.kill_() assert len(w) >= 1 assert issubclass(w[-1].category, UserWarning) assert "64-bit" in str(w[-1].message)
def open(self, title_str=None): #ensure one App instance when conn param is True if not os.path.exists(self.__bare_path) or \ not os.access(self.__bare_path, os.X_OK): return False # connection is prefer. if title_str is not None: self.__app = Application.connect(self.__app, title=title_str) else: self.__app = self.__app.start(self.__path) #FIXME: to check __app is valid. self.__conn = True
def main(argv): driver = test_util.create_chrome_webdriver() try: application = Application(backend="uia") application.connect(title_re='.*Chrome|.*Chromium') w = application.top_window() for desc in w.descendants(): print "item: %s" % desc print "Closing info bar." container = w.child_window(best_match="Infobar Container") container.child_window(best_match="Close").click_input() print "Clicking on the Fullscreen button." button = w.child_window(title_re="^Chrom(e|ium)$", control_type="Button") button.click_input() w.child_window(best_match="Full screen").click_input() window_rect = w.rectangle() window_width = window_rect.width() window_height = window_rect.height() content_width = driver.execute_script("return window.innerWidth") content_height = driver.execute_script("return window.innerHeight") # The content area should be the same size as the full window. print "window_rect: %s" % window_rect print "window_width: %s" % window_width print "window_height: %s" % window_height print "content_width: %s" % content_width print "content_height: %s" % content_height fs = window_width == content_width and window_height == content_height print "FullscreenAllowed: %s" % fs finally: driver.quit()
def testConnect_path(self): "Test that connect_() works with a path" app1 = Application() app1.start(_notepad_exe()) app_conn = Application() app_conn.connect(path=self.notepad_subpath) self.assertEqual(app1.process, app_conn.process) app_conn = Application() if is_x64_Python() or not is_x64_OS(): app_conn.connect(path=r"c:\windows\system32\notepad.exe") else: app_conn.connect(path=r"c:\windows\syswow64\notepad.exe") self.assertEqual(app1.process, app_conn.process) app_conn.UntitledNotepad.MenuSelect('File->Exit')
def test_connect_windowspec(self): """Test that connect_() works with a windowspec""" app1 = Application() app1.start(_notepad_exe()) #unused var: handle = app1.UntitledNotepad.handle app_conn = Application() try: app_conn.connect(title = "Untitled - Notepad") except findwindows.WindowAmbiguousError: wins = findwindows.find_elements(active_only = True, title = "Untitled - Notepad") app_conn.connect(handle = wins[0].handle) except findwindows.ElementNotFoundError: WaitUntil(30, 0.5, lambda: len(findwindows.find_elements(active_only = True, title = "Untitled - Notepad")) > 0) wins = findwindows.find_elements(active_only = True, title = "Untitled - Notepad") app_conn.connect(handle = wins[0].handle) self.assertEqual(app1.process, app_conn.process) app_conn.UntitledNotepad.MenuSelect('File->Exit')
def test_connect_path(self): """Test that connect_() works with a path""" app1 = Application() app1.start(_notepad_exe()) app_conn = Application() app_conn.connect(path=self.notepad_subpath) self.assertEqual(app1.process, app_conn.process) app_conn = Application() if is_x64_Python() or not is_x64_OS(): app_conn.connect(path=r"c:\windows\system32\notepad.exe") else: app_conn.connect(path=r"c:\windows\syswow64\notepad.exe") self.assertEqual(app1.process, app_conn.process) accessible_modules = process_get_modules() accessible_process_names = [os.path.basename(name.lower()) for process, name, cmdline in accessible_modules] self.assertEquals('notepad.exe' in accessible_process_names, True) app_conn.UntitledNotepad.MenuSelect('File->Exit')
0) t = Timer(0.1, first) # Quit after 5 seconds main_thread_id = win32api.GetCurrentThreadId() t.start() hm = pyHook.HookManager() hm.MouseAll = uMad hm.MouseLeftDown = wegood hm.MouseLeftUp = wegood hm.KeyAll = uMad hm.HookMouse() hm.HookKeyboard() pythoncom.PumpMessages() app2 = Application(backend='uia') appconnect2 = app2.connect(title='Convert to RINEX') app2_dlg = appconnect2.Dialog if app.window(title="Options").exists(): #app2_dlg.Options.print_control_identifiers() #time.sleep(1) def second(): try: if (app2_dlg.CheckBox.get_toggle_state() == 0): app2_dlg.CheckBox.click() time.sleep(0.1) if (app2_dlg.CheckBox2.get_toggle_state() == 0): app2_dlg.CheckBox2.click() time.sleep(0.1) if (app2_dlg.CheckBox9.get_toggle_state() == 0):
# Copyright (c) 2019 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. from pywinauto.application import Application import test_util # Print 'home button exists' if the home button exists. driver = test_util.create_chrome_webdriver() try: app = Application(backend="uia") app.connect(title_re='.*Chrome|.*Chromium') home_button = app.top_window().child_window(title="Home", control_type="Button") if home_button.exists(timeout=1): print 'home button exists' finally: driver.quit()
class Notepad: def __init__(self): self.app = Application(backend="uia") def open_app(self): self.app.start('notepad.exe') def close_app(self): self.app.connect(path="notepad.exe") self.app.kill() def type_in_notepad(self, text_string): # self.app.connect(path="notepad.exe") notepad_window = self.app.window(title='Untitled - Notepad') notepad_window.Edit.set_text(text_string) def print_current_document(self): # self.app.connect(path="notepad.exe") notepad_window = self.app.UntitledNotepad notepad_window.menu_select("File -> Print") pdfButton = self.app.Dialog.Print.FolderView.child_window( title_re='.*PDF', control_type="ListItem") if not pdfButton.is_selected(): pdfButton.click_input() self.app.Dialog.Print.Print.click() save_window = notepad_window.child_window(title="Save Print Output As", control_type='Window') name_field = save_window.child_window(title="File name:", auto_id="1001", control_type='Edit') name_field.set_text(pdf_filename) save_window.Save.click() notepad_window.print_control_identifiers() try: saveas_window = notepad_window.child_window( title="Confirm Save As", control_type='Window') if saveas_window.is_active(): saveas_window.Yes.click() except: print "No overwrite" finally: pass @keyword('Check document is printed to pdf file') def is_printed_as_pdf(self): isfile(pdf_path) if not pdf_path.lower().endswith(".pdf"): raise AssertionError("ERROR: Printed file extension is not PDF") def open_about_dialog(self): notepad_window = self.app.UntitledNotepad notepad_window.menu_select("Help -> About Notepad") notepad_window.AboutNotepad.is_active() @keyword('Check Notepad version is') def check_version(self, expected_ver): current_ver = self.app.UntitledNotepad.AboutNotepad.child_window( title_re="Version*", control_type="Text").texts()[0] try: assert expected_ver in current_ver except: raise AssertionError( "ERROR: Current version is not {}, it's {}".format( expected_ver, current_ver)) finally: self.app.UntitledNotepad.AboutNotepad.OK.click() @keyword('Delete file') def delete_file(self): try: os.remove(pdf_path) except OSError: pass
def Conn(self, pid): self.__app = Application.connect(self.__app, process=pid) return self.__app
import pyautogui as pag from pywinauto.application import Application import time start_time = time.time() app = Application(backend="uia") app.connect(path='C:\Program Files (x86)\Rozm\Rozm.exe', title='Rozm') app.Dialog.menu_select("Правка->Очистити") app.Dialog.type_keys("Здравствуйте,_я_ваш_новий_голосовой_помошник_Анатоль._Чем_могу_бить_полезен") pag.press('home') app.Dialog['Читай'].select() #print(app.top_window().descendants(control_type="MenuBar")[1].items()) #print(pag.position()) #field_start_pos = (5, 57) #read_pos = (124, 35) #rozm = app.Dialog #rozm.MenuSelect() #rozm['Правка'] #rozm['Вставит'] #app.start('C:\Program Files (x86)\Rozm\Rozm.exe') #print(app.your_dialog.print_control_identifiers()) #app["Приложение -> Текст"] #pag.click(field_start_pos) #pag.typewrite("") #pag.typewrite(["home"])
class Windows(Device): """Windows client.""" def __init__(self, handle=None, dpifactor=1, **kwargs): super(Windows, self).__init__() self.app = None self.handle = int(handle) if handle else None # windows high dpi scale factor, no exact way to auto detect this value for a window # reference: https://msdn.microsoft.com/en-us/library/windows/desktop/mt843498(v=vs.85).aspx self._dpifactor = float(dpifactor) self._app = Application() self._top_window = None self._focus_rect = (0, 0, 0, 0) self.mouse = mouse self.keyboard = keyboard self._init_connect(handle, kwargs) self.screen = mss() self.monitor = self.screen.monitors[0] # 双屏的时候,self.monitor为整个双屏 self.main_monitor = self.screen.monitors[ 1] # 双屏的时候,self.main_monitor为主屏 @property def uuid(self): return self.handle def _init_connect(self, handle, kwargs): if handle: self.connect(handle=handle) elif kwargs: self.connect(**kwargs) def connect(self, handle=None, **kwargs): """ Connect to window and set it foreground Args: **kwargs: optional arguments Returns: None """ if handle: handle = int(handle) self.app = self._app.connect(handle=handle) self._top_window = self.app.window(handle=handle).wrapper_object() else: for k in ["process", "timeout"]: if k in kwargs: kwargs[k] = int(kwargs[k]) self.app = self._app.connect(**kwargs) self._top_window = self.app.top_window().wrapper_object() self.set_foreground() def shell(self, cmd): """ Run shell command in subprocess Args: cmd: command to be run Raises: subprocess.CalledProcessError: when command returns non-zero exit status Returns: command output as a byte string """ return subprocess.check_output(cmd, shell=True) def snapshot(self, filename=None, quality=10, max_size=None): """ Take a screenshot and save it in ST.LOG_DIR folder Args: filename: name of the file to give to the screenshot, {time}.jpg by default quality: The image quality, integer in range [1, 99] max_size: the maximum size of the picture, e.g 1200 Returns: display the screenshot """ if self.handle: screen = screenshot(filename, self.handle) else: screen = screenshot(filename) if self.app: rect = self.get_rect() screen = aircv.crop_image( screen, [rect.left, rect.top, rect.right, rect.bottom]) if not screen.any(): if self.app: rect = self.get_rect() screen = aircv.crop_image( screenshot(filename), [rect.left, rect.top, rect.right, rect.bottom]) if self._focus_rect != (0, 0, 0, 0): height, width = screen.shape[:2] rect = (self._focus_rect[0], self._focus_rect[1], width + self._focus_rect[2], height + self._focus_rect[3]) screen = aircv.crop_image(screen, rect) if filename: aircv.imwrite(filename, screen, quality, max_size=max_size) return screen def keyevent(self, keyname, **kwargs): """ Perform a key event References: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html Args: keyname: key event **kwargs: optional arguments Returns: None """ self.keyboard.SendKeys(keyname) def text(self, text, **kwargs): """ Input text Args: text: text to input **kwargs: optional arguments Returns: None """ self.keyevent(text) def _fix_op_pos(self, pos): """Fix operation position.""" # 如果是全屏的话,就进行双屏修正,否则就正常即可 if not self.handle: pos = list(pos) pos[0] = pos[0] + self.monitor["left"] pos[1] = pos[1] + self.monitor["top"] return pos def key_press(self, key): """Simulates a key press event. Sends a scancode to the computer to report which key has been pressed. Some games use DirectInput devices, and respond only to scancodes, not virtual key codes. You can simulate DirectInput key presses using this method, instead of the keyevent() method, which uses virtual key codes. :param key: A string indicating which key to be pressed. Available key options are: {'ESCAPE', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', 'BACKSPACE', 'TAB', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', 'ENTER', 'LCTRL', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', "'", '`', 'LSHIFT', 'BACKSLASH', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/', 'RSHIFT', '*', 'LALT', 'SPACE', 'CAPS_LOCK', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'NUM_LOCK', 'SCROLL_LOCK', 'NUMPAD_7', 'NUMPAD_8', 'NUMPAD_9', 'NUMPAD_-', 'NUMPAD_4', 'NUMPAD_5', 'NUMPAD_6', 'NUMPAD_+', 'NUMPAD_1', 'NUMPAD_2', 'NUMPAD_3', 'NUMPAD_0', 'NUMPAD_.', 'F11', 'F12', 'PRINT_SCREEN', 'PAUSE', 'NUMPAD_ENTER', 'RCTRL', 'NUMPAD_/', 'RALT', 'HOME', 'UP', 'PAGE_UP', 'LEFT', 'RIGHT', 'END', 'DOWN', 'PAGE_DOWN', 'INSERT', 'DELETE', 'LWINDOWS', 'RWINDOWS', 'MENU'}. """ key_press(key) def key_release(self, key): """Simulates a key release event. Sends a scancode to the computer to report which key has been released. Some games use DirectInput devices, and respond only to scancodes, not virtual key codes. You can simulate DirectInput key releases using this method. A call to the key_release() method usually follows a call to the key_press() method of the same key. :param key: A string indicating which key to be released. """ key_release(key) def touch(self, pos, **kwargs): """ Perform mouse click action References: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.mouse.html Args: pos: coordinates where to click **kwargs: optional arguments Returns: None """ duration = kwargs.get("duration", 0.01) right_click = kwargs.get("right_click", False) button = "right" if right_click else "left" steps = kwargs.get("steps", 1) offset = kwargs.get("offset", 0) start = self._action_pos(win32api.GetCursorPos()) end = self._action_pos(pos) start_x, start_y = self._fix_op_pos(start) end_x, end_y = self._fix_op_pos(end) interval = float(duration) / steps time.sleep(interval) for i in range(1, steps): x = int(start_x + (end_x - start_x) * i / steps) y = int(start_y + (end_y - start_y) * i / steps) self.mouse.move(coords=(x, y)) time.sleep(interval) self.mouse.move(coords=(end_x, end_y)) for i in range(1, offset + 1): self.mouse.move(coords=(end_x + i, end_y + i)) time.sleep(0.01) for i in range(offset): self.mouse.move(coords=(end_x + offset - i, end_y + offset - i)) time.sleep(0.01) self.mouse.press(button=button, coords=(end_x, end_y)) time.sleep(duration) self.mouse.release(button=button, coords=(end_x, end_y)) def double_click(self, pos): pos = self._fix_op_pos(pos) coords = self._action_pos(pos) self.mouse.double_click(coords=coords) def swipe(self, p1, p2, duration=0.8, steps=5): """ Perform swipe (mouse press and mouse release) Args: p1: start point p2: end point duration: time interval to perform the swipe action steps: size of the swipe step Returns: None """ # 设置坐标时相对于整个屏幕的坐标: x1, y1 = self._fix_op_pos(p1) x2, y2 = self._fix_op_pos(p2) from_x, from_y = self._action_pos(p1) to_x, to_y = self._action_pos(p2) interval = float(duration) / (steps + 1) self.mouse.press(coords=(from_x, from_y)) time.sleep(interval) for i in range(1, steps): self.mouse.move(coords=( int(from_x + (to_x - from_x) * i / steps), int(from_y + (to_y - from_y) * i / steps), )) time.sleep(interval) for i in range(10): self.mouse.move(coords=(to_x, to_y)) time.sleep(interval) self.mouse.release(coords=(to_x, to_y)) def mouse_move(self, pos): """Simulates a `mousemove` event. Known bug: Due to a bug in the pywinauto module, users might experience \ off-by-one errors when it comes to the exact coordinates of \ the position on screen. :param pos: A tuple (x, y), where x and y are x and y coordinates of the screen to move the mouse to, respectively. """ if not isinstance(pos, tuple) or len(pos) != 2: # pos is not a 2-tuple raise ValueError('invalid literal for mouse_move: {}'.format(pos)) try: self.mouse.move(coords=self._action_pos(pos)) except ValueError: # in case where x, y are not numbers raise ValueError('invalid literal for mouse_move: {}'.format(pos)) def mouse_down(self, button='left'): """Simulates a `mousedown` event. :param button: A string indicating which mouse button to be pressed. Available mouse button options are: {'left', 'middle', 'right'}. """ buttons = {'left', 'middle', 'right'} if not isinstance(button, str) or button not in buttons: raise ValueError( 'invalid literal for mouse_down(): {}'.format(button)) else: coords = self._action_pos(win32api.GetCursorPos()) self.mouse.press(button=button, coords=coords) def mouse_up(self, button='left'): """Simulates a `mouseup` event. A call to the mouse_up() method usually follows a call to the mouse_down() method of the same mouse button. :param button: A string indicating which mouse button to be released. """ buttons = {'left', 'middle', 'right'} if not isinstance(button, str) or button not in buttons: raise ValueError( 'invalid literal for mouse_up(): {}'.format(button)) else: coords = self._action_pos(win32api.GetCursorPos()) self.mouse.release(button=button, coords=coords) def start_app(self, path, **kwargs): """ Start the application Args: path: full path to the application kwargs: reference: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html#pywinauto.application.Application.start Returns: None """ self.app = self._app.start(path, **kwargs) def stop_app(self, pid): """ Stop the application Args: pid: process ID of the application to be stopped Returns: None """ self._app.connect(process=pid).kill() @require_app def set_foreground(self): """ Bring the window foreground Returns: None """ SetForegroundWindow(self._top_window) def get_rect(self): """ Get rectangle Returns: win32structures.RECT """ if self.app and self._top_window: return self._top_window.rectangle() else: return RECT(right=GetSystemMetrics(0), bottom=GetSystemMetrics(1)) @require_app def get_title(self): """ Get the window title Returns: window title """ return self._top_window.texts() @require_app def get_pos(self): """ Get the window position coordinates Returns: coordinates of topleft corner of the window (left, top) """ rect = self.get_rect() return (rect.left, rect.top) @require_app def move(self, pos): """ Move window to given coordinates Args: pos: coordinates (x, y) where to move the window Returns: None """ self._top_window.MoveWindow(x=pos[0], y=pos[1]) @require_app def kill(self): """ Kill the application Returns: None """ self.app.kill() def _action_pos(self, pos): if self.app: pos = self._windowpos_to_screenpos(pos) pos = (int(pos[0]), int(pos[1])) return pos # @property # def handle(self): # return self._top_window.handle @property def focus_rect(self): return self._focus_rect @focus_rect.setter def focus_rect(self, value): # set focus rect to get rid of window border assert len( value) == 4, "focus rect must be in [left, top, right, bottom]" self._focus_rect = value def get_current_resolution(self): rect = self.get_rect() w = (rect.right + self._focus_rect[2]) - (rect.left + self._focus_rect[0]) h = (rect.bottom + self._focus_rect[3]) - (rect.top + self._focus_rect[1]) return w, h def _windowpos_to_screenpos(self, pos): """ Convert given position relative to window topleft corner to screen coordinates Args: pos: coordinates (x, y) Returns: converted position coordinates """ rect = self.get_rect() pos = (int( (pos[0] + rect.left + self._focus_rect[0]) * self._dpifactor), int((pos[1] + rect.top + self._focus_rect[1]) * self._dpifactor)) return pos def get_ip_address(self): """ Return default external ip address of the windows os. Returns: :py:obj:`str`: ip address """ return socket.gethostbyname(socket.gethostname())
# Copyright 2019 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. from selenium import webdriver from pywinauto.application import Application from pywinauto.findwindows import ElementNotFoundError import os options = webdriver.ChromeOptions() options.add_argument("--force-renderer-accessibility") os.environ["CHROME_LOG_FILE"] = r"c:\temp\chrome_log.txt" driver = webdriver.Chrome( "C:/ProgramData/chocolatey/lib/chromedriver/tools/chromedriver.exe", chrome_options=options, service_args=["--verbose", r"--log-path=c:\temp\chromedriver.log"]) try: app = Application(backend="uia") app.connect(title_re='.*Chrome') app.top_window().child_window(title="Bookmarks", control_type="ToolBar") \ .print_control_identifiers() print "Bookmarkbar is found" except ElementNotFoundError: print "Bookmarkbar is missing" finally: driver.quit()
driver.find_element(By.XPATH, "//input[@id='txtUsername']").send_keys('admin') driver.find_element(By.ID, 'txtPassword').send_keys('qtpsudhakar') driver.find_element(By.ID, 'txtPassword').submit() driver.find_element(By.LINK_TEXT, "PIM").click() driver.find_element(By.LINK_TEXT, "Add Employee").click() driver.find_element(By.ID, "firstName").send_keys("sudhakar") driver.find_element(By.ID, "lastName").send_keys("ka") driver.find_element(By.CSS_SELECTOR, "#location_inputfileddiv input.select-dropdown").click() driver.find_element( By.XPATH, "//div[@id='location_inputfileddiv']//span[contains(text(),'Canadian Regional HQ')]" ).click() driver.find_element(By.CSS_SELECTOR, "label#photo-preview-lable").click() # driver.find_element(By.CSS_SELECTOR,"label#photo-preview-lable").send_keys(r"C:\Users\envy\Desktop\PythonForTestersB2\selenium.png") time.sleep(2) app = Application() hwnd = findwindows.find_windows(class_name='#32770', title='Open') print(hwnd) window = app.connect(handle=hwnd[0]) # app.top_window().PrintControlIdentifiers() app.top_window().Edit.type_keys( '{}'.format(r"C:\Users\envy\Desktop\PythonForTestersB2\selenium.png")) app.top_window()['&OpenButton'].click()
for x in range(board_width): xmin = drop_width * x xmax = drop_width * (x + 1) box = (xmin, ymin, xmax, ymax) img = board_img.crop(box) img = img.resize((DROP_SIZE, DROP_SIZE)) img.save("sample/drop_{}s.png".format(y * board_width + x + 1)) color = k_nn(img) board.append(color) return board #Apowersoftとの接続を試みる(失敗なら起動) app = Application() try: app.connect(path=APP_DIR) except: app.start(cmd_line=APP_DIR) #app[APP_NAME].move_window(x=None, y=None, width=APP_WIDTH, height=APP_HEIGHT, repaint=True) # 事前にテンプレート画像を1次元ベクトル化しておく for i in range(1, TEMPLATE_NUM + 1): img = Image.open("template/drop_{}.png".format(i)) img = img.resize((DROP_SIZE, DROP_SIZE)) templates.append(np.asarray(img, dtype="int32")) api = Flask(__name__) CORS(api)
sleep(1) # 双击账号并取消文本 mouse.double_click(button="left", coords=(925, 567)) keyboard.SendKeys('{BACKSPACE}') # 键盘 BACKSPACE keyboard.SendKeys('admingltest') # 输入账号 sleep(1) keyboard.SendKeys('{TAB}') # TAB keyboard.SendKeys('{BACKSPACE}') # 键盘 BACKSPACE keyboard.SendKeys('123abc') # 输入密码 sleep(1) 2 mouse.click(button="left", coords=(979, 684)) # 点击登录 sleep(3) app = app.connect( title_re="康华检验平台", class_name="WindowsForms10.Window.8.app.0.2eed1ca_r9_ad1") # 连接到现运行程序 # print(app["康华检验平台"].print_control_identifiers()) # 显示窗口的子窗口、控件等 # print(app.top_window().print_control_identifiers()) # print(app["康华检验平台"]['Dock Top'].print_control_identifiers()) mouse.click(button="left", coords=(193, 41)) # 点击检验管理 sleep(1) mouse.click(button="left", coords=(212, 74)) # 点击常规检验 sleep(3) mouse.click(button="left", coords=(588, 253)) # 点击仪器文本框 keyboard.SendKeys('{BACKSPACE}') # 键盘 BACKSPACE keyboard.SendKeys('E601发光仪') # 输入仪器名称 sleep(1) keyboard.SendKeys('{ENTER}') # 回车
class Windows(Device): """Windows client.""" def __init__(self, handle=None, dpifactor=1, **kwargs): self.app = None self.handle = int(handle) if handle else None # windows high dpi scale factor, no exact way to auto detect this value for a window # reference: https://msdn.microsoft.com/en-us/library/windows/desktop/mt843498(v=vs.85).aspx self._dpifactor = float(dpifactor) self._app = Application() self._top_window = None self._focus_rect = (0, 0, 0, 0) self.mouse = mouse self.keyboard = keyboard self._init_connect(handle, kwargs) def _init_connect(self, handle, kwargs): if handle: self.connect(handle=handle) elif kwargs: self.connect(**kwargs) def connect(self, handle=None, **kwargs): """ Connect to window and set it foreground Args: **kwargs: optional arguments Returns: None """ if handle: handle = int(handle) self.app = self._app.connect(handle=handle) self._top_window = self.app.window(handle=handle).wrapper_object() else: self.app = self._app.connect(**kwargs) self._top_window = self.app.top_window().wrapper_object() self.set_foreground() def shell(self, cmd): """ Run shell command in subprocess Args: cmd: command to be run Raises: subprocess.CalledProcessError: when command returns non-zero exit status Returns: command output as a byte string """ return subprocess.check_output(cmd, shell=True) def snapshot(self, filename="tmp.png"): """ Take a screenshot and save it to `tmp.png` filename by default Args: filename: name of file where to store the screenshot Returns: display the screenshot """ if not filename: filename = "tmp.png" if self.handle: screen = screenshot(filename, self.handle) else: screen = screenshot(filename) if self.app: rect = self.get_rect() screen = aircv.crop_image(screen, [rect.left, rect.top, rect.right, rect.bottom]) if self._focus_rect != (0, 0, 0, 0): height, width = screen.shape[:2] rect = (self._focus_rect[0], self._focus_rect[1], width + self._focus_rect[2], height + self._focus_rect[3]) screen = aircv.crop_image(screen, rect) if filename: aircv.imwrite(filename, screen) return screen def keyevent(self, keyname, **kwargs): """ Perform a key event References: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html Args: keyname: key event **kwargs: optional arguments Returns: None """ self.keyboard.SendKeys(keyname) def text(self, text, **kwargs): """ Input text Args: text: text to input **kwargs: optional arguments Returns: None """ self.keyevent(text) def touch(self, pos, **kwargs): # def touch(self, pos, times=1, duration=0.01): """ Perform mouse click action References: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.mouse.html Args: pos: coordinates where to click **kwargs: optional arguments Returns: None """ # self.mouse.click(coords=self._action_pos(pos), **kwargs) duration = kwargs.get("duration", 0.01) times = kwargs.get("times", 1) right_click = kwargs.get("right_click", False) button = "right" if right_click else "left" coords = self._action_pos(pos) print(coords) for _ in range(times): self.mouse.press(button=button, coords=coords) time.sleep(duration) self.mouse.release(button=button, coords=coords) def swipe(self, p1, p2, duration=0.8, steps=5): """ Perform swipe (mouse press and mouse release) Args: p1: start point p2: end point duration: time interval to perform the swipe action steps: size of the swipe step Returns: None """ from_x, from_y = self._action_pos(p1) to_x, to_y = self._action_pos(p2) interval = float(duration) / (steps + 1) self.mouse.press(coords=(from_x, from_y)) time.sleep(interval) for i in range(1, steps): self.mouse.move(coords=( int(from_x + (to_x - from_x) * i / steps), int(from_y + (to_y - from_y) * i / steps), )) time.sleep(interval) for i in range(10): self.mouse.move(coords=(to_x, to_y)) time.sleep(interval) self.mouse.release(coords=(to_x, to_y)) def start_app(self, path): """ Start the application Args: path: full path to the application Returns: None """ self.app = self._app.start(path) def stop_app(self, pid): """ Stop the application Args: pid: proccess ID of the application to be stopped Returns: None """ self._app.connect(process=pid).kill() @require_app def set_foreground(self): """ Bring the window foreground Returns: None """ SetForegroundWindow(self._top_window) @require_app def get_rect(self): """ Get rectangle Returns: None """ return self._top_window.rectangle() @require_app def get_title(self): """ Get the window title Returns: window title """ return self._top_window.texts() @require_app def get_pos(self): """ Get the window position coordinates Returns: coordinates of topleft corner of the window (left, top) """ rect = self.get_rect() return (rect.left, rect.top) @require_app def move(self, pos): """ Move window to given coordinates Args: pos: coordinates (x, y) where to move the window Returns: None """ self._top_window.MoveWindow(x=pos[0], y=pos[1]) @require_app def kill(self): """ Kill the application Returns: None """ self.app.kill() def _action_pos(self, pos): if self.app: pos = self._windowpos_to_screenpos(pos) pos = (int(pos[0]), int(pos[1])) return pos # @property # def handle(self): # return self._top_window.handle @property def focus_rect(self): return self._focus_rect @focus_rect.setter def focus_rect(self, value): # set focus rect to get rid of window border assert len(value) == 4, "focus rect must be in [left, top, right, bottom]" self._focus_rect = value def get_current_resolution(self): rect = self.get_rect() w = (rect.right + self._focus_rect[2]) - (rect.left + self._focus_rect[0]) h = (rect.bottom + self._focus_rect[3]) - (rect.top + self._focus_rect[1]) return w, h def _windowpos_to_screenpos(self, pos): """ Convert given position relative to window topleft corner to screen coordinates Args: pos: coordinates (x, y) Returns: converted position coordinates """ rect = self.get_rect() pos = (int((pos[0] + rect.left + self._focus_rect[0]) * self._dpifactor), int((pos[1] + rect.top + self._focus_rect[1]) * self._dpifactor)) return pos
class yunduan(): def __init__(self): # self.func 挂对话框 self.func = None self.nowdir = os.getcwd() self.hld = Image.open("{}\\temp\\hld.png".format(self.nowdir)) def getpid(self, processname): # pset = set() proc = os.popen( 'tasklist /NH /FO "csv" /FI "IMAGENAME eq {}"'.format(processname)) procstrs = proc.read() # print(procstrs) procl = procstrs.splitlines() for l in procl: ll = l.split(",") self.pid = eval(ll[1]) # print(self.pid) def linkprocess(self): self.pid = int(self.pid) self.app = Application(backend='uia') self.app.connect(process=self.pid) self.dlg = self.app.windows()[0] print(self.dlg) def setcontrol(self): for a in self.dlg.children(): ## print(a.class_name()) if a.class_name() == "TFrmBottom": self.edt = a.children()[1] for b in a.children(): if b.class_name() == 'TListBox': self.msglistitem = b.children()[2] ## im = self.msglistitem.capture_as_image() ## im.save("{}\\temp\\hld.png".format(self.nowdir)) if b.class_name() == "TFrmIcon": self.wu = b def openwu(self): if self.wu == None: print("wu is None") return ''' 查找弹出的对话框 ''' winlist = {} for a in self.dlg.children(): winlist[a.class_name()] = a if "TFrmFunction" in winlist.keys(): self.func = winlist["TFrmFunction"] else: # 如果窗口没有显示,就点击无字 x = self.wu.rectangle().left x = x + random.randint(5, 20) y = self.wu.rectangle().top y = y + random.randint(5, 20) mouse.move(coords=(x, y)) mouse.click(coords=(x, y)) ## print("======") for a in self.dlg.children(): if a.class_name() == "TFrmFunction": self.func = a break # tab标签页 for b in self.func.children()[0].children(): if b.class_name() == "TPageControl": self.tab = b ## print("self.tab:",self.tab.class_name()) for c in self.tab.children(): ## print("c=",c.texts()) if c.class_name() == "msctls_updown32": self.d = c x = self.d.rectangle().left x = x + random.randint(5, 10) y = self.d.rectangle().top y = y + random.randint(5, 10) mouse.move(coords=(x, y)) mouse.click(coords=(x, y)) mouse.click(coords=(x, y)) x = self.d.rectangle().left x = x + random.randint(5, 10) + 20 y = self.d.rectangle().top y = y + random.randint(5, 10) mouse.move(coords=(x, y)) mouse.click(coords=(x, y)) mouse.click(coords=(x, y)) if c.texts()[0] == "其他": self.qita = c ## print("qita=",self.qita.texts()) x = self.qita.rectangle().left x = x + random.randint(5, 10) y = self.qita.rectangle().top y = y + random.randint(5, 10) mouse.move(coords=(x, y)) mouse.click(coords=(x, y)) for a in self.tab.children(): for b in a.children(): ## print(b.class_name()) if b.class_name() == "TGroupBox": for c in b.children(): ## print(c.class_name()) ## print(c.texts()) if c.class_name() == "TButton": self.killset = c if c.texts()[0] == "自动杀怪": self.autokillcb = c cl = b.children() self.huticb = cl[0] self.point = cl[2] self.pointlist = cl[3] self.monster = cl[4] self.monsterlist = cl[5] self.autokillcb = cl[6] def startkill(self): killstatus = self.autokillcb.get_toggle_state() if killstatus == 0: self.autokillcb.click() ## print(self.autokillcb.get_toggle_state()) def stopkill(self): killstatus = self.autokillcb.get_toggle_state() if killstatus == 1: self.autokillcb.click() ## print(self.autokillcb.get_toggle_state()) def openkillset(self): setstr = self.killset.texts() if setstr[0] == "配置->": self.killset.click() def closekillset(self): setstr = self.killset.texts() if setstr[0] == "配置<-": self.killset.click() def addmonster(self, monster): self.monster.set_edit_text(monster) self.monster.type_keys("{ENTER}") def addpoint(self, point): self.point.set_edit_text(point) self.point.type_keys("{ENTER}") def clearpoint(self): listitems = self.pointlist.get_items() x = listitems[0].rectangle().left x = x + 5 y = listitems[0].rectangle().top y = y + 5 for i in range(len(listitems)): mouse.double_click(coords=(x, y)) def clearmonster(self): listitems = self.monsterlist.get_items() x = listitems[0].rectangle().left x = x + 5 y = listitems[0].rectangle().top y = y + 5 for i in range(3): mouse.double_click(coords=(x, y)) def _compareimage(self, firstImage, secondImage): """ return the two image's different value """ "Calculate the root-mean-square difference between two images" h1 = firstImage.histogram() h2 = secondImage.histogram() rms = math.sqrt( reduce(operator.add, map(lambda a, b: (a - b)**2, h1, h2)) / len(h1)) ## print( {'图片比较':'图片【%s】和图片【%s】比较的差值为【%s】' % ( str( firstImage ), str( secondImage ), str( rms ) )} ) return rms def _get_area_image(self): for i in range(2): time.sleep(1) self.edt.set_edit_text("/where") self.edt.type_keys("{ENTER}") self.area = self.msglistitem.capture_as_image() def compareimage(self): # self.area = Image.open("{}\\temp\\ccyn.png".format(self.nowdir)) # self.hld = Image.open("{}\\temp\\hld.png".format(self.nowdir)) self._get_area_image() sz = self.area.size self.areacut = self.area.crop((36, 0, sz[0], sz[1])) # self.areacut.show() sz = self.hld.size self.hldcut = self.hld.crop((36, 0, sz[0], sz[1])) # self.hldcut.show() return self._compareimage(self.areacut, self.hldcut)
def hide_hud_macro(): app = Application() app.connect(title_re='Rocket League.*') win = app.window_(title_re='Rocket League.*') win.type_keys("{h down}" "{h up}")
class Windows(Device): """Windows client.""" def __init__(self, handle=None, dpifactor=1, **kwargs): self.app = None self.handle = int(handle) if handle else None # windows high dpi scale factor, no exact way to auto detect this value for a window # reference: https://msdn.microsoft.com/en-us/library/windows/desktop/mt843498(v=vs.85).aspx self._dpifactor = float(dpifactor) self._app = Application() self._top_window = None self._focus_rect = (0, 0, 0, 0) self.mouse = mouse self.keyboard = keyboard self._init_connect(handle, kwargs) self.screen = mss() self.monitor = self.screen.monitors[0] # 双屏的时候,self.monitor为整个双屏 self.main_monitor = self.screen.monitors[ 1] # 双屏的时候,self.main_monitor为主屏 @property def uuid(self): return self.handle def _init_connect(self, handle, kwargs): if handle: self.connect(handle=handle) elif kwargs: self.connect(**kwargs) def connect(self, handle=None, **kwargs): """ Connect to window and set it foreground Args: **kwargs: optional arguments Returns: None """ if handle: handle = int(handle) self.app = self._app.connect(handle=handle) self._top_window = self.app.window(handle=handle).wrapper_object() else: for k in ["process", "timeout"]: if k in kwargs: kwargs[k] = int(kwargs[k]) self.app = self._app.connect(**kwargs) self._top_window = self.app.top_window().wrapper_object() self.set_foreground() def shell(self, cmd): """ Run shell command in subprocess Args: cmd: command to be run Raises: subprocess.CalledProcessError: when command returns non-zero exit status Returns: command output as a byte string """ return subprocess.check_output(cmd, shell=True) def snapshot(self, filename=None): """ Take a screenshot and save it in ST.LOG_DIR folder Args: filename: name of the file to give to the screenshot, {time}.jpg by default Returns: display the screenshot """ if self.handle: screen = screenshot(filename, self.handle) else: screen = screenshot(filename) if self.app: rect = self.get_rect() screen = aircv.crop_image( screen, [rect.left, rect.top, rect.right, rect.bottom]) if not screen.any(): if self.app: rect = self.get_rect() screen = aircv.crop_image( screenshot(filename), [rect.left, rect.top, rect.right, rect.bottom]) if self._focus_rect != (0, 0, 0, 0): height, width = screen.shape[:2] rect = (self._focus_rect[0], self._focus_rect[1], width + self._focus_rect[2], height + self._focus_rect[3]) screen = aircv.crop_image(screen, rect) if filename: aircv.imwrite(filename, screen) return screen def keyevent(self, keyname, **kwargs): """ Perform a key event References: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html Args: keyname: key event **kwargs: optional arguments Returns: None """ self.keyboard.SendKeys(keyname) def text(self, text, **kwargs): """ Input text Args: text: text to input **kwargs: optional arguments Returns: None """ self.keyevent(text) def _fix_op_pos(self, pos): """Fix operation position.""" # 如果是全屏的话,就进行双屏修正,否则就正常即可 if not self.handle: pos = list(pos) pos[0] = pos[0] + self.monitor["left"] pos[1] = pos[1] + self.monitor["top"] return pos def touch(self, pos, **kwargs): """ Perform mouse click action References: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.mouse.html Args: pos: coordinates where to click **kwargs: optional arguments Returns: None """ duration = kwargs.get("duration", 0.01) right_click = kwargs.get("right_click", False) button = "right" if right_click else "left" coords = self._action_pos(pos) coords = self._fix_op_pos(coords) self.mouse.press(button=button, coords=coords) time.sleep(duration) self.mouse.release(button=button, coords=coords) def double_click(self, pos): pos = self._fix_op_pos(pos) coords = self._action_pos(pos) self.mouse.double_click(coords=coords) def swipe(self, p1, p2, duration=0.8, steps=5): """ Perform swipe (mouse press and mouse release) Args: p1: start point p2: end point duration: time interval to perform the swipe action steps: size of the swipe step Returns: None """ # 设置坐标时相对于整个屏幕的坐标: x1, y1 = self._fix_op_pos(p1) x2, y2 = self._fix_op_pos(p2) # 双屏时,涉及到了移动的比例换算: if len(self.screen.monitors) > 2: ratio_x = (self.monitor["width"] + self.monitor["left"]) / self.main_monitor["width"] ratio_y = (self.monitor["height"] + self.monitor["top"]) / self.main_monitor["height"] x2 = int(x1 + (x2 - x1) * ratio_x) y2 = int(y1 + (y2 - y1) * ratio_y) p1, p2 = (x1, y1), (x2, y2) from_x, from_y = self._action_pos(p1) to_x, to_y = self._action_pos(p2) interval = float(duration) / (steps + 1) self.mouse.press(coords=(from_x, from_y)) time.sleep(interval) for i in range(1, steps): self.mouse.move(coords=( int(from_x + (to_x - from_x) * i / steps), int(from_y + (to_y - from_y) * i / steps), )) time.sleep(interval) for i in range(10): self.mouse.move(coords=(to_x, to_y)) time.sleep(interval) self.mouse.release(coords=(to_x, to_y)) def start_app(self, path, **kwargs): """ Start the application Args: path: full path to the application kwargs: reference: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.application.html#pywinauto.application.Application.start Returns: None """ self.app = self._app.start(path, **kwargs) def stop_app(self, pid): """ Stop the application Args: pid: process ID of the application to be stopped Returns: None """ self._app.connect(process=pid).kill() @require_app def set_foreground(self): """ Bring the window foreground Returns: None """ SetForegroundWindow(self._top_window) def get_rect(self): """ Get rectangle Returns: win32structures.RECT """ if self.app and self._top_window: return self._top_window.rectangle() else: return RECT(right=GetSystemMetrics(0), bottom=GetSystemMetrics(1)) @require_app def get_title(self): """ Get the window title Returns: window title """ return self._top_window.texts() @require_app def get_pos(self): """ Get the window position coordinates Returns: coordinates of topleft corner of the window (left, top) """ rect = self.get_rect() return (rect.left, rect.top) @require_app def move(self, pos): """ Move window to given coordinates Args: pos: coordinates (x, y) where to move the window Returns: None """ self._top_window.MoveWindow(x=pos[0], y=pos[1]) @require_app def kill(self): """ Kill the application Returns: None """ self.app.kill() def _action_pos(self, pos): if self.app: pos = self._windowpos_to_screenpos(pos) pos = (int(pos[0]), int(pos[1])) return pos # @property # def handle(self): # return self._top_window.handle @property def focus_rect(self): return self._focus_rect @focus_rect.setter def focus_rect(self, value): # set focus rect to get rid of window border assert len( value) == 4, "focus rect must be in [left, top, right, bottom]" self._focus_rect = value def get_current_resolution(self): rect = self.get_rect() w = (rect.right + self._focus_rect[2]) - (rect.left + self._focus_rect[0]) h = (rect.bottom + self._focus_rect[3]) - (rect.top + self._focus_rect[1]) return w, h def _windowpos_to_screenpos(self, pos): """ Convert given position relative to window topleft corner to screen coordinates Args: pos: coordinates (x, y) Returns: converted position coordinates """ rect = self.get_rect() pos = (int( (pos[0] + rect.left + self._focus_rect[0]) * self._dpifactor), int((pos[1] + rect.top + self._focus_rect[1]) * self._dpifactor)) return pos def get_ip_address(self): """ Return default external ip address of the windows os. Returns: :py:obj:`str`: ip address """ return socket.gethostbyname(socket.gethostname())