Author: remi
Date: 2009-03-27 20:37:57 +0100 (Fri, 27 Mar 2009)
New Revision: 4227

Added:
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/Attitune.py
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttituneDescription.py
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttitunesContainer.py
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/__init__.py
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/AttituneManager.py
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstAttitunes.py
Modified:
   
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
Log:
* added classes to control the attitune manager

Modified: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
  2009-03-27 19:36:12 UTC (rev 4226)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/TuxAPI.py
  2009-03-27 19:37:57 UTC (rev 4227)
@@ -17,6 +17,7 @@
 from tuxdroid.const.ConstTuxDriver import *
 from tuxdroid.const.ConstTuxOsl import *
 from tuxdroid.const.ConstFramework import *
+from tuxdroid.const.ConstAttitunes import *
 from tuxdroid.MouthEyes import MouthEyes
 from tuxdroid.TTS import TTS
 from tuxdroid.Wav import Wav
@@ -32,6 +33,7 @@
 from tuxdroid.Light import Light
 from tuxdroid.Battery import Battery
 from tuxdroid.Charger import Charger
+from tuxdroid.AttituneManager import AttituneManager
 
 # 
------------------------------------------------------------------------------
 # Tux Droid API.
@@ -91,6 +93,8 @@
         self.charger = Charger(self, self.server)
         # Create the framework object
         self.framework = Framework(self, self.server)
