<commit_before># Orca
#
# Copyright 2005-2006 Sun Microsystems Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

"""Custom script for Evolution."""

__id__        = "$Id$"
__version__   = "$Revision$"
__date__      = "$Date$"
__copyright__ = "Copyright (c) 2005-2006 Sun Microsystems Inc."
__license__   = "LGPL"

import orca.debug as debug
import orca.default as default
import orca.atspi as atspi
import orca.input_event as input_event
import orca.rolenames as rolenames
import orca.orca as orca
import orca.braille as braille
import orca.speech as speech
import orca.settings as settings
import orca.util as util

from orca.orca_i18n import _ # for gettext support

########################################################################
#                                                                      #
# The Evolution script class.                                          #
#                                                                      #
########################################################################

class Script(default.Script):

    def __init__(self, app):
        """Creates a new script for the given application.

        Arguments:
        - app: the application to create a script for.
        """

        default.Script.__init__(self, app)

        # Set the debug level for all the methods in this script.
        #
        self.debugLevel = debug.LEVEL_FINEST

        # The default for Evolution is to read all table cells (such as in
        # the mail message header summary list).

        settings.readTableCellRow = True

        # This will be used to cache a handle to the message area in the
        # Mail compose window.

        self.message_panel = None

        # Dictionary of Setup Assistant panels already handled.
        #
        self.setupPanels = {}

        # Dictionary of Setup Assistant labels already handled.
        #
        self.setupLabels = {}

        # The last row and column we were on in the mail message header list.

        self.lastMessageColumn = -1
        self.lastMessageRow = -1

        # Evolution defines new custom roles. We need to make them known
        # to Orca for Speech and Braille output.

        rolenames.ROLE_CALENDAR_VIEW = "Calendar View"
        rolenames.rolenames[rolenames.ROLE_CALENDAR_VIEW] = \
            rolenames.Rolename(rolenames.ROLE_CALENDAR_VIEW,
                               _("calv"),
                               _("CalendarView"),
                               _("calendar view"))

        rolenames.ROLE_CALENDAR_EVENT = "Calendar Event"
        rolenames.rolenames[rolenames.ROLE_CALENDAR_EVENT] = \
            rolenames.Rolename(rolenames.ROLE_CALENDAR_EVENT,
                               _("cale"),
                               _("CalendarEvent"),
                               _("calendar event"))

    def setupInputEventHandlers(self):
        """Defines InputEventHandler fields for this script that can be
        called by the key and braille bindings. In this particular case,
        we just want to be able to define our own sayAll() method.
        """

        default.Script.setupInputEventHandlers(self)

        self.sayAllHandler = input_event.InputEventHandler(
            Script.sayAll,
            _("Speaks entire document."))

    def speakSetupAssistantLabel(self, label):
        """Perform a variety of tests on this Setup Assistant label to see
        if we want to speak it.

        Arguments:
        - label: the Setup Assistant Label.
        """

        if label.state.count(atspi.Accessibility.STATE_SHOWING):
            # We are only interested in a label if all the panels in the
            # component hierarchy have states of ENABLED, SHOWING and VISIBLE.
            # If this is not the case, thewn just return.
            #
            obj = label.parent
            while obj and obj.role != rolenames.ROLE_APPLICATION:
                if obj.role == rolenames.ROLE_PANEL:
                    state = obj.state
                    if not state.count(atspi.Accessibility.STATE_ENABLED) or \
                       not state.count(atspi.Accessibility.STATE_SHOWING) or \
                       not state.count(atspi.Accessibility.STATE_VISIBLE):
                        return
                obj = obj.parent

            # Each Setup Assistant screen has one label in the top left
            # corner that describes what this screen is for. It has a text
            # weight attribute of 800. We always speak those labels with 
            # " screen" appended.
            #
            if label.text:
                charAttributes = label.text.getAttributes(0)
                if charAttributes[0]:
                    charDict = self.textAttrsToDictionary(charAttributes[0])
                    weight = charDict.get('weight')
                    if weight and weight == '800':
                        text = util.getDisplayedText(label)
                        if text:
                            speech.speak(text + _(" screen"))

            # It's possible to get multiple "object:state-changed:showing"
            # events for the same label. If we've already handled this
            # label, then just ignore it.
            #
            text = util.getDisplayedText(label)
            if text and not self.setupLabels.has_key(label):
                # Most of the Setup Assistant screens have a useful piece
                # of text starting with the word "Please". We want to speak
                # these. For the first screen, the useful piece of text
                # starts with "Welcome". For the last screen, it starts
                # with "Done". Speak those too.
                #
                if text.startswith(_("Please")) or \
                    text.startswith(_("Welcome")) or \
                    text.startswith(_("Congratulations")):
                    speech.speak(text)
                    self.setupLabels[label] = True

    def handleSetupAssistantPanel(self, panel):
        """Find all the labels in this Setup Assistant panel and see if 
        we want to speak them.

        Arguments:
        - panel: the Setup Assistant panel.
        """

        allLabels = util.findByRole(panel, rolenames.ROLE_LABEL)
        for i in range(0, len(allLabels)):
            self.speakSetupAssistantLabel(allLabels[i])

    def readPageTab(self, tab):
        """Speak/Braille the given page tab. The speech verbosity is set
           to VERBOSITY_LEVEL_BRIEF for this operation and then restored
           to its previous value on completion.

        Arguments:
        - tab: the page tab to speak/braille.
        """<commit_msg>Fixup one of the comments.<commit_after># Orca
#
# Copyright 2005-2006 Sun Microsystems Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

"""Custom script for Evolution."""

