[orca] Added Banshee script (bug #597170).



commit 226ee58b69d8fe94b3a47cf6379508dc9b03c35c
Author: Eitan Isaacson <eitan monotonous org>
Date:   Mon Nov 9 10:39:05 2009 -0800

    Added Banshee script (bug #597170).

 configure.in                                      |    1 +
 src/orca/scripts/apps/Banshee/Makefile.am         |    9 +++
 src/orca/scripts/apps/Banshee/__init__.py         |    1 +
 src/orca/scripts/apps/Banshee/formatting.py       |   30 ++++++++
 src/orca/scripts/apps/Banshee/script.py           |   75 +++++++++++++++++++++
 src/orca/scripts/apps/Banshee/speech_generator.py |   19 +++++
 src/orca/scripts/apps/Makefile.am                 |    3 +-
 src/orca/settings.py                              |    3 +
 8 files changed, 140 insertions(+), 1 deletions(-)
---
diff --git a/configure.in b/configure.in
index 4753f17..e1a3b13 100644
--- a/configure.in
+++ b/configure.in
@@ -85,6 +85,7 @@ src/orca/scripts/apps/rhythmbox/Makefile
 src/orca/scripts/apps/Thunderbird/Makefile
 src/orca/scripts/apps/gedit/Makefile
 src/orca/scripts/apps/gnome-window-properties/Makefile
+src/orca/scripts/apps/Banshee/Makefile
 src/orca/scripts/toolkits/Makefile
 src/orca/scripts/toolkits/Gecko/Makefile
 src/orca/scripts/toolkits/J2SE-access-bridge/Makefile
diff --git a/src/orca/scripts/apps/Banshee/Makefile.am b/src/orca/scripts/apps/Banshee/Makefile.am
new file mode 100644
index 0000000..cc5291f
--- /dev/null
+++ b/src/orca/scripts/apps/Banshee/Makefile.am
@@ -0,0 +1,9 @@
+orca_pathdir=$(pyexecdir)
+
+orca_python_PYTHON = \
+	__init__.py \
+	script.py \
+	speech_generator.py \
+	formatting.py
+
+orca_pythondir=$(pyexecdir)/orca/scripts/apps/Banshee
diff --git a/src/orca/scripts/apps/Banshee/__init__.py b/src/orca/scripts/apps/Banshee/__init__.py
new file mode 100644
index 0000000..1d50af9
--- /dev/null
+++ b/src/orca/scripts/apps/Banshee/__init__.py
@@ -0,0 +1 @@
+from script import Script
diff --git a/src/orca/scripts/apps/Banshee/formatting.py b/src/orca/scripts/apps/Banshee/formatting.py
new file mode 100644
index 0000000..fee05b3
--- /dev/null
+++ b/src/orca/scripts/apps/Banshee/formatting.py
@@ -0,0 +1,30 @@
+import copy
+
+import pyatspi
+
+import orca.formatting
+
+formatting = {
+    'speech': {
+        # When the rating widget changes values, it emits an accessible
+        # name changed event. Because it is of ROLE_UNKNOWN, the default
+        # speech_generator's _getDefaultSpeech handles it. And because
+        # the widget is already focused, it doesn't speak anything. We
+        # want to speak the widget's name as it contains the number of
+        # stars being displayed.
+        #
+        'REAL_ROLE_TABLE_CELL': {
+            'unfocused': '(tableCell2ChildLabel + tableCell2ChildToggle)\
+                          or (columnHeaderIfToggleAndNoText\
+                              + cellCheckedState\
+                              + (realActiveDescendantDisplayedText or imageDescription)\
+                              + (expandableState and (expandableState + numberOfChildren))\
+                              + required)'
+            },
+    }
+}
+
+class Formatting(orca.formatting.Formatting):
+    def __init__(self, script):
+        orca.formatting.Formatting.__init__(self, script)
+        self.update(copy.deepcopy(formatting))
diff --git a/src/orca/scripts/apps/Banshee/script.py b/src/orca/scripts/apps/Banshee/script.py
new file mode 100644
index 0000000..b05f874
--- /dev/null
+++ b/src/orca/scripts/apps/Banshee/script.py
@@ -0,0 +1,75 @@
+import orca.default as default
+import orca.orca_state as orca_state
+import pyatspi
+
+from speech_generator import SpeechGenerator
+from formatting import Formatting
+
+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)
+        self._last_seek_value = 0
+
+
+    def getSpeechGenerator(self):
+        """Returns the speech generator for this script.
+        """
+        return SpeechGenerator(self)
+
+    def getFormatting(self):
+        """Returns the formatting strings for this script."""
+        return Formatting(self)
+
+    def _formatDuration(self, s):
+        seconds = '%02d' % (s%60)
+        minutes = '%02d' % (s/60)
+        hours = '%02d' % (s/3600)
+        
+        duration = [minutes, seconds]
+        
+        if hours != '00':
+            duration.insert(0, hours)
+
+        return ':'.join(duration)
+
+    def _isSeekSlider(self, obj):
+        return bool(pyatspi.findAncestor(
+                obj, lambda x: x.getRole() == pyatspi.ROLE_TOOL_BAR))
+
+    def visualAppearanceChanged(self, event, obj):
+        if event.type == 'object:property-change:accessible-value' and \
+                self._isSeekSlider(obj):
+            try:
+                value = obj.queryValue()
+            except NotImplementedError:
+                return default.Script.getTextForValue(self, obj)
+
+            current_value = int(value.currentValue)/1000
+
+            if current_value in \
+                    range(self._last_seek_value, self._last_seek_value + 4):
+                if self.isSameObject(obj, orca_state.locusOfFocus):
+                    self.updateBraille(obj)
+                return
+
+            self._last_seek_value = current_value
+
+        default.Script.visualAppearanceChanged(self, event, obj)
+            
+
+    def getTextForValue(self, obj):
+        if not self._isSeekSlider(obj):
+            return default.Script.getTextForValue(self, obj)
+
+        try:
+            value = obj.queryValue()
+        except NotImplementedError:
+            return default.Script.getTextForValue(self, obj)
+        else:
+            return self._formatDuration(int(value.currentValue)/1000)
diff --git a/src/orca/scripts/apps/Banshee/speech_generator.py b/src/orca/scripts/apps/Banshee/speech_generator.py
new file mode 100644
index 0000000..b0f8835
--- /dev/null
+++ b/src/orca/scripts/apps/Banshee/speech_generator.py
@@ -0,0 +1,19 @@
+from orca.speech_generator import SpeechGenerator as BaseSpeechGenerator
+import pyatspi
+
+class SpeechGenerator(BaseSpeechGenerator):
+    def _generateImage(self, obj, **args):
+        """Returns an array of strings (and possibly voice and audio
+        specifications) that represent the image on the the object, if
+        it exists.  Otherwise, an empty array is returned.
+        """
+        result = []
+        try:
+            image = obj.queryImage()
+        except:
+            pass
+        else:
+            args['role'] = pyatspi.ROLE_IMAGE
+            result.extend(self.generate(obj, **args))
+        return result
+
diff --git a/src/orca/scripts/apps/Makefile.am b/src/orca/scripts/apps/Makefile.am
index 8a1f43d..973766d 100644
--- a/src/orca/scripts/apps/Makefile.am
+++ b/src/orca/scripts/apps/Makefile.am
@@ -8,7 +8,8 @@ SUBDIRS = \
 	rhythmbox \
 	Thunderbird \
 	gedit \
-	gnome-window-properties
+	gnome-window-properties \
+	Banshee
 
 orca_pathdir=$(pyexecdir)
 
diff --git a/src/orca/settings.py b/src/orca/settings.py
index 61d402e..d7c1bde 100644
--- a/src/orca/settings.py
+++ b/src/orca/settings.py
@@ -1129,6 +1129,9 @@ setScriptMapping(re.compile(_('gaim')), "pidgin")
 #setScriptMapping(re.compile(_('gnome-help')), "yelp")
 setScriptMapping(re.compile('gnome-help'), "yelp")
 
+# This is for development builds of Banshee
+setScriptMapping(re.compile('Nereid'), "Banshee")
+
 # Strip off the extra 'py' that the Device Driver Utility includes
 # as part of its accessible name.
 #



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]