diff --git a/source/controlTypes/__init__.py b/source/controlTypes/__init__.py index f8ab1e89125..09376b9eb0b 100644 --- a/source/controlTypes/__init__.py +++ b/source/controlTypes/__init__.py @@ -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__ = [ @@ -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 @@ -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 diff --git a/source/controlTypes/processing.py b/source/controlTypes/processing.py index 5860c800b08..e84557f8e61 100644 --- a/source/controlTypes/processing.py +++ b/source/controlTypes/processing.py @@ -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): @@ -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}). @@ -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. @@ -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, @@ -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. @@ -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. diff --git a/source/controlTypes/state.py b/source/controlTypes/state.py index 606ab7b566a..562d83cd5a7 100644 --- a/source/controlTypes/state.py +++ b/source/controlTypes/state.py @@ -9,7 +9,7 @@ from utils.mixins import DisplayStringEnumMixin -class STATE(IntEnum, DisplayStringEnumMixin): +class State(IntEnum, DisplayStringEnumMixin): @property def _displayStringLabels(self): return _stateLabels @@ -63,104 +63,104 @@ def defaultValue(self): HAS_ARIA_DETAILS = 0x40000000000 -STATES_SORTED = frozenset([STATE.SORTED, STATE.SORTED_ASCENDING, STATE.SORTED_DESCENDING]) +STATES_SORTED = frozenset([State.SORTED, State.SORTED_ASCENDING, State.SORTED_DESCENDING]) -_stateLabels: Dict[STATE, str] = { +_stateLabels: Dict[State, str] = { # Translators: This is presented when a control or document is unavailable. - STATE.UNAVAILABLE: _("unavailable"), + State.UNAVAILABLE: _("unavailable"), # Translators: This is presented when a control has focus. - STATE.FOCUSED: _("focused"), + State.FOCUSED: _("focused"), # Translators: This is presented when the control is selected. - STATE.SELECTED: _("selected"), + State.SELECTED: _("selected"), # Translators: This is presented when a document is busy. - STATE.BUSY: _("busy"), + State.BUSY: _("busy"), # Translators: This is presented when a button is pressed. - STATE.PRESSED: _("pressed"), + State.PRESSED: _("pressed"), # Translators: This is presented when a check box is checked. - STATE.CHECKED: _("checked"), + State.CHECKED: _("checked"), # Translators: This is presented when a three state check box is half checked. - STATE.HALFCHECKED: _("half checked"), + State.HALFCHECKED: _("half checked"), # Translators: This is presented when the control is a read-only control such as read-only edit box. - STATE.READONLY: _("read only"), + State.READONLY: _("read only"), # Translators: This is presented when a tree view or submenu item is expanded. - STATE.EXPANDED: _("expanded"), + State.EXPANDED: _("expanded"), # Translators: This is presented when a tree view or submenu is collapsed. - STATE.COLLAPSED: _("collapsed"), + State.COLLAPSED: _("collapsed"), # Translators: This is presented when a control or a document becomes invisible. - STATE.INVISIBLE: _("invisible"), + State.INVISIBLE: _("invisible"), # Translators: This is presented when a visited link is encountered. - STATE.VISITED: _("visited"), + State.VISITED: _("visited"), # Translators: This is presented when a link is encountered. - STATE.LINKED: _("linked"), + State.LINKED: _("linked"), # Translators: This is presented when the control menu item has a submenu. - STATE.HASPOPUP: _("subMenu"), + State.HASPOPUP: _("subMenu"), # Translators: This is presented when a protected control or a document is encountered. - STATE.PROTECTED: _("protected"), + State.PROTECTED: _("protected"), # Translators: This is presented when a required form field is encountered. - STATE.REQUIRED: _("required"), + State.REQUIRED: _("required"), # Translators: Reported when an object no longer exists in the user interface; # i.e. it is dead and is no longer usable. - STATE.DEFUNCT: _("defunct"), + State.DEFUNCT: _("defunct"), # Translators: This is presented when an invalid entry has been made. - STATE.INVALID_ENTRY: _("invalid entry"), - STATE.MODAL: _("modal"), + State.INVALID_ENTRY: _("invalid entry"), + State.MODAL: _("modal"), # Translators: This is presented when a field supports auto completion of entered text such as email # address field in Microsoft Outlook. - STATE.AUTOCOMPLETE: _("has auto complete"), + State.AUTOCOMPLETE: _("has auto complete"), # Translators: This is presented when an edit field allows typing multiple lines of text such as comment # fields on websites. - STATE.MULTILINE: _("multi line"), - STATE.ICONIFIED: _("iconified"), + State.MULTILINE: _("multi line"), + State.ICONIFIED: _("iconified"), # Translators: Presented when the current control is located off screen. - STATE.OFFSCREEN: _("off screen"), + State.OFFSCREEN: _("off screen"), # Translators: Presented when the control allows selection such as text fields. - STATE.SELECTABLE: _("selectable"), + State.SELECTABLE: _("selectable"), # Translators: Presented when a control can be moved to using system focus. - STATE.FOCUSABLE: _("focusable"), + State.FOCUSABLE: _("focusable"), # Translators: Presented when a control allows clicking via mouse (mostly presented on web controls). - STATE.CLICKABLE: _("clickable"), - STATE.EDITABLE: _("editable"), - STATE.CHECKABLE: _("checkable"), - STATE.DRAGGABLE: _("draggable"), - STATE.DRAGGING: _("dragging"), + State.CLICKABLE: _("clickable"), + State.EDITABLE: _("editable"), + State.CHECKABLE: _("checkable"), + State.DRAGGABLE: _("draggable"), + State.DRAGGING: _("dragging"), # Translators: Reported where an object which is being dragged can be dropped. # This is only reported for objects that support accessible drag and drop. - STATE.DROPTARGET: _("drop target"), - STATE.SORTED: _("sorted"), - STATE.SORTED_ASCENDING: _("sorted ascending"), - STATE.SORTED_DESCENDING: _("sorted descending"), + State.DROPTARGET: _("drop target"), + State.SORTED: _("sorted"), + State.SORTED_ASCENDING: _("sorted ascending"), + State.SORTED_DESCENDING: _("sorted descending"), # Translators: a state that denotes that an object (usually a graphic) has a long description. - STATE.HASLONGDESC: _("has long description"), + State.HASLONGDESC: _("has long description"), # Translators: a state that denotes that an object has additional details (such as a comment section). - STATE.HAS_ARIA_DETAILS: _("has details"), + State.HAS_ARIA_DETAILS: _("has details"), # Translators: a state that denotes that an object is pinned in its current location - STATE.PINNED: _("pinned"), + State.PINNED: _("pinned"), # Translators: a state that denotes the existance of a formula on a spreadsheet cell - STATE.HASFORMULA: _("has formula"), + State.HASFORMULA: _("has formula"), # Translators: a state that denotes the existance of a comment. - STATE.HASCOMMENT: _("has comment"), + State.HASCOMMENT: _("has comment"), # Translators: a state that denotes that the object is covered partially or fully by another object - STATE.OBSCURED: _("obscured"), + State.OBSCURED: _("obscured"), # Translators: a state that denotes that the object(text) is cropped as it couldn't be accommodated in the # allocated/available space - STATE.CROPPED: _("cropped"), + State.CROPPED: _("cropped"), # Translators: a state that denotes that the object(text) is overflowing into the adjacent space - STATE.OVERFLOWING: _("overflowing"), + State.OVERFLOWING: _("overflowing"), # Translators: a state that denotes that the object is unlocked (such as an unlocked cell in a protected # Excel spreadsheet). - STATE.UNLOCKED: _("unlocked"), + State.UNLOCKED: _("unlocked"), } -negativeStateLabels: Dict[STATE, str] = { +negativeStateLabels: Dict[State, str] = { # Translators: This is presented when a selectable object (e.g. a list item) is not selected. - STATE.SELECTED: _("not selected"), + State.SELECTED: _("not selected"), # Translators: This is presented when a button is not pressed. - STATE.PRESSED: _("not pressed"), + State.PRESSED: _("not pressed"), # Translators: This is presented when a checkbox is not checked. - STATE.CHECKED: _("not checked"), + State.CHECKED: _("not checked"), # Translators: This is presented when drag and drop is finished. # This is only reported for objects which support accessible drag and drop. - STATE.DROPTARGET: _("done dragging"), + State.DROPTARGET: _("done dragging"), }