Skip to content

Commit

Permalink
move isCurrent class to isCurrent.py (#12510)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbudd committed Jun 16, 2021
1 parent b13da5b commit ea7775c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 47 deletions.
48 changes: 1 addition & 47 deletions source/controlTypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down
55 changes: 55 additions & 0 deletions source/controlTypes/isCurrent.py
Original file line number Diff line number Diff line change
@@ -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"),
}

0 comments on commit ea7775c

Please sign in to comment.