pywinauto_recorder.recorder.Recorder

class pywinauto_recorder.recorder.Recorder[source]

Bases: Thread

Recorder is a class thread used to record UI events in clipboard or in a file.

Example of code using ‘Recorder’:
from pywinauto_recorder.recorder import Recorder
from pywinauto_recorder.player import UIPath, click, move, playback

recorder = Recorder()
recorder.start_recording()
with UIPath("Untitled - Notepad||Window"):
        doc = move("Text editor||Document")
        time.sleep(0.5)
        click(doc)
        utf8 = move("||Pane-> UTF-8||Text")
        time.sleep(0.5)
        click(utf8)
recorded_python_script = recorder.stop_recording()
recorder.quit()
playback(filename=recorded_python_script)

The above code clicks on the text field and then on ‘utf8’. All these events are recorded in a file. Then the file is replayed.

Methods

get_last_element_event()

It returns the last element of the event.

playback([str_code, filename])

This function plays back a string of code or a Python file.

quit()

The function clears the main and info overlays, sets the mode to 'Quit', and then joins the thread.

run()

The function is called in a loop, and it tries to find the unique element under the mouse cursor.

start_recording()

It adds a mouse move event to the event list, displays the record icon to the main overlay, clears and refreshes the main and info overlays, and then sets the mode to "Record".

stop_recording()

It cleans the event list, displays the stop icon to the main overlay, clears and refreshes the main and info overlays, writes the Python script, and then sets the mode to "Stop".

Attributes

daemon

A boolean value indicating whether this thread is a daemon thread.

ident

Thread identifier of this thread or None if it has not been started.

mode

It returns the mode of the recorder: "Record", "Play", "Info", "Stop", "Quit"

name

A string used for identification purposes only.

native_id

Native integral thread ID of this thread, or None if it has not been started.

process_menu_click_mode

If True, the process menu events are recorded else they are ignored.

relative_coordinate_mode

If True, the relative coordinates are recorded else they are ignored.

smart_mode

If True, the smart mode is activated.

property daemon

A boolean value indicating whether this thread is a daemon thread.

This must be set before start() is called, otherwise RuntimeError is raised. Its initial value is inherited from the creating thread; the main thread is not a daemon thread and therefore all threads created in the main thread default to daemon = False.

The entire Python program exits when only daemon threads are left.

get_last_element_event()[source]

It returns the last element of the event. :return: The last element event.

property ident

Thread identifier of this thread or None if it has not been started.

This is a nonzero integer. See the get_ident() function. Thread identifiers may be recycled when a thread exits and another thread is created. The identifier is available even after the thread has exited.

isAlive()

Return whether the thread is alive.

This method is deprecated, use is_alive() instead.

is_alive()

Return whether the thread is alive.

This method returns True just before the run() method starts until just after the run() method terminates. The module function enumerate() returns a list of all alive threads.

join(timeout=None)

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

property mode

It returns the mode of the recorder: “Record”, “Play”, “Info”, “Stop”, “Quit”

return

The mode of the recorder.

property name

A string used for identification purposes only.

It has no semantics. Multiple threads may be given the same name. The initial name is set by the constructor.

property native_id

Native integral thread ID of this thread, or None if it has not been started.

This is a non-negative integer. See the get_native_id() function. This represents the Thread ID as reported by the kernel.

playback(str_code='', filename='')[source]

This function plays back a string of code or a Python file.

Parameters
  • str_code – The code to be played back

  • filename – The name of the file coresponding to the code to be played back

property process_menu_click_mode

If True, the process menu events are recorded else they are ignored.

Returns

The state of the process menu click mode.

quit()[source]

The function clears the main and info overlays, sets the mode to ‘Quit’, and then joins the thread.

property relative_coordinate_mode

If True, the relative coordinates are recorded else they are ignored.

Returns

The state of the relative coordinates mode.

run()[source]

The function is called in a loop, and it tries to find the unique element under the mouse cursor.

property smart_mode

If True, the smart mode is activated. :return: The state of the smart mode.

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

start_recording()[source]

It adds a mouse move event to the event list, displays the record icon to the main overlay, clears and refreshes the main and info overlays, and then sets the mode to “Record”.

stop_recording()[source]

It cleans the event list, displays the stop icon to the main overlay, clears and refreshes the main and info overlays, writes the Python script, and then sets the mode to “Stop”. :return: The name of the file that was created.