|
4 | 4 | #See the file COPYING for more details. |
5 | 5 | #Copyright (C) 2007-2016 NV Access Limited, Babbage B.V. |
6 | 6 | from typing import Dict, Union, Set, Any, Optional, List |
| 7 | +from enum import Enum, auto |
7 | 8 |
|
8 | 9 | ROLE_UNKNOWN=0 |
9 | 10 | ROLE_WINDOW=1 |
|
622 | 623 | ROLE_APPLICATION, |
623 | 624 | } |
624 | 625 |
|
625 | | -#{ Output reasons |
626 | | -# These constants are used to specify the reason that a given piece of output was generated. |
627 | | -#: An object to be reported due to a focus change or similar. |
628 | | -REASON_FOCUS="focus" |
629 | | -#: An ancestor of the focus object to be reported due to a focus change or similar. |
630 | | -REASON_FOCUSENTERED="focusEntered" |
631 | | -#: An item under the mouse. |
632 | | -REASON_MOUSE="mouse" |
633 | | -#: A response to a user query. |
634 | | -REASON_QUERY="query" |
635 | | -#: Reporting a change to an object. |
636 | | -REASON_CHANGE="change" |
637 | | -#: A generic, screen reader specific message. |
638 | | -REASON_MESSAGE="message" |
639 | | -#: Text reported as part of a say all. |
640 | | -REASON_SAYALL="sayAll" |
641 | | -#: Content reported due to caret movement or similar. |
642 | | -REASON_CARET="caret" |
643 | | -#: No output, but any state should be cached as if output had occurred. |
644 | | -REASON_ONLYCACHE="onlyCache" |
645 | | -#} |
| 626 | + |
| 627 | +class OutputReason(Enum): |
| 628 | + """Specify the reason that a given piece of output was generated. |
| 629 | + """ |
| 630 | + #: An object to be reported due to a focus change or similar. |
| 631 | + FOCUS = auto() |
| 632 | + #: An ancestor of the focus object to be reported due to a focus change or similar. |
| 633 | + FOCUSENTERED = auto() |
| 634 | + #: An item under the mouse. |
| 635 | + MOUSE = auto() |
| 636 | + #: A response to a user query. |
| 637 | + QUERY = auto() |
| 638 | + #: Reporting a change to an object. |
| 639 | + CHANGE = auto() |
| 640 | + #: A generic, screen reader specific message. |
| 641 | + MESSAGE = auto() |
| 642 | + #: Text reported as part of a say all. |
| 643 | + SAYALL = auto() |
| 644 | + #: Content reported due to caret movement or similar. |
| 645 | + CARET = auto() |
| 646 | + #: No output, but any state should be cached as if output had occurred. |
| 647 | + ONLYCACHE = auto() |
| 648 | + |
| 649 | + QUICKNAV = auto() |
| 650 | + |
| 651 | +# The following constants are kept for backwards compatibility. |
| 652 | +# In future, OutputReason should be used directly |
| 653 | + |
| 654 | + |
| 655 | +REASON_FOCUS = OutputReason.FOCUS |
| 656 | +REASON_FOCUSENTERED = OutputReason.FOCUSENTERED |
| 657 | +REASON_MOUSE = OutputReason.MOUSE |
| 658 | +REASON_QUERY = OutputReason.QUERY |
| 659 | +REASON_CHANGE = OutputReason.CHANGE |
| 660 | +REASON_MESSAGE = OutputReason.MESSAGE |
| 661 | +REASON_SAYALL = OutputReason.SAYALL |
| 662 | +REASON_CARET = OutputReason.CARET |
| 663 | +REASON_ONLYCACHE = OutputReason.ONLYCACHE |
646 | 664 |
|
647 | 665 | #: Text to use for 'current' values. These describe if an item is the current item |
648 | 666 | #: within a particular kind of selection. |
|
661 | 679 | "time":_("current time"), |
662 | 680 | } |
663 | 681 |
|
664 | | -def processPositiveStates(role, states, reason, positiveStates=None): |
| 682 | +def processPositiveStates(role, states, reason: OutputReason, positiveStates=None): |
665 | 683 | """Processes the states for an object and returns the positive states to output for a specified reason. |
666 | 684 | For example, if C{STATE_CHECKED} is in the returned states, it means that the processed object is checked. |
667 | 685 | @param role: The role of the object to process states for (e.g. C{ROLE_CHECKBOX}. |
668 | 686 | @type role: int |
669 | 687 | @param states: The raw states for an object to process. |
670 | 688 | @type states: set |
671 | 689 | @param reason: The reason to process the states (e.g. C{REASON_FOCUS}. |
672 | | - @type reason: str |
673 | 690 | @param positiveStates: Used for C{REASON_CHANGE}, specifies states changed from negative to positive; |
674 | 691 | @type positiveStates: set |
675 | 692 | @return: The processed positive states. |
@@ -719,15 +736,14 @@ def processPositiveStates(role, states, reason, positiveStates=None): |
719 | 736 | positiveStates.discard(STATE_EDITABLE) |
720 | 737 | return positiveStates |
721 | 738 |
|
722 | | -def processNegativeStates(role, states, reason, negativeStates=None): |
| 739 | +def processNegativeStates(role, states, reason: OutputReason, negativeStates=None): |
723 | 740 | """Processes the states for an object and returns the negative states to output for a specified reason. |
724 | 741 | For example, if C{STATE_CHECKED} is in the returned states, it means that the processed object is not checked. |
725 | 742 | @param role: The role of the object to process states for (e.g. C{ROLE_CHECKBOX}. |
726 | 743 | @type role: int |
727 | 744 | @param states: The raw states for an object to process. |
728 | 745 | @type states: set |
729 | 746 | @param reason: The reason to process the states (e.g. C{REASON_FOCUS}. |
730 | | - @type reason: str |
731 | 747 | @param negativeStates: Used for C{REASON_CHANGE}, specifies states changed from positive to negative; |
732 | 748 | @type negativeStates: set |
733 | 749 | @return: The processed negative states. |
@@ -787,7 +803,7 @@ def processNegativeStates(role, states, reason, negativeStates=None): |
787 | 803 | def processAndLabelStates( |
788 | 804 | role: int, |
789 | 805 | states: Set[Any], |
790 | | - reason: str, |
| 806 | + reason: OutputReason, |
791 | 807 | positiveStates: Optional[Set[Any]] = None, |
792 | 808 | negativeStates: Optional[Set[Any]] = None, |
793 | 809 | positiveStateLabelDict: Dict[int, str] = {}, |
|
0 commit comments