fortrace.utility.applications package

Subpackages

Submodules

fortrace.utility.applications.application module

class fortrace.utility.applications.application.ApplicationEvent(*values)[source]

Bases: Enum

Application events that are processed by the desktop environment.

APPLICATION_POPUP_CLOSED = 7
APPLICATION_POPUP_OPENED = 6
APPLICATION_RESIZED = 5
CLOSED = 1
FOCUS_APPLICATION = 4
FOCUS_SHIFTED = 3
NEW_APPLICATION_OPENED = 2
class fortrace.utility.applications.application.ApplicationType(*values)[source]

Bases: Enum

Supported application types, used to select the correct factory method

FILE_MANAGER = 1
MAIL_CLIENT = 5
OTHER = 6
TERMINAL = 3
TEXT_EDITOR = 4
WEB_BROWSER = 2
class fortrace.utility.applications.application.FileDialogue(parent_application: GenericApplication)[source]

Bases: GenericPopup

save_to_directory(destination: Path | None = None, name: str | None = None)[source]
class fortrace.utility.applications.application.GenericApplication(name: str, application_type: ApplicationType, qemu_monitor_session: QEMUMonitorSession, parent_notifier: ParentNotifier)[source]

Bases: object

Representation of a generic graphic application window.

This class resembles the general interface of all graphical applications with which ForTrace might interact. It can be used to control applications with keyboard shortcuts and simple commands, without writing any application specific Python classes.

close()[source]

Close an application with ‘alt-f4’ key combination.

coordinates: tuple[int, int, int, int] | None
extract_text() tuple[list[tuple[int, int, int, int]], list[str]][source]

Extract text from application window.

Extracts the text visible in the application window. Uses OCR, thus the result is not 100% accurate, thus applying string similarity search is highly recommended.

Returns:

tuple of list with bounding boxes and the detected strings within

focus_element(text: str)[source]

Focus the element with the specified text.

This method acts as a stub for the integration of a screen parsing tool into ForTrace++. It ought to be overwritten on instance level, like it is done in the OmniParser example.

Parameters:

text – text to be searched for

property focused

Signals whether this application receives mouse and keyboard inputs.

property name: str

Name of this application (not unique if multiple instances are opened).

open_popup(screenshot_before_popup: bytes | PathLike | ndarray, popup_type: PopupType = PopupType.GENERIC, popup_min_size: int = 50000) GenericPopup[source]

React on the opening of a new popup window within the application window.

Parameters:
  • screenshot_before_popup – a screenshot taken of the application before the popup is opened

  • popup_type – specify the kind of popup to return

  • popup_min_size – the size of the popup in px

Returns:

Instance of opened popup window to interact with

perform_complex_action(func: Callable[[GenericApplication], Any]) Any[source]

Performs a complex action in an application.

Parameters:

func – Callable representing the action to perform

Returns:

returns whatever func returns

send_key_combination(key_combination: str, times: int = 1)[source]

Send a direct key combination to the application.

Parameters:
  • key_combination – key combination to be sent (using qemu key_codes)

  • times – number of times to send key combination

send_text(text: str, end_ret: bool = False)[source]

Send text to the application.

Parameters:
  • text – text to be sent

  • end_ret – should return be pressed after the text is entered?

Note

The text is allowed to contain ‘n’ and ‘r’ characters, which are respected

property size

Compute the size of the application window.

Returns:

The size of the application window in pixels. 0, if coordinates are unknown.

take_screenshot() ndarray[source]

Take screenshot of the application window.

Returns:

OpenCV image of the application window with all color channels

property uuid: UUID

UUID of the application (unique, even for multiple instances).

class fortrace.utility.applications.application.GenericPopup(parent_application: GenericApplication)[source]

Bases: GenericApplication

Representation of a popup window opened by another application.

Should not be used on its own, but created through GenericApplication’s open_popup method.

close()[source]

Notifies the desktop env about the closing of a popup window.

Note

Popups are closed indirectly by pressing a certain key and NOT alt-f4

class fortrace.utility.applications.application.ParentNotifier(*args, **kwargs)[source]

Bases: Protocol

Used to provide type hints and enable the IDE for static type checking.

It refers to DesktopEnvironment._on_change method.

class fortrace.utility.applications.application.PopupType(*values)[source]

Bases: Enum

FILE_DIALOGUE = 2
GENERIC = 1
WARNING = 3

fortrace.utility.applications.application_factory module

fortrace.utility.applications.application_factory.get_application(application_type: ApplicationType, name: str, qs: QEMUMonitorSession, parent_notifier: ParentNotifier, **kwargs) GenericApplication[source]

Factory to create an application object by calling the correct sub-factory.

Parameters:
  • application_type – ApplicationType to filter for correct sub-factory

  • name – name of the application (if not included ValueError is thrown)

  • qs – handle to QEMUMonitor

  • parent_notifier – attribute of desktop environment to handle changes in windows

  • **kwargs – relevant to certain applications that might be started with extra arguments, e.g., Terminals

Returns:

Handle to opened application

Module contents