[tuxdroid-svn] r5989 - software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/execut
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-12-16 10:58:42
|
Author: jerome
Date: 2009-12-16 11:58:27 +0100 (Wed, 16 Dec 2009)
New Revision: 5989
Modified:
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/communicator.py
Log:
* Applied new comments guideline.
* Added some comments for incoming and outgoing calls events.
Modified: software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/communicator.py
===================================================================
--- software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/communicator.py 2009-12-16 10:25:43 UTC (rev 5988)
+++ software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/communicator.py 2009-12-16 10:58:27 UTC (rev 5989)
@@ -30,11 +30,13 @@
from EmoticonsToAttitunes import EMOTICONS_TO_ATTITUNES
from errors import EquipmentException, UnavailableContactException, UserNotFindException
-
+
+# ==============================================================================
+# Declaration of the "SynchroniousCommands" object.
+# ==============================================================================
class SynchroniousCommands(object):
+ '''Handle skype synchronious commands.
'''
- Handle skype synchronious commands.
- '''
connectionObj = None
currentUser = None
@@ -62,38 +64,37 @@
#List available offline statuses.
contacts_ofs = [u'UNKNOWN', u'OFFLINE', u'INVISIBLE']
-
-###################################################
-####### Private functions ############
+ # ==========================================================================
+ # Private functions
+ # ==========================================================================
+ # --------------------------------------------------------------------------
+ # Init procedure.
+ # --------------------------------------------------------------------------
def __init__(self, Connector):
+ '''Init procedure.
'''
- Init procedure.
- '''
self.connectionObj = Connector
-
#Updating audio cards values.
- if os.name == 'nt':
- self.IN = AudioUtils.getSoundDeviceNameTuxdroidMicro()
- self.OUT = AudioUtils.getSoundDeviceNameTuxdroidAudio()
- self.RINGER = self.OUT
-
+ self.IN = AudioUtils.getSoundDeviceNameTuxdroidMicro()
+ self.OUT = AudioUtils.getSoundDeviceNameTuxdroidAudio()
+ self.RINGER = self.OUT
#Getting current user.
try:
self.currentUser = connectionObj.getSkypeAPI().CurrentUser
except:
self.currentUser = 'default'
-
+ # --------------------------------------------------------------------------
+ # Set Tux Droid as audio card for Skype client.
+ # --------------------------------------------------------------------------
def __set_tux_in_out__(self):
+ '''Set Tux Droid as audio card for Skype client.
'''
- Set Tux Droid as audio card for Skype client.
- '''
try:
self.connectionObj.getSkypeAPI().Settings.AudioIn = self.IN
self.connectionObj.getSkypeAPI().Settings.AudioOut = self.OUT
self.connectionObj.getSkypeAPI().Settings.Ringer = self.RINGER
-
time.sleep(1.0)
#Checking if Tux Droid was successfully set as audio card.
if self.isTuxDroidAudioCard():
@@ -103,11 +104,12 @@
#Return False, maybe Tux Droid is not connected.
return False
-
+ # --------------------------------------------------------------------------
+ # Return true if Tux Droid is set as audio card.
+ # --------------------------------------------------------------------------
def __is_tux_audio__(self):
+ '''Return true if Tux Droid is set as audio card.
'''
- Return true if Tux Droid is set as audio card.
- '''
if not ( self.connectionObj.getSkypeAPI().Settings.AudioIn == self.IN ):
return False
if not ( self.connectionObj.getSkypeAPI().Settings.AudioOut == self.OUT ):
@@ -117,12 +119,12 @@
return True
-
-
+ # --------------------------------------------------------------------------
+ # Querry client api to fetch contact list.
+ # --------------------------------------------------------------------------
def __fetch_contacts__(self):
+ '''Querry client api to fetch contact list.
'''
- Querry client api to fetch contact list.
- '''
if self.currentUser != self.connectionObj.getSkypeAPI().CurrentUser:
self.contacts = []
@@ -157,10 +159,11 @@
self.connectionObj.releaseSkypeLock()
return self.contacts
-
+ # --------------------------------------------------------------------------
+ # Return the 'name' value of a user for tts use.
+ # --------------------------------------------------------------------------
def __get_user_tts__(self, handle):
- '''
- Return the 'name' value of a user for tts use.
+ '''Return the 'name' value of a user for tts use.
@Param : User skype name.
'''
for user in self.contacts:
@@ -168,23 +171,23 @@
return user['name']
return None
-
-
+ # --------------------------------------------------------------------------
+ # Return the user handle for a tts name.
+ # --------------------------------------------------------------------------
def __get_user_handle__(self, ttsName):
+ '''Return the user handle for a tts name.
'''
- Return the user handle for a tts name.
- '''
for user in self.contacts:
if tounicode(ttsName) == tounicode(user['ttsName']):
return user['handle']
return None
-
-
+ # --------------------------------------------------------------------------
+ # Return a tts name online list
+ # --------------------------------------------------------------------------
def __get_online_list__(self):
+ '''Return a tts name online list
'''
- Return a tts name online list
- '''
online = []
for user in self.contacts:
try:
@@ -200,10 +203,11 @@
return sorted(online)
-
+ # --------------------------------------------------------------------------
+ # Proceed to call a contact.
+ # --------------------------------------------------------------------------
def __call_contact__(self, ttsName):
- '''
- Proceed to call a contact.
+ '''Proceed to call a contact.
Raise equipement error
Raise unavailable contact error
'''
@@ -228,27 +232,29 @@
#User has no equipment, exiting.
raise EquipmentException()
-
+ # --------------------------------------------------------------------------
+ # Finish inprogress call.
+ # --------------------------------------------------------------------------
def __finish_call__(self):
+ '''Finish inprogress call.
'''
- Finish inprogress call.
- '''
for aCall in self.connectionObj.getSkypeAPI().ActiveCalls:
aCall.Finish()
-
+ # --------------------------------------------------------------------------
+ # Place a call in progress.
+ # --------------------------------------------------------------------------
def __get_call__(self, Call):
+ '''Place a call in progress.
'''
- Place a call in progress.
- '''
Call.Answer()
-
-
+ # --------------------------------------------------------------------------
+ # Add a user into the contacts list.
+ # --------------------------------------------------------------------------
def __user_add__(self, handle):
+ '''Add a user into the contacts list.
'''
- Add a user into the contacts list.
- '''
user = None
try:
@@ -274,12 +280,12 @@
#User was not find
raise UserNotFindException()
-
-
+ # --------------------------------------------------------------------------
+ # Remove a user from the contacts list.
+ # --------------------------------------------------------------------------
def __user_del__(self, handle):
+ '''Remove a user from the contacts list.
'''
- remove a user from the contacts list.
- '''
user = None
try:
@@ -291,13 +297,13 @@
self.contacts.remove( user )
except Excetion, e:
raise UserNotFindException
-
-
-
+
+ # --------------------------------------------------------------------------
+ # Return true if tts username is in the contacts list.
+ # --------------------------------------------------------------------------
def __is_valid_contact__(self, ttsName):
+ '''Return true if tts username is in the contacts list.
'''
- Return true if tts username is in the contacts list.
- '''
try:
for user in self.contacts:
if tounicode(user['name']) == tounicode(ttsName):
@@ -306,11 +312,12 @@
except:
pass
-
+ # --------------------------------------------------------------------------
+ # Change the user status.
+ # --------------------------------------------------------------------------
def __set_online_status__(self, status):
+ '''Change the user status.
'''
- Change the user status.
- '''
try:
if ( status in self.contacts_ols ) or ( status in self.contacts_ofs):
#if status allowed then updating.
@@ -318,10 +325,11 @@
except:
pass
-
+ # --------------------------------------------------------------------------
+ # Send a message to the user handle.
+ # --------------------------------------------------------------------------
def __send_message__(self, handle, text):
- '''
- Send a message to the user handle.
+ '''Send a message to the user handle.
Return true if success, false otherwise.
'''
try:
@@ -333,195 +341,214 @@
except:
return False
-
-
-###################################################
-####### User functions ############
+ # ==========================================================================
+ # Public functions
+ # ==========================================================================
+ # --------------------------------------------------------------------------
+ # Return the current Skype user.
+ # --------------------------------------------------------------------------
def getCurrentUser(self):
+ '''Return the current Skype user.
'''
- Return the current Skype user.
- '''
return self.currentUser
-
+ # --------------------------------------------------------------------------
+ # Fetch user contact list.
+ # --------------------------------------------------------------------------
def getContacts(self):
+ '''Fetch user contact list.
'''
- Fetch user contact list.
- '''
return self.__fetch_contacts__()
-
+ # --------------------------------------------------------------------------
+ # Return true if Tux Droid is set as audio card.
+ # --------------------------------------------------------------------------
def isTuxDroidAudioCard(self):
+ '''Return true if Tux Droid is set as audio card.
'''
- Return true if Tux Droid is set as audio card.
- '''
return self.__is_tux_audio__()
-
+ # --------------------------------------------------------------------------
+ # Set Tux Droid as audio card for Skype client.
+ # --------------------------------------------------------------------------
def setAudioCards(self):
+ '''Set Tux Droid as audio card for Skype client.
'''
- Set Tux Droid as audio card for Skype client.
- '''
self.__set_tux_in_out__()
-
+ # --------------------------------------------------------------------------
+ # Return the tts name for this user handle.
+ # --------------------------------------------------------------------------
def getTTSName(self, user):
+ '''Return the tts name for this user handle.
'''
- Return the tts name for this user handle.
- '''
return self.__get_user_tts__(user)
-
+ # --------------------------------------------------------------------------
+ # Return the handle of a user.
+ # --------------------------------------------------------------------------
def getHandle(self, ttsName):
+ '''Return the handle of a user.
'''
- Return the handle os a user.
- '''
return self.__get_user_handle__(ttsName)
-
+ # --------------------------------------------------------------------------
+ # Return a complete online / skypeout user list.
+ # --------------------------------------------------------------------------
def getOnlineList(self):
+ '''Return a complete online / skypeout user list.
'''
- Return a complete online / skypeout user list.
- '''
return self.__get_online_list__()
-
+ # --------------------------------------------------------------------------
+ # Place a call.
+ # --------------------------------------------------------------------------
def call(self, ttsName):
- '''
- Place a call.
+ '''Place a call.
Raise 'EquimentException' and 'UnavailableContactException'
'''
self.__call_contact__(ttsName)
-
+ # --------------------------------------------------------------------------
+ # In case of add user skype event ( not used for now )
+ # --------------------------------------------------------------------------
def adduser(self, userHandle):
''' ( in case of add user skype event )
'''
self.__user_add__(userHandle)
-
+ # --------------------------------------------------------------------------
+ # In case of removed user skype event ( not used for now )
+ # --------------------------------------------------------------------------
def deluser(self, userHandle):
''' ( in case of remove user skype event )
'''
self.__user_del__(userHandle)
-
+ # --------------------------------------------------------------------------
+ # Check if a user is in the contact list.
+ # --------------------------------------------------------------------------
def isUserInList(self, ttsName):
+ '''Check if a user is in the contact list.
'''
- Check if a user is in the contact list.
- '''
return self.__is_valid_contact__(ttsName)
-
+ # --------------------------------------------------------------------------
+ # Finish a call.
+ # --------------------------------------------------------------------------
def finishCall(self):
+ '''Finish a call.
'''
- Finish a call.
- '''
self.__finish_call__()
-
+ # --------------------------------------------------------------------------
+ # Reject a call
+ # --------------------------------------------------------------------------
def rejectCall(self):
+ '''Reject a call
'''
- Reject a call
- '''
self.finishCall()
-
+ # --------------------------------------------------------------------------
+ # Accept an incoming call.
+ # --------------------------------------------------------------------------
def acceptCall(self, Call):
+ '''Accept an incoming call.
'''
- Accept an incoming call.
- '''
self.__get_call__(Call)
-
+ # --------------------------------------------------------------------------
+ # Change use status.
+ # --------------------------------------------------------------------------
def setOnlineStatus(self, status):
+ '''Change use status.
'''
- Change use status.
- '''
self.__set_online_status__(status)
-
+ # --------------------------------------------------------------------------
+ # Send a message to the user handle.
+ # --------------------------------------------------------------------------
def sendTextMessage(self, handle, message):
+ '''Send a message to the user handle.
'''
- Send a message to the user handle.
- '''
self.__send_message__(handle, message)
-
+# ==============================================================================
+# Declaration of the "AsynchroniousCommands" object.
+# ==============================================================================
class AsynchroniousCommands(object):
- '''
- Handle Asynchronious commands and skype events.
+ '''Handle Asynchronious commands and skype events.
'''
-
connectorObj = None
call = None
- ##### incoming triggered events. ####
+ # ------------------------------
+ # Incoming triggered events.
+ # ------------------------------
#@Params : ttsName skype name otherwise.
OnIncomingCall = None
-
- OnIncomingFinished = None
-
- #incoming call was refused because a call is in progress.
- # Sending event with user handle that tries to call.
- OnIncomingCallRefused = None
-
+ OnIncomingFinished = None
+ #Incoming call was refused because a call is in progress.
+ OnIncomingCallRefused = None
#@Params : ttsName, skype name otherwise.
OnIncomingMessage = None
-
- #### Outgoing triggered events ####
+ # ------------------------------
+ # Outgoing triggered events
+ # ------------------------------
#@Params : ttsName, cut number otherwise.
OnOutgoingCall = None
-
OnOutgoingFinished = None
-
#Outgoing call was refused because a call is in progress.
OnOutgoingCallRefused = None
- #### Misc events ####
+ # ------------------------------
+ # Misc triggered events
+ # ------------------------------
#@Params : ttsName , newStatus
OnlineContactStatusChanged = None
-
#@Params : AttituneName.
OnAvailableEmoticon = None
-
#@Params : TTS sentence.
OnAvailableTTSSentence = None
-
+ #contacts mutex.
lock = threading.Lock()
+ # ==========================================================================
+ # Public functions
+ # ==========================================================================
-###################################################
-####### Private functions ############
-
+ # --------------------------------------------------------------------------
+ # Init procedure
+ # --------------------------------------------------------------------------
def __init__(self, Connector):
+ '''Init procedure
'''
- Init procedure
- '''
self.connectorObj = Connector
- #Initializing events.
+ #Initializing connector events.
self.connectorObj.getSkypeAPI().OnOnlineStatus = self.__on_online_contact__
self.connectorObj.getSkypeAPI().OnMessageStatus = self.__on_message_status__
self.connectorObj.getSkypeAPI().OnCallStatus = self.__on_call_status__
-
-
+ # --------------------------------------------------------------------------
+ # Online contact event ( not used for now )
+ # --------------------------------------------------------------------------
def __on_online_contact__(self, User, Status):
+ '''Online contact event
'''
- '''
if self.OnlineContactStatusChanged != None:
thread = threading.Thread(target=self.OnlineContactStatusChanged, args = [User.Handle, Status])
thread.start()
-
+ # --------------------------------------------------------------------------
+ # Event handler for skype client incoming / outgoing calls.
+ # --------------------------------------------------------------------------
def __on_call_status__(self, Call, Status):
+ '''Event handler for skype client incoming / outgoing calls.
'''
- Event handler for skype client incoming / outgoing calls.
- '''
if Call.Type in [ Skype4Py.cltIncomingPSTN, Skype4Py.cltIncomingP2P]:
#incoming call.
self.__on_incoming_call__(Call, Status)
@@ -529,31 +556,32 @@
#Outgoing call.
self.__on_outgoing_call__(Call, Status)
-
-
+ # --------------------------------------------------------------------------
+ # Trigger incoming call events.
+ # --------------------------------------------------------------------------
def __on_incoming_call__(self, Call, Status):
+ '''Trigger incoming call events.
'''
- Trigger incoming call events.
- '''
+ #Setting up the current call
if ( self.call is None ):
self.call = Call
-
+ #If last registered call = current call parameter then it's ok continue.
if ( self.call.Id == Call.Id ) :
self.call = Call
partnerHandle = Call.PartnerHandle
-
+ #Call status is ringing, then trigger incoming call event.
if Status == Skype4Py.clsRinging:
if self.OnIncomingCall != None:
thread = threading.Thread(target=self.OnIncomingCall, args = [partnerHandle, ])
thread.start()
-
+ #Call status is in a 'finished' state without any distinction, then trigger finished event.
elif Status in [Skype4Py.clsFinished, Skype4Py.clsRefused,
Skype4Py.clsMissed, Skype4Py.clsFailed]:
if self.OnIncomingFinished != None:
self.call = None
thread = threading.Thread(target=self.OnIncomingFinished, args = [partnerHandle, ])
thread.start()
-
+ #Registered call and call parameter are diferents, so sending rejected event.
else:
callerHandle = None
try:
@@ -569,25 +597,25 @@
thread = threading.Thread(target=self.OnIncomingCallRefused, args = [Call.PartnerHandle, ])
thread.start()
-
-
-
+ # --------------------------------------------------------------------------
+ # Trigger outgoing call event.
+ # --------------------------------------------------------------------------
def __on_outgoing_call__(self, Call, Status):
+ '''Trigger outgoing call event.
'''
- Trigger outgoing call event.
- '''
+ #Setting up the current call
if ( self.call is None ):
self.call = Call
-
+ #If last registered call = current call parameter then it's ok continue.
if ( self.call.Id == Call.Id ) :
self.call = Call
partnerHandle = Call.PartnerHandle
-
+ #Call status is ringing, then trigger outgoing call event.
if Status == Skype4Py.clsRouting:
if self.OnOutgoingCall != None:
thread = threading.Thread(target=self.OnOutgoingCall, args = [partnerHandle, ])
thread.start()
-
+ #Call status is in a 'finished' state without any distinction, then trigger finished event.
elif Status in [Skype4Py.clsFinished, Skype4Py.clsRefused,
Skype4Py.clsCancelled, Skype4Py.clsFailed]:
if self.OnOutgoingFinished != None:
@@ -612,23 +640,23 @@
#Resume last call.
Call.Finish()
-
-
+ # --------------------------------------------------------------------------
+ # Skype contact message received.
+ # --------------------------------------------------------------------------
def __on_message_status__(self, Message, Status):
+ '''Skype contact message received.
'''
- '''
exclude_list = ['<partlist', '<part identity', '</name>', '<name>']
exclude_message = False
if Status == 'RECEIVED':
#Checking if message body is not empty.
- #Handle empty lists api case.
+ #Handle empty lists api case that can only be detected using try statment.
try:
Message.Body.splitlines()[0]
except:
exclude_message = True
-
#Checking first for available emoticon, if one found, then do not
#trigger message event BUT emoticon event.
emoticon_available, type = self.__check_emoticons__(Message.Body)
@@ -652,14 +680,13 @@
return
#Excluding 'identity call' messages in case of most recent Skype clients.
-
+ #'identity call' = call statuses in the messages box.
for excluded in exclude_list:
for msgPart in Message.Body.splitlines() :
if msgPart.find(excluded) != -1 :
exclude_message = True
break
-
if not exclude_message:
#Getting message user handle.
handle = tounicode(Message.FromHandle)
@@ -674,13 +701,12 @@
thread = threading.Thread(target=self.OnIncomingMessage, args=[handle, ])
thread.start()
-
-
-
+ # --------------------------------------------------------------------------
+ # Check message for matching emoticons.
+ # --------------------------------------------------------------------------
def __check_emoticons__(self, message):
+ '''Check message for matching emoticons.
'''
- Check message for matching emoticons.
- '''
self.lock.acquire()
# Search for emoticon
for emoticon in EMOTICONS_TO_ATTITUNES.keys():
@@ -690,11 +716,12 @@
self.lock.release()
return ( False, '' )
-
+ # --------------------------------------------------------------------------
+ # Check if the message contains 'tux'.
+ # --------------------------------------------------------------------------
def __check_tts_sentence__(self, message):
+ '''Check if the message contains 'tux'.
'''
- Check if the message contains 'tux'.
- '''
self.lock.acquire()
# speak the text if begin is "tuxdroid>"
if message.find('tuxdroid>') == 0:
|