Skip to content

Commit

Permalink
fix lint and improve function headers
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd committed Jun 3, 2021
1 parent d70e29c commit 17c6ecd
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 55 deletions.
79 changes: 45 additions & 34 deletions source/controlTypes/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,26 @@ class OutputReason(Enum):
QUICKNAV = auto()


def processPositiveStates(role, states, reason: OutputReason, positiveStates=None):
def processPositiveStates(
role: ROLE,
states: Set[STATE],
reason: OutputReason,
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.
@param role: The role of the object to process states for (e.g. C{ROLE.CHECKBOX}.
@type role: int
@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.
@type states: set
@param reason: The reason to process the states (e.g. C{OutputReason.FOCUS}.
@param positiveStates: Used for C{OutputReason.CHANGE}, specifies states changed from negative to positive;
@type positiveStates: set
@param reason: The reason to process the states (e.g. C{OutputReason.FOCUS}).
@param positiveStates: Used for C{OutputReason.CHANGE}, specifies states changed from negative to
positive.
@return: The processed positive states.
@rtype: set
"""
positiveStates = positiveStates.copy() if positiveStates is not None else states.copy()
# The user never cares about certain states.
if role==ROLE.EDITABLETEXT:
if role == ROLE.EDITABLETEXT:
positiveStates.discard(STATE.EDITABLE)
if role!=ROLE.LINK:
if role != ROLE.LINK:
positiveStates.discard(STATE.VISITED)
positiveStates.discard(STATE.SELECTABLE)
positiveStates.discard(STATE.FOCUSABLE)
Expand Down Expand Up @@ -102,24 +104,27 @@ def processPositiveStates(role, states, reason: OutputReason, positiveStates=Non
return positiveStates


def processNegativeStates(role, states, reason: OutputReason, negativeStates=None):
def processNegativeStates(
role: ROLE,
states: Set[STATE],
reason: OutputReason,
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 checked.
@param role: The role of the object to process states for (e.g. C{ROLE.CHECKBOX}.
@type role: int
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.
@type states: set
@param reason: The reason to process the states (e.g. C{OutputReason.FOCUS}.
@param negativeStates: Used for C{OutputReason.CHANGE}, specifies states changed from positive to negative;
@type negativeStates: set
@param reason: The reason to process the states (e.g. C{OutputReason.FOCUS)}.
@param negativeStates: Used for C{OutputReason.CHANGE}, specifies states changed from positive to
negative.
@return: The processed negative states.
@rtype: set
"""
if reason == OutputReason.CHANGE and not isinstance(negativeStates, set):
raise TypeError("negativeStates must be a set for this reason")
speakNegatives = set()
# Add the negative selected state if the control is selectable,
# but only if it is reported for the reason of focus, or this is a change to the focused object.
# but only if it is reported for the reason of focus, or this is a change to the focused object.
# The condition stops "not selected" from being spoken in some broken controls
# when the state change for the previous focus is issued before the focus change.
if (
Expand All @@ -128,11 +133,11 @@ def processNegativeStates(role, states, reason: OutputReason, negativeStates=Non
# Only include if the object is focusable (E.g. ARIA grid cells, but not standard html tables)
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.
# 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 role in (
ROLE.LISTITEM,
ROLE.TREEVIEWITEM,
ROLE.LISTITEM,
ROLE.TREEVIEWITEM,
ROLE.TABLEROW,
ROLE.TABLECELL,
ROLE.TABLECOLUMNHEADER,
Expand Down Expand Up @@ -180,26 +185,32 @@ def processAndLabelStates(
positiveStateLabelDict: Dict[int, str] = {},
negativeStateLabelDict: Dict[int, str] = {},
) -> List[str]:
"""Processes the states for an object and returns the appropriate state labels for both positive and negative states.
@param role: The role of the object to process states for (e.g. C{ROLE.CHECKBOX}.
"""Processes the states for an object and returns the appropriate state labels for both positive and
negative states.
@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}.
@param positiveStates: Used for C{OutputReason.CHANGE}, specifies states changed from negative to positive;
@param negativeStates: Used for C{OutputReason.CHANGE}, specifies states changed from positive to negative;
@param positiveStateLabelDict: Dictionary containing state identifiers as keys and associated positive labels as their values.
@param negativeStateLabelDict: Dictionary containing state identifiers as keys and associated negative labels as their values.
@param reason: The reason to process the states (e.g. C{OutputReason.FOCUS}).
@param positiveStates: Used for C{OutputReason.CHANGE}, specifies states changed from negative to
positive.
@param negativeStates: Used for C{OutputReason.CHANGE}, specifies states changed from positive to
negative.
@param positiveStateLabelDict: Dictionary containing state identifiers as keys and associated positive
labels as their values.
@param negativeStateLabelDict: Dictionary containing state identifiers as keys and associated negative
labels as their values.
@return: The labels of the relevant positive and negative states.
"""
mergedStateLabels=[]
mergedStateLabels = []
positiveStates = processPositiveStates(role, states, reason, positiveStates)
negativeStates = processNegativeStates(role, states, reason, negativeStates)
for state in sorted(positiveStates | negativeStates):
if state in positiveStates:
mergedStateLabels.append(positiveStateLabelDict.get(state, stateLabels[state]))
elif state in negativeStates:
# Translators: Indicates that a particular state of an object is negated.
# Separate strings have now been defined for commonly negated states (e.g. not selected and not checked),
# but this still might be used in some other cases.
# Separate strings have now been defined for commonly negated states (e.g. not selected and not
# checked), but this still might be used in some other cases.
# %s will be replaced with the full identifier of the negated state (e.g. selected).
mergedStateLabels.append(negativeStateLabelDict.get(state, negativeStateLabels.get(state, _("not %s") % stateLabels[state])))
negativeStateLabel = negativeStateLabels.get(state, _("not %s") % stateLabels[state])
mergedStateLabels.append(negativeStateLabelDict.get(state, negativeStateLabel))
return mergedStateLabels
46 changes: 30 additions & 16 deletions source/controlTypes/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,11 @@ class ROLE(IntEnum):
ROLE.LISTITEM: _("list item"),
# Translators: The word used to identify graphics such as webpage graphics.
ROLE.GRAPHIC: _("graphic"),
# Translators: Used to identify help balloon (a circular window with helpful text such as notification text).
# Translators: Used to identify help balloon (a circular window with helpful text such as notification
# text).
ROLE.HELPBALLOON: _("help balloon"),
# Translators: Used to identify a tooltip (a small window with additional text about selected item such as file information).
# Translators: Used to identify a tooltip (a small window with additional text about selected item such as
# file information).
ROLE.TOOLTIP: _("tool tip"),
# Translators: Identifies a link in webpage documents.
ROLE.LINK: _("link"),
Expand All @@ -216,7 +218,8 @@ class ROLE(IntEnum):
ROLE.PROGRESSBAR: _("progress bar"),
# Translators: Identifies a scroll bar.
ROLE.SCROLLBAR: _("scroll bar"),
# Translators: Identifies a status bar (text at the bottom bar of the screen such as cursor position in a document).
# Translators: Identifies a status bar (text at the bottom bar of the screen such as cursor position in a
# document).
ROLE.STATUSBAR: _("status bar"),
# Translators: Identifies a table such as ones used in various websites.
ROLE.TABLE: _("table"),
Expand Down Expand Up @@ -262,7 +265,8 @@ class ROLE(IntEnum):
# i.e. a long quotation in a separate paragraph distinguished by indentation, etc.
# See http://en.wikipedia.org/wiki/Block_quotation
ROLE.BLOCKQUOTE: _("block quote"),
# Translators: Identifies a table header (a short text at the start of a table which describes what the table is about).
# Translators: Identifies a table header (a short text at the start of a table which describes what the
# table is about).
ROLE.TABLEHEADER: _("table header"),
# Translators: Identifies a table body (the main body of the table).
ROLE.TABLEBODY: _("table body"),
Expand All @@ -276,15 +280,18 @@ class ROLE(IntEnum):
ROLE.APPLICATION: _("application"),
# Translators: Identifies a box element.
ROLE.BOX: _("box"),
# Translators: Identifies a grouping (a number of related items grouped together, such as related options in dialogs).
# Translators: Identifies a grouping (a number of related items grouped together, such as related options
# in dialogs).
ROLE.GROUPING: _("grouping"),
# Translators: Identifies a property page such as drive properties dialog.
ROLE.PROPERTYPAGE: _("property page"),
# Translators: Identifies a canvas element on webpages (a box with some background color with some text drawn on the box, like a canvas).
# Translators: Identifies a canvas element on webpages (a box with some background color with some text
# drawn on the box, like a canvas).
ROLE.CANVAS: _("canvas"),
# Translators: Identifies a caption (usually a short text identifying a picture or a graphic on websites).
ROLE.CAPTION: _("caption"),
# Translators: Identifies a check menu item (a menu item with a checkmark as part of the menu item's name).
# Translators: Identifies a check menu item (a menu item with a checkmark as part of the menu item's
# name).
ROLE.CHECKMENUITEM: _("check menu item"),
# Translators: Identifies a data edit field.
ROLE.DATEEDITOR: _("date edit"),
Expand Down Expand Up @@ -328,7 +335,8 @@ class ROLE(IntEnum):
ROLE.EDITBAR: _("edit bar"),
# Translators: Identifies a terminal window such as command prompt.
ROLE.TERMINAL: _("terminal"),
# Translators: Identifies a rich edit box (an edit box which allows entering formatting commands in addition to text; encountered on webpages and NvDA log viewer).
# Translators: Identifies a rich edit box (an edit box which allows entering formatting commands in
# addition to text; encountered on webpages and NvDA log viewer).
ROLE.RICHEDIT: _("rich edit"),
# Translators: Identifies a ruler object (commonly seen on some webpages and in some Office programs).
ROLE.RULER: _("ruler"),
Expand Down Expand Up @@ -367,7 +375,8 @@ class ROLE(IntEnum):
ROLE.DIAL: _("dial"),
# Translators: Identifies a drop list.
ROLE.DROPLIST: _("drop list"),
# Translators: Identifies a split button (a control which performs different actions when different parts are clicked).
# Translators: Identifies a split button (a control which performs different actions when different parts
# are clicked).
ROLE.SPLITBUTTON: _("split button"),
# Translators: Identifies a menu button (a button which opens a menu of items).
ROLE.MENUBUTTON: _("menu button"),
Expand All @@ -377,7 +386,8 @@ class ROLE(IntEnum):
ROLE.MATH: _("math"),
# Translators: Identifies a grip control.
ROLE.GRIP: _("grip"),
# Translators: Identifies a hot key field (a field where one can enter a hot key for something, such as assigning shortcut for icons on the desktop).
# Translators: Identifies a hot key field (a field where one can enter a hot key for something, such as
# assigning shortcut for icons on the desktop).
ROLE.HOTKEYFIELD: _("hot key field"),
# Translators: Identifies an indicator control.
ROLE.INDICATOR: _("indicator"),
Expand All @@ -391,9 +401,11 @@ class ROLE(IntEnum):
ROLE.TREEVIEWBUTTON: _("tree view button"),
# Translators: Identifies an IP address (an IP address field element).
ROLE.IPADDRESS: _("IP address"),
# Translators: Identifies a desktop icon (the icons on the desktop such as computer and various shortcuts for programs).
# Translators: Identifies a desktop icon (the icons on the desktop such as computer and various shortcuts
# for programs).
ROLE.DESKTOPICON: _("desktop icon"),
# Translators: Identifies an internal frame. This is usually a frame on a web page; i.e. a web page embedded within a web page.
# Translators: Identifies an internal frame. This is usually a frame on a web page; i.e. a web page
# embedded within a web page.
ROLE.INTERNALFRAME: _("frame"),
# Translators: Identifies desktop pane (the desktop window).
ROLE.DESKTOPPANE: _("desktop pane"),
Expand All @@ -408,7 +420,8 @@ class ROLE(IntEnum):
ROLE.MENU: _("menu"),
# Translators: Identifies a panel control for grouping related options.
ROLE.PANEL: _("panel"),
# Translators: Identifies a password field (a protected edit field for entering passwords such as when logging into web-based email sites).
# Translators: Identifies a password field (a protected edit field for entering passwords such as when
# logging into web-based email sites).
ROLE.PASSWORDEDIT: _("password edit"),
# Translators: Identifies a font chooser.
ROLE.FONTCHOOSER: _("font chooser"),
Expand Down Expand Up @@ -437,7 +450,8 @@ class ROLE(IntEnum):
ROLE.INDENT: _("indent"),
# Translators: Describes text formatting.
ROLE.ALIGNMENT: _("alignment"),
# Translators: Identifies an alert window or bar (usually on Internet Explorer 9 and above for alerts such as file downloads or pop-up blocker).
# Translators: Identifies an alert window or bar (usually on Internet Explorer 9 and above for alerts such
# as file downloads or pop-up blocker).
ROLE.ALERT: _("alert"),
# Translators: Identifies a data grid control (a grid which displays data).
ROLE.DATAGRID: _("data grid"),
Expand All @@ -450,9 +464,9 @@ class ROLE(IntEnum):
ROLE.AUDIO: _("audio"),
# Translators: Identifies a chart element.
ROLE.CHARTELEMENT: _("chart element"),
# Translators: Identifies deleted content.
# Translators: Identifies deleted content.
ROLE.DELETED_CONTENT: _("deleted"),
# Translators: Identifies inserted content.
# Translators: Identifies inserted content.
ROLE.INSERTED_CONTENT: _("inserted"),
# Translators: Identifies a landmark.
ROLE.LANDMARK: _("landmark"),
Expand Down
14 changes: 9 additions & 5 deletions source/controlTypes/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class STATE(IntEnum):
SORTED_DESCENDING = 0x200000000
HASLONGDESC = 0x400000000
PINNED = 0x800000000
HASFORMULA = 0x1000000000 #Mostly for spreadsheets
HASFORMULA = 0x1000000000 # Mostly for spreadsheets
HASCOMMENT = 0X2000000000
OBSCURED = 0x4000000000
CROPPED = 0x8000000000
Expand Down Expand Up @@ -95,9 +95,11 @@ class STATE(IntEnum):
# Translators: This is presented when an invalid entry has been made.
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.
# 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"),
# Translators: This is presented when an edit field allows typing multiple lines of text such as comment fields on websites.
# 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"),
# Translators: Presented when the current control is located off screen.
Expand Down Expand Up @@ -130,11 +132,13 @@ class STATE(IntEnum):
STATE.HASCOMMENT: _("has comment"),
# Translators: a state that denotes that the object is covered partially or fully by another object
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
# 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"),
# Translators: a state that denotes that the object(text) is overflowing into the adjacent space
STATE.OVERFLOWING: _("overflowing"),
# Translators: a state that denotes that the object is unlocked (such as an unlocked cell in a protected Excel spreadsheet).
# Translators: a state that denotes that the object is unlocked (such as an unlocked cell in a protected
# Excel spreadsheet).
STATE.UNLOCKED: _("unlocked"),
}

Expand Down

0 comments on commit 17c6ecd

Please sign in to comment.