Skip to content

Commit

Permalink
replace STATE with State
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd committed Jun 9, 2021
1 parent 1601b9b commit 8c2fdc9
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 149 deletions.
92 changes: 46 additions & 46 deletions source/controlTypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .isCurrent import IsCurrent
from .processing import OutputReason, processAndLabelStates, processNegativeStates, processPositiveStates
from .role import Role, silentRolesOnFocus, silentValuesForRoles, _roleLabels
from .state import STATE, STATES_SORTED, negativeStateLabels, _stateLabels
from .state import State, STATES_SORTED, negativeStateLabels, _stateLabels


__all__ = [
Expand All @@ -21,14 +21,14 @@
"Role",
"silentRolesOnFocus",
"silentValuesForRoles",
"STATE",
"State",
"STATES_SORTED",
"negativeStateLabels",
]


# Added to maintain backwards compatibility, marked for deprecation to be removed in 2022.1
# usages to be replaced by Role.*.displayString and STATE.*.displayString
# usages to be replaced by Role.*.displayString and State.*.displayString
if version_year < 2022:
roleLabels = _roleLabels
stateLabels = _stateLabels
Expand Down Expand Up @@ -191,46 +191,46 @@

# Added to maintain backwards compatibility, marked for deprecation to be removed in 2022.1
if version_year < 2022:
STATE_UNAVAILABLE = STATE.UNAVAILABLE
STATE_FOCUSED = STATE.FOCUSED
STATE_SELECTED = STATE.SELECTED
STATE_BUSY = STATE.BUSY
STATE_PRESSED = STATE.PRESSED
STATE_CHECKED = STATE.CHECKED
STATE_HALFCHECKED = STATE.HALFCHECKED
STATE_READONLY = STATE.READONLY
STATE_EXPANDED = STATE.EXPANDED
STATE_COLLAPSED = STATE.COLLAPSED
STATE_INVISIBLE = STATE.INVISIBLE
STATE_VISITED = STATE.VISITED
STATE_LINKED = STATE.LINKED
STATE_HASPOPUP = STATE.HASPOPUP
STATE_PROTECTED = STATE.PROTECTED
STATE_REQUIRED = STATE.REQUIRED
STATE_DEFUNCT = STATE.DEFUNCT
STATE_INVALID_ENTRY = STATE.INVALID_ENTRY
STATE_MODAL = STATE.MODAL
STATE_AUTOCOMPLETE = STATE.AUTOCOMPLETE
STATE_MULTILINE = STATE.MULTILINE
STATE_ICONIFIED = STATE.ICONIFIED
STATE_OFFSCREEN = STATE.OFFSCREEN
STATE_SELECTABLE = STATE.SELECTABLE
STATE_FOCUSABLE = STATE.FOCUSABLE
STATE_CLICKABLE = STATE.CLICKABLE
STATE_EDITABLE = STATE.EDITABLE
STATE_CHECKABLE = STATE.CHECKABLE
STATE_DRAGGABLE = STATE.DRAGGABLE
STATE_DRAGGING = STATE.DRAGGING
STATE_DROPTARGET = STATE.DROPTARGET
STATE_SORTED = STATE.SORTED
STATE_SORTED_ASCENDING = STATE.SORTED_ASCENDING
STATE_SORTED_DESCENDING = STATE.SORTED_DESCENDING
STATE_HASLONGDESC = STATE.HASLONGDESC
STATE_PINNED = STATE.PINNED
STATE_HASFORMULA = STATE.HASFORMULA
STATE_HASCOMMENT = STATE.HASCOMMENT
STATE_OBSCURED = STATE.OBSCURED
STATE_CROPPED = STATE.CROPPED
STATE_OVERFLOWING = STATE.OVERFLOWING
STATE_UNLOCKED = STATE.UNLOCKED
STATE_HAS_ARIA_DETAILS = STATE.HAS_ARIA_DETAILS
STATE_UNAVAILABLE = State.UNAVAILABLE
STATE_FOCUSED = State.FOCUSED
STATE_SELECTED = State.SELECTED
STATE_BUSY = State.BUSY
STATE_PRESSED = State.PRESSED
STATE_CHECKED = State.CHECKED
STATE_HALFCHECKED = State.HALFCHECKED
STATE_READONLY = State.READONLY
STATE_EXPANDED = State.EXPANDED
STATE_COLLAPSED = State.COLLAPSED
STATE_INVISIBLE = State.INVISIBLE
STATE_VISITED = State.VISITED
STATE_LINKED = State.LINKED
STATE_HASPOPUP = State.HASPOPUP
STATE_PROTECTED = State.PROTECTED
STATE_REQUIRED = State.REQUIRED
STATE_DEFUNCT = State.DEFUNCT
STATE_INVALID_ENTRY = State.INVALID_ENTRY
STATE_MODAL = State.MODAL
STATE_AUTOCOMPLETE = State.AUTOCOMPLETE
STATE_MULTILINE = State.MULTILINE
STATE_ICONIFIED = State.ICONIFIED
STATE_OFFSCREEN = State.OFFSCREEN
STATE_SELECTABLE = State.SELECTABLE
STATE_FOCUSABLE = State.FOCUSABLE
STATE_CLICKABLE = State.CLICKABLE
STATE_EDITABLE = State.EDITABLE
STATE_CHECKABLE = State.CHECKABLE
STATE_DRAGGABLE = State.DRAGGABLE
STATE_DRAGGING = State.DRAGGING
STATE_DROPTARGET = State.DROPTARGET
STATE_SORTED = State.SORTED
STATE_SORTED_ASCENDING = State.SORTED_ASCENDING
STATE_SORTED_DESCENDING = State.SORTED_DESCENDING
STATE_HASLONGDESC = State.HASLONGDESC
STATE_PINNED = State.PINNED
STATE_HASFORMULA = State.HASFORMULA
STATE_HASCOMMENT = State.HASCOMMENT
STATE_OBSCURED = State.OBSCURED
STATE_CROPPED = State.CROPPED
STATE_OVERFLOWING = State.OVERFLOWING
STATE_UNLOCKED = State.UNLOCKED
STATE_HAS_ARIA_DETAILS = State.HAS_ARIA_DETAILS
104 changes: 52 additions & 52 deletions source/controlTypes/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Dict, List, Optional, Set

from .role import Role, clickableRoles
from .state import STATE, STATES_SORTED, negativeStateLabels, stateLabels
from .state import State, STATES_SORTED, negativeStateLabels, stateLabels


class OutputReason(Enum):
Expand Down Expand Up @@ -37,12 +37,12 @@ class OutputReason(Enum):

def processPositiveStates(
role: Role,
states: Set[STATE],
states: Set[State],
reason: OutputReason,
positiveStates: Optional[Set[STATE]] = None
) -> Set[STATE]:
positiveStates: Optional[Set[State]] = None
) -> Set[State]:
"""Processes the states for an object and returns the positive states to output for a specified reason.
For example, if C{STATE.CHECKED} is in the returned states, it means that the processed object is checked.
For example, if C{State.CHECKED} is in the returned states, it means that the processed object is checked.
@param role: The role of the object to process states for (e.g. C{Role.CHECKBOX}).
@param states: The raw states for an object to process.
@param reason: The reason to process the states (e.g. C{OutputReason.FOCUS}).
Expand All @@ -53,65 +53,65 @@ def processPositiveStates(
positiveStates = positiveStates.copy() if positiveStates is not None else states.copy()
# The user never cares about certain states.
if role == Role.EDITABLETEXT:
positiveStates.discard(STATE.EDITABLE)
positiveStates.discard(State.EDITABLE)
if role != Role.LINK:
positiveStates.discard(STATE.VISITED)
positiveStates.discard(STATE.SELECTABLE)
positiveStates.discard(STATE.FOCUSABLE)
positiveStates.discard(STATE.CHECKABLE)
if STATE.DRAGGING in positiveStates:
positiveStates.discard(State.VISITED)
positiveStates.discard(State.SELECTABLE)
positiveStates.discard(State.FOCUSABLE)
positiveStates.discard(State.CHECKABLE)
if State.DRAGGING in positiveStates:
# It's obvious that the control is draggable if it's being dragged.
positiveStates.discard(STATE.DRAGGABLE)
positiveStates.discard(State.DRAGGABLE)
if role == Role.COMBOBOX:
# Combo boxes inherently have a popup, so don't report it.
positiveStates.discard(STATE.HASPOPUP)
positiveStates.discard(State.HASPOPUP)
import config
if not config.conf['documentFormatting']['reportClickable'] or role in clickableRoles:
# This control is clearly clickable according to its role,
# or reporting clickable just isn't useful,
# or the user has explicitly requested no reporting clickable
positiveStates.discard(STATE.CLICKABLE)
positiveStates.discard(State.CLICKABLE)
if reason == OutputReason.QUERY:
return positiveStates
positiveStates.discard(STATE.DEFUNCT)
positiveStates.discard(STATE.MODAL)
positiveStates.discard(STATE.FOCUSED)
positiveStates.discard(STATE.OFFSCREEN)
positiveStates.discard(STATE.INVISIBLE)
positiveStates.discard(State.DEFUNCT)
positiveStates.discard(State.MODAL)
positiveStates.discard(State.FOCUSED)
positiveStates.discard(State.OFFSCREEN)
positiveStates.discard(State.INVISIBLE)
if reason != OutputReason.CHANGE:
positiveStates.discard(STATE.LINKED)
positiveStates.discard(State.LINKED)
if role in (
Role.LISTITEM,
Role.TREEVIEWITEM,
Role.MENUITEM,
Role.TABLEROW,
Role.CHECKBOX,
) and STATE.SELECTABLE in states:
positiveStates.discard(STATE.SELECTED)
) and State.SELECTABLE in states:
positiveStates.discard(State.SELECTED)
if role not in (Role.EDITABLETEXT, Role.CHECKBOX):
positiveStates.discard(STATE.READONLY)
positiveStates.discard(State.READONLY)
if role == Role.CHECKBOX:
positiveStates.discard(STATE.PRESSED)
if role == Role.MENUITEM and STATE.HASPOPUP in positiveStates:
positiveStates.discard(State.PRESSED)
if role == Role.MENUITEM and State.HASPOPUP in positiveStates:
# The user doesn't usually care if a submenu is expanded or collapsed.
positiveStates.discard(STATE.COLLAPSED)
positiveStates.discard(STATE.EXPANDED)
if STATE.FOCUSABLE not in states:
positiveStates.discard(STATE.EDITABLE)
positiveStates.discard(State.COLLAPSED)
positiveStates.discard(State.EXPANDED)
if State.FOCUSABLE not in states:
positiveStates.discard(State.EDITABLE)
if not config.conf["annotations"]["reportDetails"]:
# reading aria-details is an experimental feature still and should not always be reported.
positiveStates.discard(STATE.HAS_ARIA_DETAILS)
positiveStates.discard(State.HAS_ARIA_DETAILS)
return positiveStates


def processNegativeStates(
role: Role,
states: Set[STATE],
states: Set[State],
reason: OutputReason,
negativeStates: Optional[Set[STATE]] = None
) -> Set[STATE]:
negativeStates: Optional[Set[State]] = None
) -> Set[State]:
"""Processes the states for an object and returns the negative states to output for a specified reason.
For example, if C{STATE.CHECKED} is in the returned states, it means that the processed object is not
For example, if C{State.CHECKED} is in the returned states, it means that the processed object is not
checked.
@param role: The role of the object to process states for (e.g. C{Role.CHECKBOX}).
@param states: The raw states for an object to process.
Expand All @@ -129,12 +129,12 @@ def processNegativeStates(
# when the state change for the previous focus is issued before the focus change.
if (
# Only include if the object is actually selectable
STATE.SELECTABLE in states
State.SELECTABLE in states
# Only include if the object is focusable (E.g. ARIA grid cells, but not standard html tables)
and STATE.FOCUSABLE in states
and State.FOCUSABLE in states
# Only include if reporting the focus or when states are changing on the focus.
# This is to avoid exposing it for things like caret movement in browse mode.
and (reason == OutputReason.FOCUS or (reason == OutputReason.CHANGE and STATE.FOCUSED in states))
and (reason == OutputReason.FOCUS or (reason == OutputReason.CHANGE and State.FOCUSED in states))
and role in (
Role.LISTITEM,
Role.TREEVIEWITEM,
Expand All @@ -145,30 +145,30 @@ def processNegativeStates(
Role.CHECKBOX,
)
):
speakNegatives.add(STATE.SELECTED)
speakNegatives.add(State.SELECTED)
# Restrict "not checked" in a similar way to "not selected".
if(
(role in (Role.CHECKBOX, Role.RADIOBUTTON, Role.CHECKMENUITEM) or STATE.CHECKABLE in states)
and (STATE.HALFCHECKED not in states)
and (reason != OutputReason.CHANGE or STATE.FOCUSED in states)
(role in (Role.CHECKBOX, Role.RADIOBUTTON, Role.CHECKMENUITEM) or State.CHECKABLE in states)
and (State.HALFCHECKED not in states)
and (reason != OutputReason.CHANGE or State.FOCUSED in states)
):
speakNegatives.add(STATE.CHECKED)
speakNegatives.add(State.CHECKED)
if role == Role.TOGGLEBUTTON:
speakNegatives.add(STATE.PRESSED)
speakNegatives.add(State.PRESSED)
if reason == OutputReason.CHANGE:
# We want to speak this state only if it is changing to negative.
speakNegatives.add(STATE.DROPTARGET)
speakNegatives.add(State.DROPTARGET)
# We were given states which have changed to negative.
# Return only those supplied negative states which should be spoken;
# i.e. the states in both sets.
speakNegatives &= negativeStates
# #6946: if HALFCHECKED is present but CHECKED isn't, we should make sure we add CHECKED to speakNegatives.
if (STATE.HALFCHECKED in negativeStates and STATE.CHECKED not in states):
speakNegatives.add(STATE.CHECKED)
if (State.HALFCHECKED in negativeStates and State.CHECKED not in states):
speakNegatives.add(State.CHECKED)
if STATES_SORTED & negativeStates and not STATES_SORTED & states:
# If the object has just stopped being sorted, just report not sorted.
# The user doesn't care how it was sorted before.
speakNegatives.add(STATE.SORTED)
speakNegatives.add(State.SORTED)
return speakNegatives
else:
# This is not a state change; only positive states were supplied.
Expand All @@ -178,12 +178,12 @@ def processNegativeStates(

def processAndLabelStates(
role: Role,
states: Set[STATE],
states: Set[State],
reason: OutputReason,
positiveStates: Optional[Set[STATE]] = None,
negativeStates: Optional[Set[STATE]] = None,
positiveStateLabelDict: Dict[STATE, str] = {},
negativeStateLabelDict: Dict[STATE, str] = {},
positiveStates: Optional[Set[State]] = None,
negativeStates: Optional[Set[State]] = None,
positiveStateLabelDict: Dict[State, str] = {},
negativeStateLabelDict: Dict[State, str] = {},
) -> List[str]:
"""Processes the states for an object and returns the appropriate state labels for both positive and
negative states.
Expand Down
Loading

0 comments on commit 8c2fdc9

Please sign in to comment.