__id__        = "$Id$"
__version__   = "$Revision$"
__date__      = "$Date$"
__copyright__ = "Copyright (c) 2005-2006 Sun Microsystems Inc."
__license__   = "LGPL"

import orca.debug as debug
import orca.default as default
import orca.atspi as atspi
import orca.input_event as input_event
import orca.rolenames as rolenames
import orca.orca as orca
import orca.braille as braille
import orca.speech as speech
import orca.settings as settings
import orca.util as util

from orca.orca_i18n import _ # for gettext support

########################################################################
#                                                                      #
# The Evolution script class.                                          #
#                                                                      #
########################################################################

class Script(default.Script):

    def __init__(self, app):
        """Creates a new script for the given application.

        Arguments:
        - app: the application to create a script for.
        """

        default.Script.__init__(self, app)

        # Set the debug level for all the methods in this script.
        #
        self.debugLevel = debug.LEVEL_FINEST

        # The default for Evolution is to read all table cells (such as in
        # the mail message header summary list).

        settings.readTableCellRow = True

        # This will be used to cache a handle to the message area in the
        # Mail compose window.

        self.message_panel = None

        # Dictionary of Setup Assistant panels already handled.
        #
        self.setupPanels = {}

        # Dictionary of Setup Assistant labels already handled.
        #
        self.setupLabels = {}

        # The last row and column we were on in the mail message header list.

        self.lastMessageColumn = -1
        self.lastMessageRow = -1

        # Evolution defines new custom roles. We need to make them known
        # to Orca for Speech and Braille output.

        rolenames.ROLE_CALENDAR_VIEW = "Calendar View"
        rolenames.rolenames[rolenames.ROLE_CALENDAR_VIEW] = \
            rolenames.Rolename(rolenames.ROLE_CALENDAR_VIEW,
                               _("calv"),
                               _("CalendarView"),
                               _("calendar view"))

        rolenames.ROLE_CALENDAR_EVENT = "Calendar Event"
        rolenames.rolenames[rolenames.ROLE_CALENDAR_EVENT] = \
            rolenames.Rolename(rolenames.ROLE_CALENDAR_EVENT,
                               _("cale"),
                               _("CalendarEvent"),
                               _("calendar event"))

    def setupInputEventHandlers(self):
        """Defines InputEventHandler fields for this script that can be
        called by the key and braille bindings. In this particular case,
        we just want to be able to define our own sayAll() method.
        """

        default.Script.setupInputEventHandlers(self)

        self.sayAllHandler = input_event.InputEventHandler(
            Script.sayAll,
            _("Speaks entire document."))

    def speakSetupAssistantLabel(self, label):
        """Perform a variety of tests on this Setup Assistant label to see
        if we want to speak it.

        Arguments:
        - label: the Setup Assistant Label.
        """

        if label.state.count(atspi.Accessibility.STATE_SHOWING):
            # We are only interested in a label if all the panels in the
            # component hierarchy have states of ENABLED, SHOWING and VISIBLE.
            # If this is not the case, thewn just return.
            #
            obj = label.parent
            while obj and obj.role != rolenames.ROLE_APPLICATION:
                if obj.role == rolenames.ROLE_PANEL:
                    state = obj.state
                    if not state.count(atspi.Accessibility.STATE_ENABLED) or \
                       not state.count(atspi.Accessibility.STATE_SHOWING) or \
                       not state.count(atspi.Accessibility.STATE_VISIBLE):
                        return
                obj = obj.parent

            # Each Setup Assistant screen has one label in the top left
            # corner that describes what this screen is for. It has a text
            # weight attribute of 800. We always speak those labels with 
            # " screen" appended.
            #
            if label.text:
                charAttributes = label.text.getAttributes(0)
                if charAttributes[0]:
                    charDict = self.textAttrsToDictionary(charAttributes[0])
                    weight = charDict.get('weight')
                    if weight and weight == '800':
                        text = util.getDisplayedText(label)
                        if text:
                            speech.speak(text + _(" screen"))

            # It's possible to get multiple "object:state-changed:showing"
            # events for the same label. If we've already handled this
            # label, then just ignore it.
            #
            text = util.getDisplayedText(label)
            if text and not self.setupLabels.has_key(label):
                # Most of the Setup Assistant screens have a useful piece
                # of text starting with the word "Please". We want to speak
                # these. For the first screen, the useful piece of text
                # starts with "Welcome". For the last screen, it starts
                # with "Congratulations". Speak those too.
                #
                if text.startswith(_("Please")) or \
                    text.startswith(_("Welcome")) or \
                    text.startswith(_("Congratulations")):
                    speech.speak(text)
                    self.setupLabels[label] = True

    def handleSetupAssistantPanel(self, panel):
        """Find all the labels in this Setup Assistant panel and see if 
        we want to speak them.

        Arguments:
        - panel: the Setup Assistant panel.
        """

        allLabels = util.findByRole(panel, rolenames.ROLE_LABEL)
        for i in range(0, len(allLabels)):
            self.speakSetupAssistantLabel(allLabels[i])

    def readPageTab(self, tab):
        """Speak/Braille the given page tab. The speech verbosity is set
           to VERBOSITY_LEVEL_BRIEF for this operation and then restored
           to its previous value on completion.

        Arguments:
        - tab: the page tab to speak/braille.
        """
{'fraction_non_alphanumeric': 0.0859915840912176, 'fraction_numerical': 0.006108320890457445, 'mean_word_length': 1.8633890400310922, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900757', 'n_tokens_mistral': 3779, 'n_tokens_neox': 3544, 'n_words': 1346}