예제 #1
0
    def inspect_element(
        cls,
        action: str = "Click",
        control_window: bool = True,
        recording: Optional[List["RecordElement"]] = None,
        verbose: bool = False,
    ) -> List[str]:
        """Inspect Windows element under mouse pointer.

        :param action: Action attached to the locator.
        :param control_window: Include relevant ``Control Window  ...`` statement or
            not.
        :param recording: Where to store records.
        :param verbose: Show exhaustive locators if `True`, otherwise just simple ones.
        """
        # TODO: Python syntax support too instead of just RF.
        output = []
        with auto.UIAutomationInitializerInThread(debug=False):
            control = auto.ControlFromCursor()
            parent_control = control.GetParentControl()
            try:
                top_level_control = control.GetTopLevelControl()
            except AttributeError:
                top_level_control = None
                top_level_name = top_level_handle = "N/A"
            else:
                top_level_name = top_level_control.Name
                top_level_handle = top_level_control.NativeWindowHandle

            parent_locator = (
                cls._get_element_key_properties(parent_control, verbose=verbose)
                or "N/A"
            )
            child_locator = (
                cls._get_element_key_properties(control, verbose=verbose) or "N/A"
            )
            locator_path = f"{parent_locator} > {child_locator}"
            if "name:" in child_locator or "id:" in child_locator:
                locator_path = child_locator
            if control_window:
                output.append(f"Control Window  {top_level_name}")
            if action:
                output.append(f"{action}  {locator_path}")
            else:
                output.append(locator_path)

            if recording is not None:
                recording.append(
                    {
                        "type": "locator",
                        "top": top_level_name,
                        "top_handle": top_level_handle,
                        "x": top_level_control,
                        "locator": locator_path,
                        "name": parent_control.Name if parent_control else None,
                        "control": parent_control,
                    }
                )

        return output
def show(stopEvent: Event, handle: List[int]):
    with auto.UIAutomationInitializerInThread():
        for handle in handles:
            win = auto.ControlFromHandle(handle)
            win.Show(0)
            if auto.IsIconic(handle):
                win.ShowWindow(auto.SW.Restore, 0)
def threadFunc(uselessRoot):
    """
    If you want to use UI Controls in a new thread, create an UIAutomationInitializerInThread object first.
    But you can't use use a Control or a Pattern created in a different thread.
    So you can't create a Control or a Pattern in main thread and then pass it to a new thread and use it.
    """
    # print(uselessRoot)# you cannot use uselessRoot because it is a control created in a different thread
    th = threading.currentThread()
    auto.Logger.WriteLine(
        '\nThis is running in a new thread. {} {}'.format(th.ident, th.name),
        auto.ConsoleColor.Cyan)
    time.sleep(2)
    with auto.UIAutomationInitializerInThread(debug=True):
        auto.GetConsoleWindow().CaptureToImage('console_newthread.png')
        newRoot = auto.GetRootControl(
        )  # ok, root control created in current thread
        auto.EnumAndLogControl(newRoot, 1)
    auto.Logger.WriteLine('\nThread exits. {} {}'.format(th.ident, th.name),
                          auto.ConsoleColor.Cyan)
예제 #4
0
def capture(stopEvent: Event):
    with auto.UIAutomationInitializerInThread(debug=True):
        control = auto.ControlFromCursor()
        control.CaptureToImage('control.png')
        subprocess.Popen('control.png', shell=True)
def hide(stopEvent: Event, handles: List[int]):
    with auto.UIAutomationInitializerInThread():
        for handle in handles:
            win = auto.ControlFromHandle(handle)
            win.Hide(0)