Author: jerome
Date: 2009-03-31 16:13:40 +0200 (Tue, 31 Mar 2009)
New Revision: 4294

Added:
   
software_suite_v2/software/gadgets/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/GadgetHelper.py
Modified:
   
software_suite_v2/software/gadgets/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/tuxdroid-gadget-skype.py
Log:
* Make use of GadgetHelper.

Added: 
software_suite_v2/software/gadgets/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/GadgetHelper.py
===================================================================
--- 
software_suite_v2/software/gadgets/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/GadgetHelper.py
                            (rev 0)
+++ 
software_suite_v2/software/gadgets/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/GadgetHelper.py
    2009-03-31 14:13:40 UTC (rev 4294)
@@ -0,0 +1,94 @@
+#    Copyright (C) 2009 C2ME Sa
+#    Remi Jocaille <[email protected]>
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+import 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: 
software_suite_v2/software/gadgets/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/tuxdroid-gadget-skype.py
===================================================================
--- 
software_suite_v2/software/gadgets/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/tuxdroid-gadget-skype.py
   2009-03-31 14:06:14 UTC (rev 4293)
+++ 
software_suite_v2/software/gadgets/tuxdroid-gadget-skype/trunk/tuxdroid-skype-gadget/executables/tuxdroid-gadget-skype.py
   2009-03-31 14:13:40 UTC (rev 4294)
@@ -29,7 +29,9 @@
 import time
 import os
 import subprocess
+
 from tuxisalive.api.TuxAPI import *
+from GadgetHelper import GadgetHelper
 
 
 class Connection(object):
@@ -115,7 +117,7 @@
             #Connect to skype api.
             self.__connectSkypeAPI()
         except:
-            print("message: \"" + "I cannot get connected to your Skeyepe. 
Please, check if you are connected. And verify if I can access skeyepe." + "\"")
+            GadgetHelper.throwMessage("I cannot get connected to your Skeyepe. 
Please, check if you are connected. And verify if I can access skeyepe.")
             self.__destroy()
      
      
@@ -343,10 +345,10 @@
                 result = process.stdout.read()
                 result.split()
                 if ("not" in result) and ("recognized" in result) and 
("command" in result):
-                    print("message: \"" + "Sorry, it looks like skeyepe is not 
installed. Please go to the skeyepe website to download the software." + "\"")
+                    GadgetHelper.throwMessage("Sorry, it looks like skeyepe is 
not installed. Please go to the skeyepe website to download the software.")
                     self.__activeMain = False
             except WindowsError:
-                print("message: \"" + "Sorry, it looks like skeyepe is not 
installed. Please go to the skeyepe website to download the software." + "\"")
+                GadgetHelper.throwMessage("Sorry, it looks like skeyepe is not 
installed. Please go to the skeyepe website to download the software.")
                 self.__activeMain = False
                
                     
@@ -365,7 +367,7 @@
              #Then skype is in PATH
              subprocess.Popen("skype", stdin=subprocess.PIPE, 
stdout=subprocess.PIPE)
          else:
-             print("message: \"" + "Sorry, it looks like skeyepe is not 
installed. Please go to the skeyepe website to download the software." + "\"")
+             GadgetHelper.throwMessage("Sorry, it looks like skeyepe is not 
installed. Please go to the skeyepe website to download the software.")
              self.__activeMain = False
             
         
@@ -402,7 +404,7 @@
          if len(self.__contactsDict) > 0:
              self.nextContact()
          else:
-             print("message \"I cannot found online user or registered cell 
numbers\"")
+             GadgetHelper.throwMessage("I cannot found online user or 
registered cell numbers")
              self.__destroy()
          return self.__contactsList
 


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

Reply via email to