Author: remi
Date: 2008-12-13 17:13:03 +0100 (Sat, 13 Dec 2008)
New Revision: 3086
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/AttituneToMacroDecl.py
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/AttitunesFileReader.py
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/__init__.py
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/version.py
Log:
* updated some dependencies with the new "Util" module
* fixed encoding
* updated version
* updated comments
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/AttituneToMacroDecl.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/AttituneToMacroDecl.py
2008-12-13 16:12:14 UTC (rev 3085)
+++
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/AttituneToMacroDecl.py
2008-12-13 16:13:03 UTC (rev 3086)
@@ -1,4 +1,4 @@
-# -*- coding: latin1 -*-
+# -*- coding: utf-8 -*-
import version
__author__ = version.author
@@ -7,11 +7,12 @@
__licence__ = version.licence
del version
-# Copyright (C) 2008 C2ME Sa
-# R�mi Jocaille <[email protected]>
+# Copyleft (C) 2008 C2ME Sa
+# Remi Jocaille <[email protected]>
# Distributed under the terms of the GNU General Public License
# http://www.gnu.org/copyleft/gpl.html
+# Leds command structures
LEDS_BLINK_CANVAS = {'cmd' : 'leds_blink', 'count' : 1.0, 'speed' : 1}
LEDS_ON_CANVAS = {'cmd' : 'leds_on', 'duration' : 0.0}
LEDL_ON_CANVAS = {'cmd' : 'ledl_on', 'duration' : 0.0}
@@ -20,49 +21,72 @@
LEDL_OFF_CANVAS = {'cmd' : 'ledl_off', 'duration' : 0.0}
LEDR_OFF_CANVAS = {'cmd' : 'ledr_off', 'duration' : 0.0}
+# Leds command types
LEDS_CMD_TYPES = {
- 'Led on/off':
+ 'Led on/off':
[
- 'leds_on',
- 'ledl_on',
+ 'leds_on',
+ 'ledl_on',
'ledr_on',
- 'leds_off',
- 'ledl_off',
+ 'leds_off',
+ 'ledl_off',
'ledr_off'
],
'Leds blink':
['leds_blink'],
}
+#
------------------------------------------------------------------------------
+# ledsBlinkTmc
+#
------------------------------------------------------------------------------
def ledsBlinkTmc(struct):
duration = (struct['speed'] * 0.004)
cmd = 'TUX_CMD:LED:BLINK:LED_BOTH,%d,%f' % (struct['count'], duration)
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# ledsOnTmc
+#
------------------------------------------------------------------------------
def ledsOnTmc(struct):
cmd = 'TUX_CMD:LED:ON:LED_BOTH,1.0'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# ledlOnTmc
+#
------------------------------------------------------------------------------
def ledlOnTmc(struct):
cmd = 'TUX_CMD:LED:ON:LED_LEFT,1.0'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# ledrOnTmc
+#
------------------------------------------------------------------------------
def ledrOnTmc(struct):
cmd = 'TUX_CMD:LED:ON:LED_RIGHT,1.0'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# ledsOffTmc
+#
------------------------------------------------------------------------------
def ledsOffTmc(struct):
cmd = 'TUX_CMD:LED:OFF:LED_BOTH'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# ledlOffTmc
+#
------------------------------------------------------------------------------
def ledlOffTmc(struct):
cmd = 'TUX_CMD:LED:OFF:LED_LEFT'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# ledrOffTmc
+#
------------------------------------------------------------------------------
def ledrOffTmc(struct):
cmd = 'TUX_CMD:LED:OFF:LED_RIGHT'
return [cmd,]
+# Mouth and eyes command structures
MOUTH_ON_CANVAS = {'cmd' : 'mouth_on', 'duration': 0.0, 'count' : 2}
MOUTH_OPEN_CANVAS = {'cmd' : 'mouth_open', 'duration': 0.0}
MOUTH_CLOSE_CANVAS = {'cmd' : 'mouth_close', 'duration': 0.0}
@@ -70,6 +94,7 @@
EYES_OPEN_CANVAS = {'cmd' : 'eyes_open', 'duration': 0.0}
EYES_CLOSE_CANVAS = {'cmd' : 'eyes_close', 'duration': 0.0}
+# Mouth and eyes command types
MOUTH_EYES_CMD_TYPES = {
'Mouth':
[
@@ -85,33 +110,53 @@
]
}
+#
------------------------------------------------------------------------------
+# mouthOnTmc
+#
------------------------------------------------------------------------------
def mouthOnTmc(struct):
cmd = 'TUX_CMD:MOUTH:ON:%d,NDEF' % struct['count']
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# mouthOpenTmc
+#
------------------------------------------------------------------------------
def mouthOpenTmc(struct):
cmd = 'TUX_CMD:MOUTH:OPEN'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# mouthCloseTmc
+#
------------------------------------------------------------------------------
def mouthCloseTmc(struct):
cmd = 'TUX_CMD:MOUTH:CLOSE'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# eyesOnTmc
+#
------------------------------------------------------------------------------
def eyesOnTmc(struct):
cmd = 'TUX_CMD:EYES:ON:%d,NDEF' % struct['count']
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# eyesOpenTmc
+#
------------------------------------------------------------------------------
def eyesOpenTmc(struct):
cmd = 'TUX_CMD:EYES:OPEN'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# eyesCloseTmc
+#
------------------------------------------------------------------------------
def eyesCloseTmc(struct):
cmd = 'TUX_CMD:EYES:CLOSE'
return [cmd,]
+# Sound play command structures
PLAY_FLASH_CANVAS = {'cmd' : 'sound_play', 'index' : 0, 'duration' : 0.0}
PLAY_WAVE_CANVAS = {'cmd' : 'wav_play', 'wav_name' : 'none', 'duration' : 0.0}
+# Sound plus command types
SOUND_CMD_TYPES = {
'Sound':
[
@@ -120,16 +165,26 @@
],
}
+#
------------------------------------------------------------------------------
+# soundPlayTmc
+#
------------------------------------------------------------------------------
def soundPlayTmc(struct):
cmd = 'TUX_CMD:SOUND_FLASH:PLAY:%d,100.0' % struct['index']
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# wavPlayTmc
+#
------------------------------------------------------------------------------
def wavPlayTmc(struct):
return ["",]
-SPINNING_LEFT_CANVAS = {'cmd' : 'spinl_on', 'duration': 0.0, 'count' : 2,
'speed': 5}
-SPINNING_RIGHT_CANVAS = {'cmd' : 'spinr_on', 'duration': 0.0, 'count' : 2,
'speed': 5}
+# Spinning command structures
+SPINNING_LEFT_CANVAS = {'cmd' : 'spinl_on', 'duration': 0.0, 'count' : 2,
+ 'speed': 5}
+SPINNING_RIGHT_CANVAS = {'cmd' : 'spinr_on', 'duration': 0.0, 'count' : 2,
+ 'speed': 5}
+# Spinning command types
SPINNING_CMD_TYPES = {
'Spinning':
[
@@ -138,16 +193,25 @@
],
}
+#
------------------------------------------------------------------------------
+# spinlOnTmc
+#
------------------------------------------------------------------------------
def spinlOnTmc(struct):
cmd = 'TUX_CMD:SPINNING:LEFT_ON:%d' % struct['count']
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# spinrOnTmc
+#
------------------------------------------------------------------------------
def spinrOnTmc(struct):
cmd = 'TUX_CMD:SPINNING:RIGHT_ON:%d' % struct['count']
return [cmd,]
-PLAY_TTS_CANVAS = {'cmd' : 'tts_play', 'text' : "Hello world", 'speaker' : 3,
'pitch': 100, 'duration' : 0.0}
+# TTS command structures
+PLAY_TTS_CANVAS = {'cmd' : 'tts_play', 'text' : "Hello world", 'speaker' : 3,
+ 'pitch': 100, 'duration' : 0.0}
+# TTS command types
TTS_CMD_TYPES = {
'TTS':
[
@@ -155,13 +219,17 @@
],
}
+# TTS locutors list
LOCUTOR_NAMES_LIST = [
- "Bruno8k", "Julie8k", "Ryan8k", "Heather8k","Sofie8k",
- "Klaus8k", "Sarah8k", "Graham8k","Lucy8k", "Salma8k",
- "Mette8k", "Maria8k", "Chiara8k", "Femke8k", "Kari8k",
+ "Bruno8k", "Julie8k", "Ryan8k", "Heather8k","Sofie8k",
+ "Klaus8k", "Sarah8k", "Graham8k","Lucy8k", "Salma8k",
+ "Mette8k", "Maria8k", "Chiara8k", "Femke8k", "Kari8k",
"Celia8k", "Erik8k", "Emma8k"
]
+#
------------------------------------------------------------------------------
+# ttsPlayTmc
+#
------------------------------------------------------------------------------
def ttsPlayTmc(struct):
cmds = []
locutor = LOCUTOR_NAMES_LIST[struct['speaker'] - 1]
@@ -174,10 +242,12 @@
cmds.append(cmd)
return cmds
+# Flippers command structures
FLIPPERS_ON_CANVAS = {'cmd' : 'wings_on', 'duration': 0.0, 'count' : 2}
FLIPPERS_UP_CANVAS = {'cmd' : 'wings_up', 'duration': 0.0}
FLIPPERS_DOWN_CANVAS = {'cmd' : 'wings_down', 'duration': 0.0}
+# Flippers command types
FLIPPERS_CMD_TYPES = {
'Wings':
[
@@ -187,24 +257,34 @@
],
}
+#
------------------------------------------------------------------------------
+# flippersOnTmc
+#
------------------------------------------------------------------------------
def flippersOnTmc(struct):
cmd = 'TUX_CMD:FLIPPERS:ON:%d,NDEF' % struct['count']
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# flippersUpTmc
+#
------------------------------------------------------------------------------
def flippersUpTmc(struct):
cmd = 'TUX_CMD:FLIPPERS:UP'
return [cmd,]
-
+
+#
------------------------------------------------------------------------------
+# flippersDownTmc
+#
------------------------------------------------------------------------------
def flippersDownTmc(struct):
cmd = 'TUX_CMD:FLIPPERS:DOWN'
return [cmd,]
-
+
+# Commands binding list
ATT_CMD_TO_MACRO_CMD_FUNCTS = {
'leds_on' : ledsOnTmc,
- 'ledl_on' : ledlOnTmc,
+ 'ledl_on' : ledlOnTmc,
'ledr_on' : ledrOnTmc,
- 'leds_off' : ledsOffTmc,
- 'ledl_off' : ledlOffTmc,
+ 'leds_off' : ledsOffTmc,
+ 'ledl_off' : ledlOffTmc,
'ledr_off' : ledrOffTmc,
'leds_blink' : ledsBlinkTmc,
'mouth_on' : mouthOnTmc,
@@ -221,8 +301,11 @@
'wings_on' : flippersOnTmc,
'wings_up' : flippersUpTmc,
'wings_down' : flippersDownTmc,
-}
+}
+#
------------------------------------------------------------------------------
+# attCmdToMacroCmd
+#
------------------------------------------------------------------------------
def attCmdToMacroCmd(struct):
if struct['cmd'] in ATT_CMD_TO_MACRO_CMD_FUNCTS.keys():
return ATT_CMD_TO_MACRO_CMD_FUNCTS[struct['cmd']](struct)
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/AttitunesFileReader.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/AttitunesFileReader.py
2008-12-13 16:12:14 UTC (rev 3085)
+++
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/AttitunesFileReader.py
2008-12-13 16:13:03 UTC (rev 3086)
@@ -1,4 +1,4 @@
-# -*- coding: latin1 -*-
+# -*- coding: utf-8 -*-
import version
__author__ = version.author
@@ -7,22 +7,32 @@
__licence__ = version.licence
del version
-# Copyright (C) 2008 C2ME Sa
-# R�mi Jocaille <[email protected]>
+# Copyleft (C) 2008 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 zipfile
import copy
-from tuxisalive.lib.misc.filesCache import CachedFilesContainer
-from tuxisalive.lib.misc.SimpleXMLStruct import xmlToStruct
+from tuxisalive.lib.Util.FilesCache import CachedFilesContainer
+from tuxisalive.lib.Util.XMLSerializer import fromXML
from AttituneToMacroDecl import attCmdToMacroCmd
+#
==============================================================================
+# Public class
+#
==============================================================================
+
+#
------------------------------------------------------------------------------
+# Class to read and parse attitunes files.
+#
------------------------------------------------------------------------------
class AttitunesFileReader(object):
"""Class to read and parse attitunes files.
"""
+ #
--------------------------------------------------------------------------
+ # Constructor.
+ #
--------------------------------------------------------------------------
def __init__(self, attPath):
"""Constructor of attitunes file reader object.
@param attPath: Attitune file path.
@@ -58,11 +68,18 @@
self.__preMacro()
+ #
--------------------------------------------------------------------------
+ # Return the validity of the attitunes read.
+ #
--------------------------------------------------------------------------
def getValid(self):
"""Return the validity of the attitunes read.
+ @return: True or False.
"""
return self.__isValid
+ #
--------------------------------------------------------------------------
+ # Uncompress the attitunes file.
+ #
--------------------------------------------------------------------------
def __uncompress(self):
"""Uncompress the attitunes file.
"""
@@ -114,6 +131,9 @@
break
return True
+ #
--------------------------------------------------------------------------
+ # Get the structure of the attitunes.
+ #
--------------------------------------------------------------------------
def __getStructure(self):
"""Get the structure of the attitunes.
"""
@@ -131,17 +151,21 @@
ret = False
if self.__xmlPath != "":
- ret, self.__timeline = xmlToStruct(self.__xmlPath)
+ self.__timeline = fromXML(self.__xmlPath)
- if not ret:
+ if self.__timeline == None:
return False
- self.__blocksStruct =
self.__timeline['scene']['body']['script']['timeline']
+ self.__blocksStruct = \
+ self.__timeline['scene']['body']['script']['timeline']
self.__blocksKeys = self.__blocksStruct.keys()
self.__blocksKeys.sort()
return True
+ #
--------------------------------------------------------------------------
+ # Convert the attitunes timeline to macro.
+ #
--------------------------------------------------------------------------
def __preMacro(self):
"""Convert the attitunes timeline to macro.
"""
@@ -159,12 +183,16 @@
if blockStruct['cmd'] == 'wav_play':
cmdStruct['delay'] = cmdStruct['delay'] - 0.3
if self.__wavs.has_key(blockStruct['wav_name']):
- cmdStruct['wav_path'] =
self.__wavs[blockStruct['wav_name']]
+ cmdStruct['wav_path'] = \
+ self.__wavs[blockStruct['wav_name']]
elif blockStruct['cmd'] == 'tts_play':
cmdStruct['delay'] = cmdStruct['delay'] - 0.3
self.__macroStruct.append(cmdStruct)
+ #
--------------------------------------------------------------------------
+ # Get a macro from the attitunes.
+ #
--------------------------------------------------------------------------
def toMacro(self, begin = 0.0):
"""Get a macro from the attitunes.
@param begin: The time begin index in seconds.
@@ -189,7 +217,8 @@
if newCmd.has_key('wav_path'):
idxb = begin - newCmd['delay']
if idxb < os.path.getsize(cmd['wav_path']):
- cmdStr = "OSL_CMD:WAV:PLAY:%f,0.0,%s" % (idxb,
newCmd['wav_path'])
+ cmdStr = "OSL_CMD:WAV:PLAY:%f,0.0,%s" % (idxb,
+ newCmd['wav_path'])
newCmd['cmd'] = cmdStr
newCmd['delay'] -= begin
macroLst.append(newCmd)
@@ -200,6 +229,9 @@
return result
+ #
--------------------------------------------------------------------------
+ # Destroy the attitunes reader object.
+ #
--------------------------------------------------------------------------
def destroy(self):
"""Destroy the attitunes reader object.
"""
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/__init__.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/__init__.py
2008-12-13 16:12:14 UTC (rev 3085)
+++
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/__init__.py
2008-12-13 16:13:03 UTC (rev 3086)
@@ -1,26 +1,28 @@
-"""
-Attitunes lib
-=============
-
- Python libraries for attitunes format.
-
- http://www.tuxisalive.com
-"""
-
-import version
-__name__ = version.name
-__author__ = version.author
-__date__ = version.date
-__version__ = version.version
-__licence__ = version.licence
-del version
-
-# Copyright (C) 2008 C2ME Sa
-# Remi Jocaille <[email protected]>
-# Distributed under the terms of the GNU General Public License
-# http://www.gnu.org/copyleft/gpl.html
-
-#
-# attitunes package modules
-#
-from tuxisalive.lib.attitunes.AttitunesFileReader import *
+# -*- coding: utf-8 -*-
+
+"""
+Attitunes lib
+=============
+
+ Python libraries for attitunes format.
+
+ http://www.tuxisalive.com
+"""
+
+import version
+__name__ = version.name
+__author__ = version.author
+__date__ = version.date
+__version__ = version.version
+__licence__ = version.licence
+del version
+
+# Copyleft (C) 2008 C2ME Sa
+# Remi Jocaille <[email protected]>
+# Distributed under the terms of the GNU General Public License
+# http://www.gnu.org/copyleft/gpl.html
+
+#
+# attitunes package modules
+#
+from tuxisalive.lib.attitunes.AttitunesFileReader import *
Modified:
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/version.py
===================================================================
---
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/version.py
2008-12-13 16:12:14 UTC (rev 3085)
+++
software_suite_v2/tuxware/pytuxisalive/branches/complete_refactoring/src/tuxisalive/lib/attitunes/version.py
2008-12-13 16:13:03 UTC (rev 3086)
@@ -1,19 +1,19 @@
-# -*- coding: latin1 -*-
+# -*- coding: utf-8 -*-
"""Version data for attitunes"""
__author__ = "Remi Jocaille ([email protected])"
-# Copyright (C) 2008 C2ME Sa
+# Copyleft (C) 2008 C2ME Sa
# Remi Jocaille <[email protected]>
# Distributed under the terms of the GNU General Public License
# http://www.gnu.org/copyleft/gpl.html
name = 'tuxisalive.lib.attitunes'
-version = '0.0.3'
+version = '0.0.4'
author = "Remi Jocaille ([email protected])"
description = "Libraries for Tuxdroid"
licence = "GPL"
-date = "May 2008"
\ No newline at end of file
+date = "December 2008"
\ No newline at end of file
------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn