[orca/orca-gnome3: 69/87] Second speech plugin approximation Intgrating plugin system in Orca's boot sequence #2



commit 6bd6f96a9e23477f1a889a69b7671fb87db82d42
Author: Javier Hernández Antúnez <jhernandez emergya es>
Date:   Mon Mar 28 17:55:47 2011 +0200

    Second speech plugin approximation
    Intgrating plugin system in Orca's boot sequence #2

 src/orca/baseplugins/speech.py     |   30 +++++++++++++++++++++++-------
 src/orca/orca.py                   |   14 +++++++++++++-
 src/orca/orca_gui_prefs.py         |   23 +++++++++++++++++++++--
 src/orca/pluglib/interfaces.py     |    4 ++--
 src/orca/pluglib/plugin_manager.py |    7 +++++--
 src/orca/scripts/default.py        |    8 +++++++-
 src/orca/settings.py               |    3 ++-
 7 files changed, 73 insertions(+), 16 deletions(-)
---
diff --git a/src/orca/baseplugins/speech.py b/src/orca/baseplugins/speech.py
index d39a207..87199c4 100644
--- a/src/orca/baseplugins/speech.py
+++ b/src/orca/baseplugins/speech.py
@@ -92,6 +92,8 @@ class speechPlugin(IPlugin, IPresenter):
         from orca.acss import ACSS
         from orca.orca_i18n import _           # for gettext support
 
+        settings.enableSpeech = True
+
         self.init()
 
     def getSpeechServerFactories(self):
@@ -104,6 +106,11 @@ class speechPlugin(IPlugin, IPresenter):
     
         moduleNames = settings.speechFactoryModules
         for moduleName in moduleNames:
+            # JH: Review this if necessary
+            # with this replacement, we're showing voices combolists
+            # values succesfully
+            #
+            moduleName = 'orca.%s' % moduleName
             try:
                 module =  __import__(moduleName,
                                      globals(),
@@ -157,6 +164,11 @@ class speechPlugin(IPlugin, IPresenter):
             raise Exception("No speech server for factory: %s" % moduleName)
     
     def init(self):
+        global _speechserver
+        global settings
+
+        print _speechserver
+
         if _speechserver:
             return
         
@@ -164,7 +176,7 @@ class speechPlugin(IPlugin, IPresenter):
             moduleName = settings.speechServerFactory
             self._initSpeechServer(moduleName,
                               settings.speechServerInfo)
-            print moduleName
+            print 'ModuleName = ', moduleName
         except:
             moduleNames = settings.speechFactoryModules
             for moduleName in moduleNames:
@@ -233,6 +245,8 @@ class speechPlugin(IPlugin, IPresenter):
         """Speaks the given content.  The content can be either a simple
         string or an array of arrays of objects returned by a speech
         generator."""
+
+        print "someone has called me to speak %s" % content
     
         if settings.silenceSpeech:
             return
@@ -368,9 +382,7 @@ class speechPlugin(IPlugin, IPresenter):
     def stop(self):
         if _speechserver:
             _speechserver.stop()
-    
-    
-    
+
     def updatePunctuationLevel(self, script=None, inputEvent=None):
         """ Punctuation level changed, inform this speechServer. """
     
@@ -382,7 +394,7 @@ class speechPlugin(IPlugin, IPresenter):
             log.info(logLine)
     
         return True
-    
+
     def increaseSpeechRate(self, script=None, inputEvent=None):
         if _speechserver:
             _speechserver.increaseSpeechRate()
@@ -392,7 +404,7 @@ class speechPlugin(IPlugin, IPresenter):
             log.info(logLine)
     
         return True
-    
+
     def decreaseSpeechRate(self, script=None, inputEvent=None):
         if _speechserver:
             _speechserver.decreaseSpeechRate()
@@ -402,7 +414,7 @@ class speechPlugin(IPlugin, IPresenter):
             log.info(logLine)
     
         return True
-    
+
     def increaseSpeechPitch(self, script=None, inputEvent=None):
         if _speechserver:
             _speechserver.increaseSpeechPitch()
@@ -472,4 +484,8 @@ class speechPlugin(IPlugin, IPresenter):
         string = multiCaseReg3.sub('\\1 \\2', string)    
         return string
 
+    def disable(self):
+        settings.enableSpeech = False
+        self.shutdown()
+
 IPlugin.register(speechPlugin)
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 544b274..20ef59b 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -559,6 +559,7 @@ import orca_state
 #
 #import speech
 global speech
+speech = None
 
 import notification_messages
 
@@ -1503,7 +1504,14 @@ def loadUserSettings(script=None, inputEvent=None, skipReloadMessage=False):
         dbusserver.shutdown()
 
     httpserver.shutdown()
-    speech.shutdown()
+    # JH / TODO: Must do something smarter
+    # Hard code for speech plugin
+    #
+    try:
+        speech.shutdown()
+    except:
+        print 'Passing speech'
+        pass
     braille.shutdown()
     mag.shutdown()
 
@@ -1546,8 +1554,11 @@ def loadUserSettings(script=None, inputEvent=None, skipReloadMessage=False):
     # Enable starting plugins
     activeStartingPlugins(activePlugins)
 
+    #print 'el if =', (settings.enableSpeech and 'speech' in activePlugins)
+
     if settings.enableSpeech and 'speech' in activePlugins:
         speech = _pluginManager.getPluginObject('speech')
+        if speech == None: import dummyspeech as speech
         try:
             speech.init()
             if reloaded and not skipReloadMessage:
@@ -1564,6 +1575,7 @@ def loadUserSettings(script=None, inputEvent=None, skipReloadMessage=False):
             debug.println(debug.LEVEL_SEVERE,
                           "Could not initialize connection to speech.")
     else:
+        if speech == None: import dummyspeech as speech
         debug.println(debug.LEVEL_CONFIGURATION,
                       "Speech module has NOT been initialized.")
 
diff --git a/src/orca/orca_gui_prefs.py b/src/orca/orca_gui_prefs.py
index 2912582..be9a3e3 100644
--- a/src/orca/orca_gui_prefs.py
+++ b/src/orca/orca_gui_prefs.py
@@ -48,16 +48,20 @@ import input_event
 import keybindings
 import pronunciation_dict
 import braille
-import speech
-import speechserver
+#import speechserver
 import text_attribute_names
 
+
 import orca_gui_profile
 
 _settingsManager = getattr(orca, '_settingsManager')
 _scriptManager = getattr(orca, '_scriptManager')
 _pluginManager = getattr(orca, '_pluginManager')
 
+speech = _pluginManager.getPluginObject('speech')
+if speech == None: import dummyspeech as speech
+import speechserver
+
 # needed to fill the graphical treeview
 #import pluglib
 #from pluglib.plugin_manager import plugmanager
@@ -985,6 +989,8 @@ class OrcaSetupGUI(orca_gtkbuilder.GtkBuilderWrapper):
         """Initialize the various speech components.
         """
 
+        print 'in orca_gui_prefs::_initSpeechState(self)'
+
         voices = self.prefsDict["voices"]
         self.defaultVoice   = acss.ACSS(voices.get(settings.DEFAULT_VOICE))
         self.uppercaseVoice = acss.ACSS(voices.get(settings.UPPERCASE_VOICE))
@@ -1001,6 +1007,7 @@ class OrcaSetupGUI(orca_gtkbuilder.GtkBuilderWrapper):
         # Where * = speechSystems, speechServers, speechFamilies
         #
         factories = speech.getSpeechServerFactories()
+
         if len(factories) == 0:
             self.workingFactories = []
             self.speechSystemsChoice = None
@@ -2321,6 +2328,10 @@ class OrcaSetupGUI(orca_gtkbuilder.GtkBuilderWrapper):
         else:
             _pluginManager.disablePlugin(plugin_name)
 
+        if plugin_name == 'speech':
+            self.__updateSpeechTab(active)
+
+
 # nacho's
 #        if active:
 #            self.currentPluginsStatus[plugin_name]
@@ -2328,6 +2339,14 @@ class OrcaSetupGUI(orca_gtkbuilder.GtkBuilderWrapper):
 #            self.currentPluginsStatus[plugin_name]
 #        self.plugins_store[path][0] = checkbox.get_active()
 
+    def __updateSpeechTab(self, active):
+        notebook = self.get_widget('notebook')
+        speechTab = notebook.get_nth_page(1)
+        if active == True:
+            speechTab.show()
+        else:
+            speechTab.hide()
+            speech.shutdown()
 
     def __initProfileCombo(self):
         """Adding available profiles and setting active as the active one"""
diff --git a/src/orca/pluglib/interfaces.py b/src/orca/pluglib/interfaces.py
index b7abd80..4dd4278 100644
--- a/src/orca/pluglib/interfaces.py
+++ b/src/orca/pluglib/interfaces.py
@@ -126,11 +126,11 @@ class IPluginManager(object):
         """Scan plugin paths looking for plugins"""
 
     @abc.abstractmethod
-    def enable_plugin(plugin):
+    def enablePlugin(plugin):
         """Perform the process of plugin activation"""
 
     @abc.abstractmethod
-    def disable_plugin(plugin):
+    def disablePlugin(plugin):
         """Perform the process of plugin deactivation"""
 
     @abc.abstractmethod    
diff --git a/src/orca/pluglib/plugin_manager.py b/src/orca/pluglib/plugin_manager.py
index 17a6c92..a09f370 100644
--- a/src/orca/pluglib/plugin_manager.py
+++ b/src/orca/pluglib/plugin_manager.py
@@ -208,7 +208,7 @@ class ModulePluginManager(IPluginManager):
 #        self.store_conf.updatePlugin({plugin_name: enabling_plugins})
 
         if self.plugins:
-            print self.plugins
+            #print self.plugins
             # load the class in the plugin list maintained in memory
             self.load_class_in_plugin(self.plugins[plugin_name], plugin_name, PLUGINS_DIR)
 
@@ -331,7 +331,10 @@ class ModulePluginManager(IPluginManager):
             return True
 
     def getPluginObject(self, plugin_name):
-        return self.plugins[plugin_name]['object']
+        if not 'object' in self.plugins[plugin_name]:
+            return None
+        else:
+            return self.plugins[plugin_name]['object']
 
     def getPlugins(self):
         self.scanPluginsDir()
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index cd8155f..dc2a4ef 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -35,6 +35,7 @@ import time
 
 import orca.orca as orca
 _settingsManager = getattr(orca, '_settingsManager')
+_pluginManager = getattr(orca, '_pluginManager') 
 
 import pyatspi
 import orca.braille as braille
@@ -53,8 +54,13 @@ import orca.orca_state as orca_state
 import orca.phonnames as phonnames
 import orca.script as script
 import orca.settings as settings
-import orca.speech as speech
+
+#import orca.speech as speech
+#import orca.speechserver as speechserver
+speech = _pluginManager.getPluginObject('speech')
+if speech == None: import orca.dummyspeech as speech
 import orca.speechserver as speechserver
+
 import orca.mouse_review as mouse_review
 import orca.text_attribute_names as text_attribute_names
 import orca.notification_messages as notification_messages
diff --git a/src/orca/settings.py b/src/orca/settings.py
index 73870a2..ca3f976 100644
--- a/src/orca/settings.py
+++ b/src/orca/settings.py
@@ -207,7 +207,8 @@ excludeKeys = ["pronunciations",
                "keybindings",
                "startingProfile",
                "activeProfile",
-               "firstStart"]
+               "firstStart",
+               "plugins"]
 
 # The name of the module that hold the user interface for the main window
 # for Orca. This module is expected to have two methods, showMainUI and



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