def __init__(self, app, is_unicode=False): """Constructor inject dll, set socket and hook (one application - one class instanse)""" self.app = app self.is_unicode = is_unicode self.pid = processid(self.app.handle) if not sysinfo.is_x64_Python() == is64bitprocess(self.pid): raise RuntimeError( "Application and Python must be both 32-bit or both 64-bit") self.h_process = self._get_process_handle(self.pid) self.dll_path = os.path.abspath("{0}pywinmsg{1}{2}.dll".format( dll_path, "64" if is64bitprocess(self.pid) else "32", "u" if self.is_unicode else "")) self._inject_dll_to_process() self.sock = socket(AF_INET, SOCK_DGRAM) self.sock.bind(('', 0)) port = self.sock.getsockname()[1] self._remote_call_int_param_func("InitSocket", port) self._remote_call_void_func("SetMsgHook")
def get_pid(self, app=None, handle=None): """Get the process id (pid) for the specified element. Parameters ---------- app: object, optional Pywinauto application object. handle: int, optional Window handle. Returns ------- int Process ID for the application or process that conrols the specified window. """ if app: handle = app.window().handle pid = handleprops.processid(handle) return pid
def get_window_info(): all_window_handles = findwindows.enum_windows() for window_handle in all_window_handles: if handleprops.isvisible(window_handle): pos_x = handleprops.rectangle(window_handle).left pos_y = handleprops.rectangle(window_handle).top size_x = handleprops.rectangle(window_handle).width() size_y = handleprops.rectangle(window_handle).height() title_name = handleprops.text(window_handle) class_name = handleprops.classname(window_handle) pid = handleprops.processid(window_handle) date_time = datetime.datetime.now() # Note: Minimized windows have negative pos_x and pos_y values (and smaller sizes). window_info = [ pos_x, pos_y, size_x, size_y, title_name, class_name, pid, date_time ] window_db_id = database.create_window_record(window_info) logger.info( 'OpenWindow record created in database (db_id %i).' % window_db_id)
def testProcessId(self): self.assertEqual(self.ctrl.process_id, processid(self.handle))
def test_processid(self): """Make sure processid() function works""" self.assertEquals(self.app.process, processid(self.dlghandle)) self.assertEquals(self.app.process, processid(self.edit_handle))
def test_processid(self): "Make sure the friendly class is set correctly" self.assertEquals(self.app.process, processid(self.dlghandle)) self.assertEquals(self.app.process, processid(self.edit_handle))
def testProcessId(self): """Test process_id equals""" self.assertEqual(self.ctrl.process_id, processid(self.handle))
def test_processid(self): """Make sure processid() function works""" self.assertEqual(self.app.process, processid(self.dlghandle)) self.assertEqual(self.app.process, processid(self.edit_handle)) self.assertEqual(0, processid(sys.maxsize)) self.assertEqual(0, processid(None))
def test_processid(self): """Make sure processid() function works""" self.assertEqual(self.app.process, processid(self.dlghandle)) self.assertEqual(self.app.process, processid(self.edit_handle))