@contextmanager<EOL><INDENT>def window(self, window):<DEDENT>
original = self.current_window<EOL>if window != original:<EOL><INDENT>self.switch_to_window(window)<EOL><DEDENT>self._scopes.append(None)<EOL>try:<EOL><INDENT>yield<EOL><DEDENT>finally:<EOL><INDENT>self._scopes.pop()<EOL>if original != window:<EOL><INDENT>self.switch_to_window(original)<EOL><DEDENT><DEDENT>
This method does the following:

1. Switches to the given window (it can be located by window instance/lambda/string).
2. Executes the given block (within window located at previous step).
3. Switches back (this step will be invoked even if exception happens at second step).

Args:
    window (Window | lambda): The desired :class:`Window`, or a lambda that will be run in
        the context of each open window and returns ``True`` for the desired window.