Skip to content

Definitions

Python ports of the C# FlaUI.Core.Definitions enums (ControlType, ToggleState, TreeScope, OrientationType, HeadingLevel, LiveSetting, ...). Member names and values mirror C# one to one: None members are spelled None_ because None is a Python keyword.

Values FlaUI hands back are converted at the boundary, so you can assert against the Python enums:

  • enum-typed element properties (Properties.orientation, heading_level, landmark_type, live_setting, visual_effects) and pattern properties (AnnotationPattern.annotation_type, StylesPattern.style) return Python enums from AutomationProperty.value / value_or_default;
  • AutomationBase.coalesce_events / connection_recovery_behavior read and accept CoalesceEventsOptions / ConnectionRecoveryBehaviorOptions;
  • structure-changed, notification and text-edit event callbacks receive StructureChangeType, NotificationKind / NotificationProcessing and TextEditChangeType.

VisualEffects is a [Flags] enum in C#, so it is an IntFlag in Python and combined effects round-trip. FrameworkIds.convert maps between a FrameworkType and the UIA FrameworkId string.

flaui.core.definitions

This module contains wrapper classes for the C# namespace FlaUI.Core.Definitions. It defines several enums for different types of controls in Microsoft UI Automation.

AnnotationType

Bases: Enum

Contains the annotation types FlaUI exposes through the Annotation pattern.

The member values are FlaUI's own enum values. UIA's raw annotation type ids (60000 and up, as returned by Properties.annotation_types) are a different number space and are not converted.

AutomationElementMode

Bases: Enum

Contains values that specify the type of reference to use when returning UI Automation elements.

CoalesceEventsOptions

Bases: Enum

Contains values that specify whether the automation coalesces events (AutomationBase.coalesce_events).

ConnectionRecoveryBehaviorOptions

Bases: Enum

Contains values that specify whether the automation recovers lost connections automatically.

ControlType

Bases: Enum

Types of controls in Microsoft UI Automation.

DockPosition

Bases: Enum

Contains values that specify the dock position of an element within a docking container.

ExpandCollapseState

Bases: Enum

Contains values that specify the expand/collapse state of a Microsoft UI Automation element that implements the ExpandCollapsePattern.

FrameworkIds

Python port of the C# static helper FlaUI.Core.Definitions.FrameworkIds.

It maps between a :class:~flaui.core.framework_types.FrameworkType and the UIA FrameworkId string ("WPF", "WinForm", "Win32", "XAML", "Qt"), delegating to FlaUI for exact parity.

convert(value) staticmethod

Convert a framework id string to a FrameworkType, or a FrameworkType to its id string.

Parameters:

Name Type Description Default
value Any

A UIA framework id string, or a Python or C# FrameworkType.

required

Returns:

Type Description
Any

The matching Python FrameworkType for a string input (FrameworkType.Unknown when the id is not recognised), otherwise the framework id string (None for FrameworkType.Unknown, "" for FrameworkType.none).

Source code in flaui/core/definitions.py
@staticmethod
def convert(value: Any) -> Any:
    """Convert a framework id string to a ``FrameworkType``, or a ``FrameworkType`` to its id string.

    :param value: A UIA framework id string, or a Python or C# ``FrameworkType``.
    :return: The matching Python ``FrameworkType`` for a string input (``FrameworkType.Unknown`` when the
        id is not recognised), otherwise the framework id string (``None`` for ``FrameworkType.Unknown``,
        ``""`` for ``FrameworkType.none``).
    """
    from flaui.core.framework_types import FrameworkType

    if isinstance(value, str):
        return to_python_enum(CSFrameworkIds.Convert(value), FrameworkType)
    if isinstance(value, FrameworkType):
        if value is FrameworkType.none:
            return ""
        value = value.value
    return CSFrameworkIds.Convert(value)

HeadingLevel

Bases: Enum

Contains values that describe the heading level of an element (Properties.heading_level).

LandmarkType

Bases: Enum

Contains values that describe the landmark type of an element (Properties.landmark_type).

LiveSetting

Bases: Enum

Contains values that describe how a live region announces changes (Properties.live_setting).

NotificationKind

Bases: Enum

Contains values that describe the kind of a notification event.

NotificationProcessing

Bases: Enum

Contains values that describe how a notification event should be processed.

OrientationType

Bases: Enum

Contains values that specify the orientation of a control (Properties.orientation).

PropertyConditionFlags

Bases: Enum

