From ea7775ccbafd9fafffe2db4777817e4d28c9bba6 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 20 May 2021 17:53:53 +1000 Subject: [PATCH] move isCurrent class to isCurrent.py (#12510) --- source/controlTypes/__init__.py | 48 +--------------------------- source/controlTypes/isCurrent.py | 55 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 47 deletions(-) create mode 100644 source/controlTypes/isCurrent.py diff --git a/source/controlTypes/__init__.py b/source/controlTypes/__init__.py index 58d4dcd19b7..9d7a74a7ee0 100644 --- a/source/controlTypes/__init__.py +++ b/source/controlTypes/__init__.py @@ -6,9 +6,9 @@ from enum import Enum, auto from typing import Any, Dict, List, Optional, Set -from logHandler import log from .role import ROLE, roleLabels, silentRolesOnFocus, silentValuesForRoles from .state import STATE, STATES_SORTED, stateLabels, negativeStateLabels +from .isCurrent import IsCurrent class OutputReason(Enum): @@ -36,52 +36,6 @@ class OutputReason(Enum): QUICKNAV = auto() -class IsCurrent(Enum): - """Values to use within NVDA to denote 'current' values. - These describe if an item is the current item within a particular kind of selection. - EG aria-current - """ - NO = "false" - YES = "true" - PAGE = "page" - STEP = "step" - LOCATION = "location" - DATE = "date" - TIME = "time" - - @property - def displayString(self): - """ - @return: The translated UI display string that should be used for this value of the IsCurrent enum - """ - try: - return _isCurrentLabels[self] - except KeyError: - log.debugWarning(f"No translation mapping for: {self}") - # there is a value for 'current' but NVDA hasn't learned about it yet, - # at least describe in the general sense that this item is 'current' - return _isCurrentLabels[IsCurrent.YES] - - -#: Text to use for 'current' values. These describe if an item is the current item -#: within a particular kind of selection. EG aria-current -_isCurrentLabels: Dict[Enum, str] = { - IsCurrent.NO: "", # There is nothing extra to say for items that are not current. - # Translators: Presented when an item is marked as current in a collection of items - IsCurrent.YES: _("current"), - # Translators: Presented when a page item is marked as current in a collection of page items - IsCurrent.PAGE: _("current page"), - # Translators: Presented when a step item is marked as current in a collection of step items - IsCurrent.STEP: _("current step"), - # Translators: Presented when a location item is marked as current in a collection of location items - IsCurrent.LOCATION: _("current location"), - # Translators: Presented when a date item is marked as current in a collection of date items - IsCurrent.DATE: _("current date"), - # Translators: Presented when a time item is marked as current in a collection of time items - IsCurrent.TIME: _("current time"), -} - - def processPositiveStates(role, states, reason: OutputReason, positiveStates=None): """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. diff --git a/source/controlTypes/isCurrent.py b/source/controlTypes/isCurrent.py new file mode 100644 index 00000000000..121ae0528dd --- /dev/null +++ b/source/controlTypes/isCurrent.py @@ -0,0 +1,55 @@ +# A part of NonVisual Desktop Access (NVDA) +# This file is covered by the GNU General Public License. +# See the file COPYING for more details. +# Copyright (C) 2007-2021 NV Access Limited, Babbage B.V. + +from enum import Enum +from typing import Dict + +from logHandler import log + + +class IsCurrent(Enum): + """Values to use within NVDA to denote 'current' values. + These describe if an item is the current item within a particular kind of selection. + EG aria-current + """ + NO = "false" + YES = "true" + PAGE = "page" + STEP = "step" + LOCATION = "location" + DATE = "date" + TIME = "time" + + @property + def displayString(self): + """ + @return: The translated UI display string that should be used for this value of the IsCurrent enum + """ + try: + return _isCurrentLabels[self] + except KeyError: + log.debugWarning(f"No translation mapping for: {self}") + # there is a value for 'current' but NVDA hasn't learned about it yet, + # at least describe in the general sense that this item is 'current' + return _isCurrentLabels[IsCurrent.YES] + + +#: Text to use for 'current' values. These describe if an item is the current item +#: within a particular kind of selection. EG aria-current +_isCurrentLabels: Dict[Enum, str] = { + IsCurrent.NO: "", # There is nothing extra to say for items that are not current. + # Translators: Presented when an item is marked as current in a collection of items + IsCurrent.YES: _("current"), + # Translators: Presented when a page item is marked as current in a collection of page items + IsCurrent.PAGE: _("current page"), + # Translators: Presented when a step item is marked as current in a collection of step items + IsCurrent.STEP: _("current step"), + # Translators: Presented when a location item is marked as current in a collection of location items + IsCurrent.LOCATION: _("current location"), + # Translators: Presented when a date item is marked as current in a collection of date items + IsCurrent.DATE: _("current date"), + # Translators: Presented when a time item is marked as current in a collection of time items + IsCurrent.TIME: _("current time"), +}