diff --git a/pywinauto/controls/HwndWrapper.py b/pywinauto/controls/HwndWrapper.py index d11d550d2..5bc47278c 100644 --- a/pywinauto/controls/HwndWrapper.py +++ b/pywinauto/controls/HwndWrapper.py @@ -1565,12 +1565,11 @@ def GetFocus(self): #----------------------------------------------------------- def SetFocus(self): - """ Set the focus to this control. + Bring the window to the foreground first if necessary. """ - # find the current foreground window cur_foreground = win32gui.GetForegroundWindow() @@ -1593,10 +1592,6 @@ def SetFocus(self): cur_fore_thread, 1) - self.actions.log('Call SetForegroundWindow within attached ' - 'threads - {0} & {1}.'.format(control_thread, - cur_fore_thread, - )) win32gui.SetForegroundWindow(self.handle) # ensure foreground window has changed to the target @@ -1605,7 +1600,7 @@ def SetFocus(self): Timings.setfocus_timeout, Timings.setfocus_retry, lambda: win32gui.GetForegroundWindow() - in [self.TopLevelParent().handle, 0]) + in [self.TopLevelParent().handle, 0]) # get the threads again to check they are still valid. cur_fore_thread = win32process.GetWindowThreadProcessId( @@ -1620,7 +1615,6 @@ def SetFocus(self): 0) else: # same threads - just set the foreground window - self.actions.log('Call SetForegroundWindow within one thread.') win32gui.SetForegroundWindow(self.handle) # make sure that we are idle before returning diff --git a/pywinauto/timings.py b/pywinauto/timings.py index bc8cb09da..554a64064 100644 --- a/pywinauto/timings.py +++ b/pywinauto/timings.py @@ -62,6 +62,8 @@ * after_windowclose_retry (default .5) * after_setfocus_wait (default .06) +* setfocus_timeout (default 2) +* setfocus_retry (default .1) * after_setcursorpos_wait (default .01)