Optional flags that are used when checking the property.

RowOrColumnMajor

Bases: Enum

Contains values that specify the row/column major order of items in a container.

ScrollAmount

Bases: Enum

Contains values that specify the direction and distance to scroll.

StructureChangeType

Bases: Enum

Contains values that describe the change passed to a structure-changed event handler.

StyleType

Bases: Enum

Contains values that describe the visual style of an element (StylesPattern.style).

SupportedTextSelection

Bases: Enum

Contains values that specify the supported text selection attribute of a text control.

SynchronizedInputType

Bases: Enum

Contains values that specify the type of synchronized input to listen for.

TextEditChangeType

Bases: Enum

Contains values that describe the change passed to a text-edit text-changed event handler.

TextPatternRangeEndpoint

Bases: Enum

Contains values that specify the endpoints of a text range.

TextUnit

Bases: Enum

Contains values that specify units of text for the purposes of navigation.

ToggleState

Bases: Enum

Contains values that specify the toggle state of a Microsoft UI Automation element that implements the TogglePattern

TreeScope

Bases: Enum

Contains values that specify the scope of various operations in the Microsoft UI Automation tree.

TreeTraversalOptions

Bases: Enum

Contains values that specify the traversal options for the tree walker.

VisualEffects

Bases: IntFlag

Contains the visual effects applied to an element (Properties.visual_effects).

The C# enum is a [Flags] enum, so this is an :class:~enum.IntFlag whose values are the C# integer values: combined effects such as VisualEffects.Shadow | VisualEffects.Glow round-trip correctly.

WindowInteractionState

Bases: Enum

Contains values that specify the current state of a window for user interaction.

WindowVisualState

Bases: Enum

Contains values that specify the visual state of a window.

ZoomUnit

Bases: Enum

Contains values that specify the amount to zoom on a control.

to_cs_enum(value)

Convert a Python enum member to the C# value FlaUI expects.

Parameters:

Name Type Description Default
value Union[Enum, Any]

A Python enum member from this module, or a raw C# value (passed through).

required

Returns:

Type Description
Any

The C# enum value.

Source code in flaui/core/definitions.py
def to_cs_enum(value: Union[Enum, Any]) -> Any:
    """Convert a Python enum member to the C# value FlaUI expects.

    :param value: A Python enum member from this module, or a raw C# value (passed through).
    :return: The C# enum value.
    """
    if isinstance(value, VisualEffects):
        from System import Enum as CSEnum  # pyright: ignore

        from FlaUI.Core.Definitions import VisualEffects as CSVisualEffects  # pyright: ignore

        return CSEnum.ToObject(CSVisualEffects, int(value))
    if isinstance(value, Enum):
        return value.value
    return value

to_python_enum(value, enum_type=None)

Convert a C# FlaUI.Core.Definitions enum value to its Python enum.

Parameters:

Name Type Description Default
value Any

The value returned by C#. Python enum members and values of unmapped types pass through.

required
enum_type Optional[Type[Enum]]

The Python enum to convert to; inferred from the C# type of value when omitted.

None

Returns:

Type Description
Any

The matching Python enum member, or value unchanged when no mapping applies. A C# value outside the enum's defined members (for example default(HeadingLevel) = 0, which FlaUI's ValueOrDefault returns for an unsupported property) is also returned unchanged.

Source code in flaui/core/definitions.py
def to_python_enum(value: Any, enum_type: Optional[Type[Enum]] = None) -> Any:
    """Convert a C# ``FlaUI.Core.Definitions`` enum value to its Python enum.

    :param value: The value returned by C#. Python enum members and values of unmapped types pass through.
    :param enum_type: The Python enum to convert to; inferred from the C# type of ``value`` when omitted.
    :return: The matching Python enum member, or ``value`` unchanged when no mapping applies. A C# value
        outside the enum's defined members (for example ``default(HeadingLevel)`` = ``0``, which FlaUI's
        ``ValueOrDefault`` returns for an unsupported property) is also returned unchanged.
    """
    if value is None or isinstance(value, Enum):
        return value
    if enum_type is None:
        get_type = getattr(value, "GetType", None)
        if get_type is None:
            return value
        enum_type = _CS_ENUM_TYPES.get(str(get_type().FullName))
        if enum_type is None:
            return value
    try:
        if issubclass(enum_type, IntFlag):
            return enum_type(int(value))
        return enum_type(value)
    except ValueError:
        return value