[tuxdroid-svn] r4565 - in softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-04-20 14:09:43
|
Author: remi Date: 2009-04-20 16:09:29 +0200 (Mon, 20 Apr 2009) New Revision: 4565 Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/build.py softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/GadgetPackager.py softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/__init__.py softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/__init__.py softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/DirectoriesAndFilesTools.py softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/__init__.py softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/version.py softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/version.py Removed: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/GadgetHelper.py Modified: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/tuxdroid-gadget-skype.py softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/resources/gadget.xml Log: * adapted the gadget to perfectly run in the python framework. * bumped to 0.2 * fixed sound card selection on windows XP Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/build.py =================================================================== --- softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/build.py (rev 0) +++ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/build.py 2009-04-20 14:09:29 UTC (rev 4565) @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- + +# Copyleft (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +from builder.GadgetPackager import GadgetPackager + +if __name__ == "__main__": + GadgetPackager().createTgf("tuxdroid-gadget-skype.tgf") Property changes on: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/build.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/GadgetPackager.py =================================================================== --- softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/GadgetPackager.py (rev 0) +++ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/GadgetPackager.py 2009-04-20 14:09:29 UTC (rev 4565) @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- + +import version +__author__ = version.author +__date__ = version.date +__version__ = version.version +__licence__ = version.licence +del version + +# Copyleft (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +import os +from zipfile import * + +from util.misc.DirectoriesAndFilesTools import * + +# ------------------------------------------------------------------------------ +# Class to create a TGF file from the main directory of a python gadget project. +# ------------------------------------------------------------------------------ +class GadgetPackager(object): + """Class to create a TGF file from the main directory of a python gadget + project. + """ + + # -------------------------------------------------------------------------- + # Create a tgf file. + # -------------------------------------------------------------------------- + def createTgf(self, tgfFileName): + """Create a tgf file. + @param tgfFileName: Tux Gadget Format file name. + @return: The success of the file creation. + """ + self.__sourcePath = os.path.realpath("") + if not os.path.isdir(self.__sourcePath): + return False + if not os.path.isdir(os.path.join(self.__sourcePath, "executables")): + return False + if not os.path.isdir(os.path.join(self.__sourcePath, "resources")): + return False + # Get some paths + SRC_EXECUTABLES_PATH = os.path.join(self.__sourcePath, "executables") + SRC_RESOURCES_PATH = os.path.join(self.__sourcePath, "resources") + TMP_BUILD_PATH = os.path.join(self.__sourcePath, "tmp") + DEST_EXECUTABLES_PATH = os.path.join(TMP_BUILD_PATH, "executables") + DEST_RESOURCES_PATH = os.path.join(TMP_BUILD_PATH, "resources") + DEST_TGF_FILENAME = os.path.join(self.__sourcePath, tgfFileName) + # Create the temporary build path + MKDirsF(TMP_BUILD_PATH) + # Copy "executables" directory + CPDir(SRC_EXECUTABLES_PATH, DEST_EXECUTABLES_PATH) + # Copy "resources" directory + CPDir(SRC_RESOURCES_PATH, DEST_RESOURCES_PATH) + # Filtering the content of temporary path + RMWithFilters(TMP_BUILD_PATH, filters = ['.svn', '.pyc']) + # Create a zip file + directory = TMP_BUILD_PATH + last_cwd = os.getcwd() + os.chdir(TMP_BUILD_PATH) + zf = ZipFile(DEST_TGF_FILENAME, 'w', compression = ZIP_DEFLATED) + def walker(zip, directory, files, root = directory): + for file in files: + file = os.path.join(directory, file) + name = file[len(TMP_BUILD_PATH) + 1:] + if os.path.isfile(file): + zip.write(file, name, ZIP_DEFLATED) + elif os.path.isdir(file): + file = os.path.join(file, "") + name = os.path.join(name, "") + zip.writestr(name, name) + os.path.walk(TMP_BUILD_PATH, walker, zf) + zf.close() + os.chdir(os.path.abspath(last_cwd)) + # Remove the temporary directory + RMDirs(TMP_BUILD_PATH) + return True Property changes on: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/GadgetPackager.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/__init__.py =================================================================== Property changes on: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/__init__.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/__init__.py =================================================================== Property changes on: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/__init__.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/DirectoriesAndFilesTools.py =================================================================== --- softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/DirectoriesAndFilesTools.py (rev 0) +++ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/DirectoriesAndFilesTools.py 2009-04-20 14:09:29 UTC (rev 4565) @@ -0,0 +1,161 @@ +# -*- coding: utf-8 -*- + +import version +__author__ = version.author +__date__ = version.date +__version__ = version.version +__licence__ = version.licence +del version + +# Copyleft (C) 2008 Acness World +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +import os +import shutil + +if os.name == 'nt': + import win32con + import win32file + +# ============================================================================== +# Public functions +# ============================================================================== + +# ------------------------------------------------------------------------------ +# Force to create a directories tree if not exists. +# ------------------------------------------------------------------------------ +def MKDirs(path): + """Force to create a directories tree if not exists. + @param path: Directory path. + """ + if not os.path.isdir(path): + try: + os.makedirs(path) + except: + pass + +# ------------------------------------------------------------------------------ +# Force to create a directories tree after having deleted the old one. +# ------------------------------------------------------------------------------ +def MKDirsF(path): + """Force to create a directories tree after having deleted the old one. + @param path: Directory path. + """ + if os.path.isdir(path): + RMDirs(path) + os.makedirs(path) + +# ------------------------------------------------------------------------------ +# Remove directories and files recursively. +# ------------------------------------------------------------------------------ +def RMDirs(path): + """Remove directories and files recursively. + @param path: Path of the base directory. + """ + if not os.path.isdir(path): + return + for root, dirs, files in os.walk(path, topdown = False): + for d in dirs: + try: + os.removedirs(os.path.join(root, d)) + except: + pass + for f in files: + try: + if os.name == 'nt': + win32file.SetFileAttributesW(os.path.join(root, f), + win32con.FILE_ATTRIBUTE_NORMAL) + os.remove(os.path.join(root, f)) + except: + pass + if os.path.isdir(path): + try: + os.removedirs(path) + except: + pass + +# ------------------------------------------------------------------------------ +# Remove directories and files recursively with filters. +# ------------------------------------------------------------------------------ +def RMWithFilters(path, filters = ['.pyc', '.pyo']): + """Remove directories and files recursively with filters. + @param path: Path of the base directory. + @param filters: Filters as list. + """ + def checkFilter(name): + for filter in filters: + if name.lower().find(filter.lower()) == (len(name) - len(filter)): + return True + return False + + if not os.path.isdir(path): + return + + for root, dirs, files in os.walk(path, topdown = False): + for d in dirs: + if checkFilter(os.path.join(root, d)): + try: + RMDirs(os.path.join(root, d)) + except: + pass + for f in files: + if checkFilter(os.path.join(root, f)): + try: + if os.name == 'nt': + win32file.SetFileAttributesW(os.path.join(root, f), + win32con.FILE_ATTRIBUTE_NORMAL) + os.remove(os.path.join(root, f)) + except: + pass + +# ------------------------------------------------------------------------------ +# Remove a file. +# ------------------------------------------------------------------------------ +def RMFile(path): + """Remove a file. + @param path: File path. + """ + if os.path.isfile(path): + try: + if os.name == 'nt': + win32file.SetFileAttributesW(path, + win32con.FILE_ATTRIBUTE_NORMAL) + os.remove(path) + except: + pass + +# ------------------------------------------------------------------------------ +# Copy a directories tree to another directory. +# ------------------------------------------------------------------------------ +def CPDir(src, dest): + """Copy a directories tree to another directory. + @param src: Source path. + @param dest: Destination path. + """ + if not os.path.isdir(src): + return + if os.path.isdir(dest): + RMDirs(dest) + shutil.copytree(src, dest) + +# ------------------------------------------------------------------------------ +# Retrieve the OS temporary directory. +# ------------------------------------------------------------------------------ +def GetOSTMPDir(): + """Retrieve the OS temporary directory. + @return: The OS temporary directory. + """ + result = None + # On Windows + if os.name == 'nt': + result = os.environ.get('tmp') + if result == None: + result = os.environ.get('temp') + if result == None: + result = "c:\\windows\\temp" + # On linux + else: + result = "/tmp" + return result Property changes on: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/DirectoriesAndFilesTools.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/__init__.py =================================================================== Property changes on: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/__init__.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/version.py =================================================================== --- softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/version.py (rev 0) +++ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/version.py 2009-04-20 14:09:29 UTC (rev 4565) @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +"""Version data for tuxisalive.lib.Util""" + +__author__ = "Remi Jocaille (rem...@c2...)" + +# Copyleft (C) 2008 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +name = 'util.misc' +version = '0.0.1' +author = "Remi Jocaille (rem...@c2...)" + +description = "Utilities libraries." + +licence = "GPL" +date = "December 2008" Property changes on: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/util/misc/version.py ___________________________________________________________________ Name: svn:keywords + Id Added: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/version.py =================================================================== --- softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/version.py (rev 0) +++ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/version.py 2009-04-20 14:09:29 UTC (rev 4565) @@ -0,0 +1,9 @@ +# Copyleft (C) 2009 C2ME Sa +# Remi Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +version = '0.0.1' +author = "Remi Jocaille (rem...@c2...)" +licence = "GPL" +date = "2009" Property changes on: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/builder/version.py ___________________________________________________________________ Name: svn:keywords + Id Deleted: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/GadgetHelper.py =================================================================== --- softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/GadgetHelper.py 2009-04-20 13:00:24 UTC (rev 4564) +++ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/GadgetHelper.py 2009-04-20 14:09:29 UTC (rev 4565) @@ -1,94 +0,0 @@ -# Copyright (C) 2009 C2ME Sa -# Remi Jocaille <rem...@c2...> -# Distributed under the terms of the GNU General Public License -# http://www.gnu.org/copyleft/gpl.html - -import sys -import traceback -import platform - -# ------------------------------------------------------------------------------ -# This class is the minimal helper for builder python gadgets. -# It's an alternative to the SimpleGadget helper. -# ------------------------------------------------------------------------------ -class GadgetHelper(object): - """This class is the minimal helper for builder python gadgets. - It's an alternative to the SimpleGadget helper. - """ - - # -------------------------------------------------------------------------- - # Get if the platform is Windows or not. - # -------------------------------------------------------------------------- - def isWindows(): - """Get if the platform is Windows or not. - @return: A boolean. - """ - platformName = platform.system().lower() - return (platformName == "microsoft") or (platformName == "windows") - - # -------------------------------------------------------------------------- - # Throw a generic notification to the framework. - # -------------------------------------------------------------------------- - def throwNotification(messageId, *args): - """Throw a generic notification to the framework. - @param messageId: Message Id. - @param args: List of objects. - """ - stringBuffer = messageId - for arg in args: - stringBuffer += " '" - stringBuffer += str(arg).replace("'", "\\'") - stringBuffer += "'" - sys.stdout.write(stringBuffer + "\n") - sys.stdout.flush() - - # -------------------------------------------------------------------------- - # Throw a message to the framework. - # -------------------------------------------------------------------------- - def throwMessage(content, *args): - """Throw a message to the framework. - @param content: Content of the message. - @param args: Arguments for the message. - """ - tmp = [content,] - for arg in args: - tmp.append(arg) - GadgetHelper.throwNotification("message", *tmp) - - # -------------------------------------------------------------------------- - # Throw a trace message to the framework. - # -------------------------------------------------------------------------- - def throwTrace(message): - """Throw a trace message to the framework. - @param message: Throwed message. - """ - GadgetHelper.throwNotification("trace", message) - - # -------------------------------------------------------------------------- - # Throw an error message to the framework. - # -------------------------------------------------------------------------- - def throwError(message, sendTraceback = False): - """Throw an error message to the framework. - @param message: Thowed message if the gadget don't want to be traced. - @param sendTraceback: For to send the traceback. Default False. - """ - def formatException(): - fList = traceback.format_exception(sys.exc_info()[0], - sys.exc_info()[1], - sys.exc_info()[2]) - result = "" - for line in fList: - result += line - return result - messagesList = [message,] - if sendTraceback: - tmpList = formatException().split("\n") - for line in tmpList: - messagesList.append(line) - GadgetHelper.throwNotification("error", *messagesList) - - isWindows = staticmethod(isWindows) - throwNotification = staticmethod(throwNotification) - throwMessage = staticmethod(throwMessage) - throwTrace = staticmethod(throwTrace) - throwError = staticmethod(throwError) Modified: softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/tuxdroid-gadget-skype.py =================================================================== --- softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/tuxdroid-gadget-skype.py 2009-04-20 13:00:24 UTC (rev 4564) +++ softwares_suite_v3/community/gadget/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/tuxdroid-gadget-skype.py 2009-04-20 14:09:29 UTC (rev 4565) @@ -1,268 +1,266 @@ -''' -This file is part of "tuxdroid-gadget-skype". - * Copyright 2008, kysoh - * Author : Conan Jerome - * eMail : jer...@ky... - * Site : http://www.kysoh.com/ - * - * "tuxdroid-gadget-skype " is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * "tuxdroid-gadget-skype" 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with "tuxdroid-gadget-skype"; if not, write to the Free - * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA - * 02110-1301 USA, or see the FSF site: http://www.fsf.org. - */ - ''' +# -*- coding: utf-8 -*- -import platform -import Skype4Py -import commands -import threading -import time +# Copyright (C) 2009 Kysoh Sa +# Conan Jerome <jer...@ky...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +__author__ = "Conan Jerome" +__appname__ = "Python gadget skype" +__version__ = "0.2" +__date__ = "2009/04/15" +__license__ = "GPL" + import os +import time +import sys +import threading import subprocess +import Skype4Py from tuxisalive.api.TuxAPI import * -from GadgetHelper import GadgetHelper +sys.path.append(os.environ['TUXDROID_SERVER_PYTHON_UTIL']) -class Connection(object): - ''' - This class manage skype connection. - ''' +from util.SimpleGadget.SimpleGadgetConfiguration import SimpleGadgetConfiguration +from util.SimpleGadget.SimpleGadget import SimpleGadget - #Private global vars. - __currentCall = None - __tux = None - __currentContactIndex = -1 - __contactsDict = {} - __contactsList = [] - __allowedStatus = { - "Online" : Skype4Py.olsOnline, - "Away" : Skype4Py.olsAway, - "Do not disturb" : Skype4Py.olsDoNotDisturb, - "Invisible" : Skype4Py.olsInvisible, - "Busy" : Skype4Py.olsNotAvailable, - "Skype me": Skype4Py.olsSkypeMe - } - - __mutexNext = threading.Lock() - __mutexPrev = threading.Lock() - __mutexCall = threading.Lock() - - #Skype api objects. - __skype = None - __apiAttachState = -1 - __activeMain = True - - #registered events. - __okEventID = None - __headEventID = None - __leftWingEvent = None - __rightWingEvent = None - __leftArrowEvent = None - __rightArrowEvent = None - __greenPhoneEvent = None - __redPhoneEvent = None +class Configuration(SimpleGadgetConfiguration): + """This class make an access to the gadget parameters. + Parameters are automatically filled by the SimpleGadget class at gadget + starting. + """ - #Users gadget parameters. - speaker = "Ryan" - pitch = 120 - ip = "127.0.0.1" - status = None - quitSkype = False - quitGadget = True - - - #Geting right gadget parameters. - if "tgp_ip" in os.environ: - ip = os.environ["tgp_ip"] - if "tgp_locutor" in os.environ: - speaker = os.environ["tgp_locutor"] - if "tgp_pitch" in os.environ: - pitch = int(os.environ["tgp_pitch"]) - if "tgp_quitSkype" in os.environ: - quitSkype = (os.environ["tgp_quitSkype"] == "true") - if "tgp_quitGadget" in os.environ: - quitGadget = (os.environ["tgp_quitGadget"] == "true") - if "tgp_startupStatus" in os.environ: - status = os.environ["tgp_startupStatus"] - + def __init__(self): + """Initialization of the class. + """ + # Call the super class + SimpleGadgetConfiguration.__init__(self) + # Initialize the parameters + self.__quitSkype = False + self.__quitGadget = False + self.__startupStatus = "" + def getQuitSkype(self): + return self.__quitSkype - def __init__(self): - ''' - Constructor - ''' - print("Debug: connecting") - - self.__tux = TuxAPI(self.ip, 270) - self.__tux.server.autoConnect(CLIENT_LEVEL_FREE, "SkypeGadget", "tuxdroid-gadget-skype") - self.__tux.server.waitConnected(3.0) - self.__tux.access.waitAcquire(3.0, ACCESS_PRIORITY_NORMAL) - - try: - #Start Skype client if not started. - self.__startSkype() - if not self.__activeMain: - self.__destroy() - #Connect to skype api. - self.__connectSkypeAPI() - except: - GadgetHelper.throwMessage("I cannot get connected to your Skeyepe. Please, check if you are connected. And verify if I can access skeyepe.") - self.__destroy() - - - - def __destroy(self): - ''' - Destroy current connection object. - ''' - try: - if self.__skype != None: - self.__resetTuxMotors() - self.__skype._API.Close() - self.__skype = None - self.__apiAttachState = -1 - - if self.__tux != None: - self.__tux.led.both.off() - self.__tux.led.both.on() - self.__resetTuxMotors() - self.__tux.access.release() - self.__tux.server.disconnect() - self.__tux.destroy() - - self.__activeMain = False - except: - pass - - - - def __initSkypeGadget(self): - ''' - Initialize the skype gadget when skype api is connected. - ''' - #Set tux as audio card. - self.__setTuxAudio() - - #Set the user status. - if self.__allowedStatus.has_key(self.status): - self.__skype._SetCurrentUserStatus(self.__allowedStatus[self.status]) - - #et the contacts list. - self.__getContacts() + def setQuitSkype(self, quitSkype): + self.__quitSkype = quitSkype + def getQuitGadget(self): + return self.__quitGadget + def setQuitGadget(self, quitGadget): + self.__quitGadget = quitGadget - def __initTuxCallbacks(self): - ''' - Init the Tux Droid callbacks - ''' - #Tux Droid switches. - self.__leftWingEvent = self.__tux.button.left.registerEventOnPressed(self.onLeftButtonPushed) - self.__rightWingEvent = self.__tux.button.right.registerEventOnPressed(self.onRightButonPushed) - self.__headEventID = self.__tux.button.head.registerEventOnReleased(self.onHeadButtonPushed) - #Remote control. - self.__tux.button.remote.registerEventOnPressed(self.onStandbyRemoteButtonPushed, K_STANDBY) - self.__leftArrowEvent = self.__tux.button.remote.registerEventOnPressed(self.onLeftButtonPushed, K_DOWN) - self.__rightArrowEvent = self.__tux.button.remote.registerEventOnPressed(self.onRightButonPushed, K_UP) - self.__okEventID = self.__tux.button.remote.registerEventOnPressed(self.onHeadButtonPushed, K_OK) - self.__greenPhoneEvent = self.__tux.button.remote.registerEventOnPressed(self.onHeadButtonPushed, K_RECEIVECALL) - self.__redPhoneEvent = self.__tux.button.remote.registerEventOnPressed(self.onFinishCall, K_HANGUP) + def getStartupStatus(self): + return self.__startupStatus + def setStartupStatus(self, startupStatus): + self.__startupStatus = startupStatus -######################################################### -######### private functions ######## +class SkypeGadget(SimpleGadget): + """Skype gadget class. + """ - def onLeftButtonPushed(self, value, delay): - ''' - On left switch / remote event. - ''' - thread = threading.Thread(target = self.nextContact, args = []) - thread.start() + def __init__(self): + """Initialization of the class. + """ + # Call the super class + SimpleGadget.__init__(self) + # Initialize some values ... + self.__currentCall = None + self.__tux = None + self.__currentContactIndex = -1 + self.__contactsDict = {} + self.__contactsList = [] + self.__allowedStatus = { + "Online" : Skype4Py.olsOnline, + "Away" : Skype4Py.olsAway, + "Do not disturb" : Skype4Py.olsDoNotDisturb, + "Invisible" : Skype4Py.olsInvisible, + "Busy" : Skype4Py.olsNotAvailable, + "Skype me": Skype4Py.olsSkypeMe, + } + self.__mutexNext = threading.Lock() + self.__mutexPrev = threading.Lock() + self.__mutexCall = threading.Lock() + # Skype api objects. + self.__skype = None + self.__apiAttachState = -1 + self.__activeMain = True + # Registered events. + self.__okEventID = None + self.__headEventID = None + self.__leftWingEvent = None + self.__rightWingEvent = None + self.__leftArrowEvent = None + self.__rightArrowEvent = None + self.__greenPhoneEvent = None + self.__redPhoneEvent = None + # Skype process + self.__skypeProcess = None + def start(self): + """Gadget entry point. + This method should be used to dispatch commands. + """ + if self.getCommand() == "run": + self.run() + else: + self.run() + def run(self): + """Gadget entry point for the "run" command. + """ + self.__tux = TuxAPI("127.0.0.1", 270) + self.__tux.server.autoConnect(CLIENT_LEVEL_FREE, "SkypeGadget", + "tuxdroid-gadget-skype") + self.__tux.server.waitConnected(3.0) + try: + # Start Skype client if not started. + self.__startSkype() + if not self.__activeMain: + self.stop() + return + # Connect to skype api. + self.__connectSkypeAPI() + except: + self.throwMessage("I cannot get connected to your Skeyepe. Please, check if you are connected. And verify if I can access skeyepe.") + self.stop() - def onRightButonPushed(self, value, delay): - ''' - On right switch / remote event. - ''' - thread = threading.Thread(target = self.previousContact, args = []) - thread.start() + def onGadgetStop(self): + """Callback on gadget stop. + """ + def closeSkype(): + if self.__skype != None: + self.__activeMain = False + self.__skype._API.Close() + self.__skype = None + self.__apiAttachState = -1 + if self.__skypeProcess != None: + if self.isWindows(): + import win32api + try: + win32api.TerminateProcess(int( + self.__skypeProcess._handle), -1) + except: + pass + else: + os.system("kill -9 " + str(self.__skypeProcess.pid)) + try: + if self.__skype != None: + self.__setCallFinished() + if self.__skypeProcess != None: + closeSkype() + if self.__tux != None: + self.__tux.led.both.off() + self.__tux.led.both.on() + self.__resetTuxMotors() + self.__tux.server.disconnect() + self.__tux.destroy() + except: + pass + def __initSkypeGadget(self): + """Initialize the skype gadget when skype api is connected. + """ + # Set tux as audio card. + self.__setTuxAudio() + # Set the user status. + status = self.configuration().getStartupStatus() + if self.__allowedStatus.has_key(status): + self.__skype._SetCurrentUserStatus(self.__allowedStatus[status]) + # Get the contacts list. + self.__getContacts() + def __initTuxCallbacks(self): + """Init the Tux Droid callbacks + """ + # Tux Droid switches. + self.__leftWingEvent = self.__tux.button.left.registerEventOnPressed( + self.__onLeftButtonPushed) + self.__rightWingEvent = self.__tux.button.right.registerEventOnPressed( + self.__onRightButonPushed) + self.__headEventID = self.__tux.button.head.registerEventOnReleased( + self.__onHeadButtonPushed) + # Remote control. + self.__tux.button.remote.registerEventOnPressed( + self.__onStandbyRemoteButtonPushed, K_STANDBY) + self.__leftArrowEvent = self.__tux.button.remote.registerEventOnPressed( + self.__onLeftButtonPushed, K_DOWN) + self.__rightArrowEvent = self.__tux.button.remote.registerEventOnPressed( + self.__onRightButonPushed, K_UP) + self.__okEventID = self.__tux.button.remote.registerEventOnPressed( + self.__onHeadButtonPushed, K_OK) + self.__greenPhoneEvent = self.__tux.button.remote.registerEventOnPressed( + self.__onHeadButtonPushed, K_RECEIVECALL) + self.__redPhoneEvent = self.__tux.button.remote.registerEventOnPressed( + self.__onFinishCall, K_HANGUP) - def onHeadButtonPushed(self, value, delay): - ''' - On head / remote event. - ''' - print(delay) - if delay > 0.8: - thread = threading.Thread(target = self.setCall, args = [self.__contactsList[self.__currentContactIndex], ]) - thread.start() - - - def onFinishCall(self, value, delay): - ''' - Finish call event ( remote control ). - ''' - thread = threading.Thread(target= self.setCallFinished, args = []) - thread.start() + def __onLeftButtonPushed(self, value, delay): + """On left switch / remote event. + """ + thread = threading.Thread(target = self.nextContact) + thread.start() - - def onStandbyRemoteButtonPushed(self, value, delay): - ''' - On standby remote button pushed : quit the script. - ''' - thread = threading.Thread(target = self.quitMainloop, args = []) + def __onRightButonPushed(self, value, delay): + """On right switch / remote event. + """ + thread = threading.Thread(target = self.previousContact) thread.start() + def __onHeadButtonPushed(self, value, delay): + """On head / remote event. + """ + if delay > 0.2: + thread = threading.Thread(target = self.setCall, + args = (self.__contactsList[self.__currentContactIndex],)) + thread.start() + def __onFinishCall(self, value, delay): + """Finish call event ( remote control ). + """ + thread = threading.Thread(target= self.setCallFinished) + thread.start() + def __onStandbyRemoteButtonPushed(self, value, delay): + """On standby remote button pushed : quit the script. + """ + thread = threading.Thread(target = self.quitMainloop) + thread.start() - def skypeApplicationAPIStatusReceived(self, value): - ''' - Received api connection status. - ''' + def __skypeApplicationAPIStatusReceived(self, value): + """Received api connection status. + """ self.__apiAttachState = value - - - def __setTuxAudio(self): - ''' - Set tux as audio peripheral. - ''' - #from SkypeConnection import Utils - if self.isWindows(): - self.__sendCommand('SET AUDIO_IN TuxDroid-Micro (TuxDroid-Audio)') - self.__sendCommand('SET AUDIO_OUT Speakers (TuxDroid-Audio)') - self.__sendCommand('SET RINGER Speakers (TuxDroid-Audio)') - else: + def __setTuxAudio(self): + """Set tux as audio peripheral. + """ + if self.isWindows(): + import platform + if int(platform.version().split(".")[0]) >= 6: + self.__sendCommand('SET AUDIO_IN TuxDroid-Micro (TuxDroid-Audio)') + self.__sendCommand('SET AUDIO_OUT Speakers (TuxDroid-Audio)') + self.__sendCommand('SET RINGER Speakers (TuxDroid-Audio)') + else: + self.__sendCommand('SET AUDIO_IN TuxDroid-Audio') + self.__sendCommand('SET AUDIO_OUT TuxDroid-Audio') + self.__sendCommand('SET RINGER TuxDroid-Audio') + else: self.__sendCommand('SET AUDIO_IN TuxDroid (plughw:TuxDroid,0)') self.__sendCommand('SET AUDIO_OUT TuxDroid (plughw:TuxDroid,0)') self.__sendCommand('SET RINGER TuxDroid (plughw:TuxDroid,0)') - - - def __sendCommand(self, command): - ''' - Send a raw command to skype api. Return true if command was sent. - ''' + def __sendCommand(self, command): + """Send a raw command to skype api. Return true if command was sent. + """ if self.__getConnected(): try: - cmd_obj = self.__skype.Command( command, Block=True ) - - self.__skype.SendCommand( cmd_obj ) + cmd_obj = self.__skype.Command(command, Block = True) + self.__skype.SendCommand(cmd_obj) result = str((cmd_obj.Reply).encode('utf-8')) return True except: @@ -270,369 +268,280 @@ else: return False - - - def __getPlatform(self): - ''' - Return the plateform name of this current computer. - ''' - return platform.system() + def __connectSkypeAPI(self): + """Get connected to the Skype client. + """ + self.__skype = Skype4Py.Skype() + self.__skype.Timeout = 20000 + self.__skype.OnAttachmentStatus = self.__skypeApplicationAPIStatusReceived + self.__setSkypeCallBacks() + self.__skype.Attach() + self.__initSkypeGadget() + self.__initTuxCallbacks() + def __getSkypeConnected(self): + """Check for skype connection + """ + if not self.isWindows(): + return len(commands.getoutput("ps -A | grep skype")) > 0 + else: + cmd = ["tasklist", "/FI", "IMAGENAME eq skype.exe"] + process = subprocess.Popen(cmd, stdin = subprocess.PIPE, + stdout = subprocess.PIPE) + value = process.stdout.read() + value = value.split() + return ("skype.exe" in value) or ("Skype.exe" in value) - def isWindows(self): - ''' - Return true if plateform is windows. - ''' - platform = self.__getPlatform() - return (platform == 'Windows' ) or (platform == 'windows') or (platform == "Microsoft") - - - def __connectSkypeAPI(self): - ''' - Get connected to the Skype client. - ''' - self.__skype = Skype4Py.Skype() - self.__skype.Timeout = 20000 - self.__skype.OnAttachmentStatus = self.skypeApplicationAPIStatusReceived - self.__setSkypeCallBacks() - self.__skype.Attach() - self.__initSkypeGadget() - self.__initTuxCallbacks() - print("Debug: connected") - - - - def __getSkypeConnected(self): - """ - Check for skype connection - """ - if not self.isWindows(): - return len(commands.getoutput("ps -A | grep skype")) > 0 - else: - cmd = ["tasklist", "/FI", "IMAGENAME eq skype.exe"] - process = subprocess.Popen(cmd, stdin = subprocess.PIPE, stdout = subprocess.PIPE) - value = process.stdout.read() - value = value.split() - return ("skype.exe" in value) or ("Skype.exe" in value) - - - - def __startSkype(self): - ''' - This function starts skype. - ''' - #Return if skype is already started. + def __startSkype(self): + """This function starts skype. + """ + # Return if skype is already started. if self.__getSkypeConnected(): return - if self.isWindows(): - thread = threading.Thread(target=self.__startSkypeWindows, args=[]) + thread = threading.Thread(target = self.__startSkypeWindows) thread.start() else: - thread = threading.Thread(target=self.__startSkypeLinux, args=[]) + thread = threading.Thread(target = self.__startSkypeLinux) thread.start() - - - - def __startSkypeWindows(self): - ''' - Start skype on windows. - ''' - - if "ProgramFiles" in os.environ: + + def __startSkypeWindows(self): + """Start skype on windows. + """ + if "ProgramFiles" in os.environ: try: - process = subprocess.Popen(os.environ["ProgramFiles"] + "\\Skype\\Phone\\Skype.exe", stdin=subprocess.PIPE, stdout=subprocess.PIPE) - result = process.stdout.read() + self.__skypeProcess = subprocess.Popen( + os.environ["ProgramFiles"] + "\\Skype\\Phone\\Skype.exe", + stdin = subprocess.PIPE, stdout = subprocess.PIPE) + result = self.__skypeProcess.stdout.read() result.split() - if ("not" in result) and ("recognized" in result) and ("command" in result): - GadgetHelper.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.") + if ("not" in result) and ("recognized" in result) \ + and ("command" in result): + self.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.") self.__activeMain = False except WindowsError: - GadgetHelper.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.") + self.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.") self.__activeMain = False - - - - - def __startSkypeLinux(self): - ''' - Start skype on linux ( thread needed to do not block the script ). - ''' - #Searching for skype binary. - cmd = ["skype", "--version"] - process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) - result = process.stdout.read() - result = result.split() - if("Skype" in result) and ("Copyright" in result): - #Then skype is in PATH - subprocess.Popen("skype", stdin=subprocess.PIPE, stdout=subprocess.PIPE) - else: - GadgetHelper.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.") - self.__activeMain = False - - - - def __getConnected(self): - ''' - Return true if connected. - ''' - return self.__apiAttachState == 0 + def __startSkypeLinux(self): + """Start skype on linux ( thread needed to do not block the script ). + """ + # Searching for skype binary. + cmd = ["skype", "--version"] + process = subprocess.Popen(cmd, stdin = subprocess.PIPE, + stdout = subprocess.PIPE) + result = process.stdout.read() + result = result.split() + if("Skype" in result) and ("Copyright" in result): + # Then skype is in PATH + self.__skypeProcess.Popen("skype", stdin = subprocess.PIPE, + stdout = subprocess.PIPE) + else: + self.throwMessage("Sorry, it looks like skeyepe is not installed. Please go to the skeyepe website to download the software.") + self.__activeMain = False + def __getConnected(self): + """Return true if connected. + """ + return self.__apiAttachState == 0 + def __getContacts(self): + """Return the contact list as list. + """ + self.__contactsList = [] + self.__contactsDict = {} + self.__currentContactIndex = -1 + for user in self.__skype.Friends: + if user.OnlineStatus not in [Skype4Py.olsUnknown, + Skype4Py.olsOffline, Skype4Py.olsInvisible]: + userFNEnc = user.FullName.encode("UTF-8").replace(" ", "_") + userDNEnc = user.DisplayName.encode("UTF-8").replace(" ", "_") + userHEnc = user.Handle.encode("UTF-8").replace(" ", "_") + if len(userFNEnc) > 0: + self.__contactsDict[userFNEnc] = userHEnc + self.__contactsList.append(userFNEnc) + elif len(userDNEnc) > 0: + self.__contactsDict[userDNEnc] = userHEnc + self.__contactsList.append(userDNEnc) + else: + self.__contactsDict[userHEnc] = userHEnc + self.__contactsList.append(userHEnc) + if len(self.__contactsDict) > 0: + self.nextContact() + else: + self.throwMessage("I cannot found online user or registered cell numbers") + self.stop() + return self.__contactsList + def __resetTuxMotors(self, removeEvents = True): + """Reset tux motors. + """ + self.__tux.flippers.down() + self.__tux.mouth.close() + if removeEvents: + self.__removeTuxEvents() - def __getContacts(self): - ''' - Return the contact list as list. - ''' - self.__contactsList = [] - self.__contactsDict = {} - self.__currentContactIndex = -1 - for user in self.__skype.Friends: - if user.OnlineStatus not in [Skype4Py.olsUnknown, Skype4Py.olsOffline, Skype4Py.olsInvisible]: - if len(user.FullName.encode("UTF-8")) > 0: - self.__contactsDict[user.FullName.encode("UTF-8").replace(" ", "_")] = user.Handle.encode("UTF-8") - self.__contactsList.append(user.FullName.encode("UTF-8").replace(" ", "_")) - elif len(user.DisplayName.encode("UTF-8")) > 0: - self.__contactsDict[user.DisplayName.encode("UTF-8").replace(" ", "_")] = user.Handle.encode("UTF-8") - self.__contactsList.append(user.DisplayName.encode("UTF-8").replace(" ", "_")) - else: - self.__contactsDict[user.Handle.encode("UTF-8").replace(" ", "_")] = user.Handle.encode("UTF-8") - self.__contactsList.append(user.Handle.encode("UTF-8").replace(" ", "_")) - - if len(self.__contactsDict) > 0: - self.nextContact() - else: - GadgetHelper.throwMessage("I cannot found online user or registered cell numbers") - self.__destroy() - return self.__contactsList + def __removeTuxEvents(self): + """Remove tux switches and buttons registered events. + """ + # Unregister ok push event + if self.__okEventID != None: + self.__tux.button.remote.unregisterEventOnPressed(self.__okEventID) + # Unregister head button push + if self.__headEventID != None: + self.__tux.button.head.unregisterEventOnReleased(self.__headEventID) + # Unregister left wing event + if self.__leftWingEvent != None: + self.__tux.button.left.unregisterEventOnPressed( + self.__leftWingEvent) + # Unregister right wing event + if self.__rightWingEvent != None: + self.__tux.button.right.unregisterEventOnPressed( + self.__rightWingEvent) + # Unregister left arrow event + if self.__leftArrowEvent != None: + self.__tux.button.remote.unregisterEventOnPressed( + self.__leftArrowEvent) + # Unregister right arrow event + if self.__rightArrowEvent != None: + self.__tux.button.remote.unregisterEventOnPressed( + self.__rightArrowEvent) + # Unregister call callback. + if self.__greenPhoneEvent != None: + self.__tux.button.remote.unregisterEventOnPressed( + self.__greenPhoneEvent) + # Unregister set call finish callback. + if self.__redPhoneEvent != None: + self.__tux.button.remote.unregisterEventOnPressed( + self.__redPhoneEvent) + def __setTuxMotors(self): + """Set tux to get the call. + """ + self.__tux.flippers.up() + self.__tux.mouth.open() + def __onOutgoingCall(self, Call, Status): + """Set outgoing calls functions. + """ + if Status == Skype4Py.clsRinging: + self.__tux.led.both.blinkAsync(SPV_SLOW, 100, LFX_FADE) + if Status in [Skype4Py.clsFinished, Skype4Py.clsCancelled, + Skype4Py.clsRefused, Skype4Py.clsFailed, Skype4Py.clsBusy]: + self.__tux.led.both.off() + self.__tux.led.both.on() + self.__currentCall = None + self.__resetTuxMotors() + if self.configuration().getQuitGadget(): + def async(): + time.sleep(2.0) + self.stop() + t = threading.Thread(target = async) + t.start() + return + self.__initTuxCallbacks() + elif Status in [Skype4Py.clsRinging, Skype4Py.clsEarlyMedia, + Skype4Py.clsRouting, Skype4Py.clsInProgress, Skype4Py.clsUnplaced]: + if Status in [Skype4Py.clsInProgress, Skype4Py.clsUnplaced]: + self.__tux.led.both.off() + self.__tux.led.both.on() + self.__currentCall = Call + self.__removeTuxEvents() + self.__setTuxMotors() + self.__okEventID = self.__tux.button.remote.registerEventOnPressed( + self.__setCallFinished, K_OK) + self.__headEventID = self.__tux.button.head.registerEventOnReleased( + self.__headCallFinish) + self.__redPhoneEvent = self.__tux.button.remote.registerEventOnPressed( + self.__onFinishCall, K_HANGUP) -######################################################### -######### callbacks ############### + def __onSkypeCall(self, Call, Status): + """Set calls callback. + """ + if (Call.Type == Skype4Py.cltOutgoingP2P) or \ + (Call.Type == Skype4Py.cltOutgoingPSTN): + self.__onOutgoingCall(Call, Status) + elif (Call.Type == Skype4Py.cltIncomingP2P) or \ + (Call.Type == Skype4Py.cltIncomingPSTN): + Call.Finish() + def __setSkypeCallBacks(self): + """Set all needed Skype callback. + """ + # The only used caallback for now is the skype call event. + self.__skype.OnCallStatus = self.__onSkypeCall - def __resetTuxMotors(self, removeEvents=True): - ''' - Reset tux motors. - ''' - self.__tux.flippers.down() - self.__tux.mouth.close() - - if removeEvents: - self.__removeTuxEvents() - - - def __removeTuxEvents(self): - ''' - Remove tux switches and buttons registered events. - ''' - #unregister ok push event - if self.__okEventID != None: - self.__tux.button.remote.unregisterEventOnPressed(self.__okEventID) - - #unregister head button push - if self.__headEventID != None: - self.__tux.button.head.unregisterEventOnReleased(self.__headEventID) - - #unregister left wing event - if self.__leftWingEvent != None: - self.__tux.button.left.unregisterEventOnPressed(self.__leftWingEvent) - - #unregister right wing event - if self.__rightWingEvent != None: - self.__tux.button.right.unregisterEventOnPressed(self.__rightWingEvent) - - #unregister left arrow event - if self.__leftArrowEvent != None: - self.__tux.button.remote.unregisterEventOnPressed(self.__leftArrowEvent) - - #unregister right arrow event - if self.__rightArrowEvent != None: - self.__tux.button.remote.unregisterEventOnPressed(self.__rightArrowEvent) - - #Unregister call callback. - if self.__greenPhoneEvent != None: - self.__tux.button.remote.unregisterEventOnPressed(self.__greenPhoneEvent) - - #Unregister set call finish callback. - if self.__redPhoneEvent != None: - self.__tux.button.remote.unregisterEventOnPressed(self.__redPhoneEvent) - + def setCall(self, contact): + """Call a specified contact. + """ + self.__mutexCall.acquire() + # Get skype name + callName = self.__contactsDict.get(contact) + # Place call + if (callName != None) and (self.__currentCall == None): + self.__currentCall = self.__skype.PlaceCall(callName) + self.__mutexCall.release() + def __headCallFinish(self, *args): + """Finish a call from head button. + """ + value, delay = args + if delay > 0.2: + self.__setCallFinished() - def __setTuxMotors(self): - ''' - Set tux to get the call. - ''' - self.__tux.flippers.up() - self.__tux.mouth.open() + def __setCallFinished(self, *args): + """Finish all placed calls. + """ + self.__mutexCall.acquire() + if self.__currentCall != None: + try: + self.__currentCall.Finish() + self.__currentCall = None + except: + self.__currentCall.Resume() + self.__currentCal = None + self.__mutexCall.release() + def nextContact(self): + """Return the next user skype full name. + """ + self.__mutexNext.acquire() + if self.__currentContactIndex >= len(self.__contactsList) -1: + self.__currentContactIndex = -1 + self.__currentContactIndex += 1 + user = self.__contactsList[self.__currentContactIndex] + # Format string that will be sent to the tts. + user = user.replace("_", " ").replace("@", " ") + self.__mutexNext.release() + self.__tux.tts.speak(user, self.configuration().getLocutor(), + self.configuration().getPitch()) + def previousContact(self): + """Return the previous user skype full name. + """ + self.__mutexPrev.acquire() + if self.__currentContactIndex <= 0: + self.__currentContactIndex = len(self.__contactsList) + self.__currentContactIndex -= 1 + user = self.__contactsList[self.__currentContactIndex] + # Format string that will sent to the tts. + user = user.replace("_", " ").replace("@", " ") + self.__mutexPrev.release() + self.__tux.tts.speak(user, self.configuration().getLocutor(), + self.configuration().getPitch()) - def __onOutgoingCall(self, Call, Status): - ''' - Set outgoing calls functions. - ''' - if Status == Skype4Py.clsRinging: - self.__tux.led.both.blinkAsync(SPV_SLOW, 100, LFX_FADE) - - - if Status in [Skype4Py.clsFinished, Skype4Py.clsCancelled, Skype4Py.clsRefused, Skype4Py.clsFailed, Skype4Py.clsBusy]: - self.__tux.led.both.off() - self.__tux.led.both.on() - self.__currentCall = None - self.__resetTuxMotors() - - #Parameter defined by user.cusLoggedOut - if bool(self.quitSkype) : - self.__skype.Client.Shutdown() - self.__destroy() - - if bool(self.quitGadget): - self.__destroy() - - self.__initTuxCallbacks() - - - - elif Status in [Skype4Py.clsRinging, Skype4Py.clsEarlyMedia, Skype4Py.clsRouting, Skype4Py.clsInProgress, Skype4Py.clsUnplaced]: - if Status in [Skype4Py.clsInProgress, Skype4Py.clsUnplaced]: - self.__tux.led.both.off() - self.__tux.led.both.on() - self.__currentCall = Call - self.__removeTuxEvents() - self.__setTuxMotors() - self.__okEventID = self.__tux.button.remote.registerEventOnPressed(self.setCallFinished, K_OK) - self.__headEventID = self.__tux.button.head.registerEventOnReleased(self.headCallFinish) - self.__redPhoneEvent = self.__tux.button.remote.registerEventOnPressed(self.onFinishCall, K_HANGUP) - - - - - def __onSkypeCall(self, Call, Status): - ''' - Set calls callback. - ''' - if (Call.Type == Skype4Py.cltOutgoingP2P) or (Call.Type == Skype4Py.cltOutgoingPSTN): - self.__onOutgoingCall(Call, Status) - elif(Call.Type == Skype4Py.cltIncomingP2P) or (Call.Type == Skype4Py.cltIncomingPSTN): - Call.Finish() - - - - - def __setSkypeCallBacks(self): - ''' - Set all needed Skype callback. - ''' - #The only used caallback for now is the skype call event. - self.__skype.OnCallStatus = self.__onSkypeCall - - -############################################################################# -##################### Users functions #################################### - - def setCall(self, contact): - ''' - Call a specified contact. - ''' - self.__mutexCall.acquire() - #Get skype name - callName = self.__contactsDict.get(contact) - #Place call - if (callName != None) and (self.__currentCall == None): - self.__currentCall = self.__skype.PlaceCall(... [truncated message content] |