+        # Create the attitune manager object
+        self.attitunes = AttituneManager(self, self.server)
         # Initialize the helper
         Helper.__init__(self)
 

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/Attitune.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/Attitune.py
                              (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/Attitune.py
      2009-03-27 19:37:57 UTC (rev 4227)
@@ -0,0 +1,98 @@
+#    Copyright (C) 2009 C2ME Sa
+#    Remi Jocaille <[email protected]>
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+import time
+
+from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource
+from tuxisalive.api.tuxdroid.const.ConstAttitunes import *
+from AttituneDescription import AttituneDescription
+
+# 
------------------------------------------------------------------------------
+# Attitune
+# 
------------------------------------------------------------------------------
+class Attitune(ApiBaseChildResource):
+
+    # 
--------------------------------------------------------------------------
+    # Constructor of the class.
+    # 
--------------------------------------------------------------------------
+    def __init__(self, apiBase, apiBaseServer, parent, infosStructure):
+        """Constructor of the class.
+        @param apiBase: ApiBase parent object.
+        @param apiBaseServer: ApiBaseServer object.
+        @param parent: Parent Attitunes container.
+        @param infosStructure: Attitune structure as dictionary.
+        """
+        ApiBaseChildResource.__init__(self, apiBase, apiBaseServer)
+        self.__parent = parent
+        self.__description = AttituneDescription(self, infosStructure)
+
+    # 
--------------------------------------------------------------------------
+    # Get the parent attitunes container.
+    # 
--------------------------------------------------------------------------
+    def getContainer(self):
+        """Get the parent attitunes container.
+        @return: The parent attitunes container.
+        """
+        return self.__parent
+
+    # 
--------------------------------------------------------------------------
+    # Get the attitune description object.
+    # 
--------------------------------------------------------------------------
+    def getDescription(self):
+        """Get the gadget description object.
+        @return: The gadget description object.
+        """
+        return self.__description
+
+    # 
--------------------------------------------------------------------------
+    # Show the description in the console.
+    # 
--------------------------------------------------------------------------
+    def showDescription(self):
+        """Show the description in the console.
+        """
+        self.__description.show()
+
+    # 
--------------------------------------------------------------------------
+    # Start this attitune.
+    # 
--------------------------------------------------------------------------
+    def startAsync(self, begin = 0.0):
+        """Start this attitune.
+        @param begin: Begin time.
+        @return: The success of the attitune start.
+        """
+        if not self._checkObjectType('begin', begin, 'float'):
+            return False
+        if begin > self.__description.getDuration():
+            return False
+        argsToSend = {
+            'name' : self.__description.getName(),
+            'begin' : begin,
+        }
+        cmd = "attitune_manager/start_attitune_by_name?"
+        return self._sendCommandBooleanResult(cmd, argsToSend)
+
+    # 
--------------------------------------------------------------------------
+    # Start this attitune.
+    # 
--------------------------------------------------------------------------
+    def start(self, begin = 0.0):
+        """Start this attitune.
+        @param begin: Begin time.
+        @return: The success of the attitune start.
+        """
+        if not self.startAsync(begin):
+            return False
+        time.sleep(0.5)
+        self._waitFor(ST_NAME_AM_ATTITUNE_STOPPED, 
self.__description.getName(),
+            600.0)
+        return True
+
+    # 
--------------------------------------------------------------------------
+    # Stop the attitune.
+    # 
--------------------------------------------------------------------------
+    def stop(self):
+        """Stop the attitune.
+        """
+        cmd = "attitune_manager/stop_attitune?"
+        return self._sendCommandBooleanResult(cmd)


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/Attitune.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttituneDescription.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttituneDescription.py
                           (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttituneDescription.py
   2009-03-27 19:37:57 UTC (rev 4227)
@@ -0,0 +1,141 @@
+#    Copyright (C) 2009 C2ME Sa
+#    Remi Jocaille <[email protected]>
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+from tuxisalive.api.base.lib.Helper import Helper
+
+# 
------------------------------------------------------------------------------
+# Attitune description.
+# 
------------------------------------------------------------------------------
+class AttituneDescription(Helper):
+    """Attitune description.
+    """
+
+    # 
--------------------------------------------------------------------------
+    # Constructor of the class.
+    # 
--------------------------------------------------------------------------
+    def __init__(self, parent, dictionary):
+        """Constructor of the class.
+        @param parent: Parent Attitune.
+        @param dictionary: Description as dictionary.
+        """
+        Helper.__init__(self)
+        self.__parent = parent
+        self.__dictionary = dictionary
+
+    # 
--------------------------------------------------------------------------
+    # Get the parent attitune.
+    # 
--------------------------------------------------------------------------
+    def getParent(self):
+        """Get the parent attitune.
+        @return: A Gadget object.
+        """
+        return self.__parent
+
+    # 
--------------------------------------------------------------------------
+    # Get the dictionary.
+    # 
--------------------------------------------------------------------------
+    def getDictionary(self):
+        """Get the dictionary.
+        @return: A dictionary.
+        """
+        return self.__dictionary
+
+    # 
--------------------------------------------------------------------------
+    # Get the attitune name.
+    # 
--------------------------------------------------------------------------
+    def getName(self):
+        """Get the attitune name.
+        @return: A string.
+        """
+        return self.__dictionary['name']
+
+    # 
--------------------------------------------------------------------------
+    # Get the author of the attitune.
+    # 
--------------------------------------------------------------------------
+    def getAuthor(self):
+        """Get the author of the attitune.
+        @return: A string.
+        """
+        return self.__dictionary['author']
+
+    # 
--------------------------------------------------------------------------
+    # Get the version of the attitune.
+    # 
--------------------------------------------------------------------------
+    def getVersion(self):
+        """Get the version of the attitune.
+        @return: A string.
+        """
+        return self.__dictionary['version']
+
+    # 
--------------------------------------------------------------------------
+    # Get the description of the attitune.
+    # 
--------------------------------------------------------------------------
+    def getDescription(self):
+        """Get the description of the attitune.
+        @return: A string.
+        """
+        return self.__dictionary['description']
+
+    # 
--------------------------------------------------------------------------
+    # Get the category of the attitune.
+    # 
--------------------------------------------------------------------------
+    def getCategory(self):
+        """Get the category of the attitune.
+        @return: A string.
+        """
+        return self.__dictionary['category']
+
+    # 
--------------------------------------------------------------------------
+    # Get the sub-category of the attitune.
+    # 
--------------------------------------------------------------------------
+    def getSubCategory(self):
+        """Get the sub-category of the attitune.
+        @return: A string.
+        """
+        return self.__dictionary['sub_category']
+
+    # 
--------------------------------------------------------------------------
+    # Get the language of the attitune.
+    # 
--------------------------------------------------------------------------
+    def getLanguage(self):
+        """Get the language of the attitune.
+        @return: A string.
+        """
+        return self.__dictionary['language']
+
+    # 
--------------------------------------------------------------------------
+    # Get the duration of the attitune.
+    # 
--------------------------------------------------------------------------
+    def getDuration(self):
+        """Get the duration of the attitune.
+        @return: A string.
+        """
+        return float(self.__dictionary['length'])
+
+    # 
--------------------------------------------------------------------------
+    # Get the keywords of the attitune.
+    # 
--------------------------------------------------------------------------
+    def getKeywords(self):
+        """Get the keywords of the attitune.
+        @return: A string.
+        """
+        return self.__dictionary['keywords']
+
+    # 
--------------------------------------------------------------------------
+    # Show the description in the console.
+    # 
--------------------------------------------------------------------------
+    def show(self):
+        """Show the description in the console.
+        """
+        descList = []
+        descList.append("%s = %s" % ('Name', self.getName()))
+        descList.append("%s = %s" % ('Description', self.getDescription()))
+        descList.append("%s = %s" % ('Author', self.getAuthor()))
+        descList.append("%s = %s" % ('Version', self.getVersion()))
+        descList.append("%s = %s" % ('Category', self.getCategory()))
+        descList.append("%s = %s" % ('Sub-category', self.getSubCategory()))
+        descList.append("%s = %.3f" % ('Duration', self.getDuration()))
+        descList.append("%s = (%s)" % ('Keywords', self.getKeywords()))
+        self._showStringList("Attitune description :", descList)


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttituneDescription.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttitunesContainer.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttitunesContainer.py
                            (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttitunesContainer.py
    2009-03-27 19:37:57 UTC (rev 4227)
@@ -0,0 +1,108 @@
+#    Copyright (C) 2009 C2ME Sa
+#    Remi Jocaille <[email protected]>
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+import threading
+
+from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource
+from Attitune import Attitune
+
+# 
------------------------------------------------------------------------------
+# Attitunes container.
+# 
------------------------------------------------------------------------------
+class AttitunesContainer(ApiBaseChildResource):
+    """Attitunes container.
+    """
+
+    # 
--------------------------------------------------------------------------
+    # Constructor of the class.
+    # 
--------------------------------------------------------------------------
+    def __init__(self, apiBase, apiBaseServer, structure):
+        """Constructor of the class.
+        @param apiBase: ApiBase parent object.
+        @param apiBaseServer: ApiBaseServer object.
+        @param structure: Attitunes container structure as dictionary.
+        """
+        ApiBaseChildResource.__init__(self, apiBase, apiBaseServer)
+        self.__mutex = threading.Lock()
+        self.__attitunes = []
+        self._update(structure)
+
+    # 
--------------------------------------------------------------------------
+    # Update the container structure.
+    # 
--------------------------------------------------------------------------
+    def _update(self, structure):
+        """Update the container structure.
+        @param structure: The new container structure dictionary.
+        """
+        self.__mutex.acquire()
+        self.__attitunes = []
+        for key in structure.keys():
+            if key.lower().find('data') == 0:
+                self.__attitunes.append(Attitune(self.getParent(),
+                    self.getServer(), self, structure[key]))
+        self.__mutex.release()
+
+    # 
--------------------------------------------------------------------------
+    # Get the attitune objects list.
+    # 
--------------------------------------------------------------------------
+    def getAttitunes(self):
+        """Get the attitune objects list.
+        @return: A list of Attitune objects.
+        """
+        self.__mutex.acquire()
+        result = self.__attitunes
+        self.__mutex.release()
+        return result
+
+    # 
--------------------------------------------------------------------------
+    # Get the number of attitunes contains in the container.
+    # 
--------------------------------------------------------------------------
+    def getCount(self):
+        """Get the number of attitunes contains in the container.
+        @return: An integer.
+        """
+        self.__mutex.acquire()
+        result = len(self.__attitunes)
+        self.__mutex.release()
+        return result
+
+    # 
--------------------------------------------------------------------------
+    # Show the attitunes name list in the console.
+    # 
--------------------------------------------------------------------------
+    def showAttitunes(self):
+        """Show the attitunes name list in the console.
+        """
+        result = []
+        self.__mutex.acquire()
+        for attitune in self.__attitunes:
+            result.append(attitune.getDescription().getName())
+        self.__mutex.release()
+        self._showStringList("Attitune names :", result)
+
+    # 
--------------------------------------------------------------------------
+    # Get an attitune object by it name.
+    # 
--------------------------------------------------------------------------
+    def getAttitune(self, attituneName):
+        """Get an attitune object by it name.
+        @param attituneName: The name of the attitune.
+        @return: An Attitune object or None.
+        """
+        self.__mutex.acquire()
+        for attitune in self.__attitunes:
+            if attitune.getDescription().getName() == attituneName:
+                self.__mutex.release()
+                return attitune
+        self.__mutex.release()
+        return None
+
+    # 
--------------------------------------------------------------------------
+    # Stop played attitune.
+    # 
--------------------------------------------------------------------------
+    def stopAttitune(self):
+        """Stop played attitune.
+        @return: The success of the command.
+        """
+        cmd = "attitune_manager/stop_attitune?"
+        return self._sendCommandBooleanResult(cmd)


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/AttitunesContainer.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/__init__.py
===================================================================


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/attitunes/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/AttituneManager.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/AttituneManager.py
                                (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/AttituneManager.py
        2009-03-27 19:37:57 UTC (rev 4227)
@@ -0,0 +1,75 @@
+#    Copyright (C) 2009 C2ME Sa
+#    Remi Jocaille <[email protected]>
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+import os
+import time
+
+from const.ConstAttitunes import *
+from tuxisalive.api.attitunes.AttitunesContainer import AttitunesContainer
+from tuxisalive.api.base.ApiBaseChildResource import ApiBaseChildResource
+
+
+# 
------------------------------------------------------------------------------
+# Class to control the attitune manager.
+# 
------------------------------------------------------------------------------
+class AttituneManager(ApiBaseChildResource):
+    """Class to control the attitune manager.
+    """
+
+    # 
--------------------------------------------------------------------------
+    # Constructor of the class.
+    # 
--------------------------------------------------------------------------
+    def __init__(self, apiBase, apiBaseServer):
+        """Constructor of the class.
+        @param apiBase: ApiBase parent object.
+        @param apiBaseServer: ApiBaseServer object.
+        """
+        ApiBaseChildResource.__init__(self, apiBase, apiBaseServer)
+        for statusName in SW_NAME_ATTITUNE_MANAGER:
+            self._insertNewEvent(statusName)
+        self.__attitunesContainer = AttitunesContainer(apiBase, apiBaseServer, 
{})
+        self._registerEvent(ST_NAME_AM_CONTAINER_DEPLOYED, None,
+            self.__updateAttitunesContainer)
+        self.__syndicateToEvents()
+
+    # 
--------------------------------------------------------------------------
+    # Get the attitunes container.
+    # 
--------------------------------------------------------------------------
+    def getAttitunesContainer(self):
+        """Get the attitunes container.
+        @return: The attitunes container.
+        """
+        return self.__attitunesContainer
+
+    # 
--------------------------------------------------------------------------
+    # Get if the attitune manager is started or not.
+    # 
--------------------------------------------------------------------------
+    def isStarted(self):
+        """Get if the attitune manager is started or not.
+        @return: True or False:
+        """
+        ret = self._requestOne(ST_NAME_AM_RUN)
+        if ret == "True":
+            return True
+        else:
+            return False
+
+    # 
--------------------------------------------------------------------------
+    # Syndicate this api to the attitune manager events.
+    # 
--------------------------------------------------------------------------
+    def __syndicateToEvents(self):
+        """Syndicate this api to the attitune manager events.
+        """
+        for statusName in SW_NAME_ATTITUNE_MANAGER:
+            self._syndicateEvent(statusName)
+
+    # 
--------------------------------------------------------------------------
+    # Update attitunes list on container deloyed event.
+    # 
--------------------------------------------------------------------------
+    def __updateAttitunesContainer(self, *args):
+        cmd = "attitune_manager/attitunes_infos?"
+        ret, result = self._sendCommandFullResultEx(cmd)
+        if ret:
+            self.__attitunesContainer._update(result)


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/AttituneManager.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstAttitunes.py
===================================================================
--- 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstAttitunes.py
                           (rev 0)
+++ 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstAttitunes.py
   2009-03-27 19:37:57 UTC (rev 4227)
@@ -0,0 +1,18 @@
+#    Copyright (C) 2009 C2ME Sa
+#    Remi Jocaille <[email protected]>
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+#
+# Statuses declaration
+#
+ST_NAME_AM_RUN = "attitune_manager_run"
+ST_NAME_AM_CONTAINER_DEPLOYED = "attitune_manager_container_deployed"
+ST_NAME_AM_ATTITUNE_STARTING = "attitune_manager_attitune_starting"
+ST_NAME_AM_ATTITUNE_STOPPED = "attitune_manager_attitune_stopped"
+SW_NAME_ATTITUNE_MANAGER = [
+    ST_NAME_AM_RUN,
+    ST_NAME_AM_CONTAINER_DEPLOYED,
+    ST_NAME_AM_ATTITUNE_STARTING,
+    ST_NAME_AM_ATTITUNE_STOPPED,
+]


Property changes on: 
software_suite_v2/tuxware/pytuxisalive/branches/0.3.0/src/tuxisalive/api/tuxdroid/const/ConstAttitunes.py
___________________________________________________________________
Name: svn:keywords
   + Id


------------------------------------------------------------------------------
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to