Author: gwadavel
Date: 2009-08-07 17:28:10 +0200 (Fri, 07 Aug 2009)
New Revision: 5297

Added:
   software_suite_v3/software/plugin/plugin-battery/trunk/builder/
   software_suite_v3/software/plugin/plugin-battery/trunk/executables/
   
software_suite_v3/software/plugin/plugin-battery/trunk/executables/plugin-battery.py
Removed:
   software_suite_v3/software/plugin/plugin-battery/trunk/builder/
   software_suite_v3/software/plugin/plugin-battery/trunk/executables/
Log:
Sorry for this very bad commit .. it's suck --i don't know why

Copied: software_suite_v3/software/plugin/plugin-battery/trunk/builder (from 
rev 5289, 
software_suite_v3/smart-core/smart-dev/plugin-toolkit/python/skeleton/trunk/builder)

Copied: software_suite_v3/software/plugin/plugin-battery/trunk/executables 
(from rev 5289, 
software_suite_v3/software/plugin/old-gadget-format-transition-to-v3/tuxdroid-gadget-battery/trunk/executables)

Added: 
software_suite_v3/software/plugin/plugin-battery/trunk/executables/plugin-battery.py
===================================================================
--- 
software_suite_v3/software/plugin/plugin-battery/trunk/executables/plugin-battery.py
                                (rev 0)
+++ 
software_suite_v3/software/plugin/plugin-battery/trunk/executables/plugin-battery.py
        2009-08-07 15:28:10 UTC (rev 5297)
@@ -0,0 +1,157 @@
+# -*- coding: utf-8 -*-
+
+#    Write with Python plugin skeleton
+#    Copyright (C) 2009 Kysoh Sa
+#    Remi Jocaille <[email protected]>
+#    Distributed under the terms of the GNU General Public License
+#    http://www.gnu.org/copyleft/gpl.html
+
+
+"""
+CHANGES
+=======
+
+2009/08/07 - version 0.0.1:
+    - Initial version
+
+TODO LIST
+=========
+
+- Internationalization
+
+__author__  = "Eric Lescaudron AKA Gwadavel"
+__appname__ = "Battery Level Plugin"
+__version__ = "0.0.1"
+__date__    = "2009/08/07"
+__license__ = "GPL"
+
+"""
+
+import os
+import sys
+
+import locale
+import gettext
+
+from tuxisalive.api import *
+
+sys.path.append(os.environ['TUXDROID_SERVER_PYTHON_UTIL'])
+
+from util.SimplePlugin.SimplePluginConfiguration import 
SimplePluginConfiguration
+from util.SimplePlugin.SimplePlugin import SimplePlugin
+
+class Battery(object):
+    """
+    Manage the battery.
+    """
+
+    tgp_language = "en"
+    tgp_ip = "127.0.0.1"
+    tgp_port = 270
+    tux = TuxAPI("127.0.0.1", 270)
+    
+    def __init__(self, plug):
+        '''
+        '''
+        self.plugin = plug 
+
+        # Test language, ip, port
+        if "tgp_language" in os.environ:
+            self.tgp_language = os.environ["tgp_language"]
+
+        if "tgp_ip" in os.environ:
+            self.tgp_ip = os.environ["tgp_ip"]
+
+        if "tgp_port" in os.environ:
+            self.tgp_port = int(os.environ["tgp_port"])
+
+        tux = TuxAPI(self.tgp_ip, self.tgp_port)
+      
+        
+    def tuxConnect(self):
+        '''
+        Wait connected
+        '''
+
+        self.tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'batterylevel', 
'plugin-battery')
+        self.tux.server.waitConnected(5.0)
+        self.tux.dongle.waitConnected(5.0)
+        self.tux.radio.waitConnected(5.0)
+        return self.tux.access.waitAcquire(5.0, ACCESS_PRIORITY_NORMAL)
+
+
+    def getLevel(self):
+        """
+        Return Battery Level
+        """
+
+        return self.tux.battery.getLevel()
+ 
+
+    def getState(self):
+        """
+        Return Battery State
+        """
+ 
+        return self.tux.battery.getState()
+
+
+    def start(self):
+        """
+        """
+
+        if self.tuxConnect():
+
+            if not self.tux.radio.getConnected():
+               plugin.throwTrace("I can't find my fish. Please, make sure I'm 
connected.")
+            else:
+                level = self.getLevel()
+                state = self.getState()
+                message = "the battery level is %1.2f it state is %s" %(level, 
state)
+                plugin.throwMessage(message)               
+               
+        self.stop()
+
+
+    def stop(self):
+        """
+        """
+
+        self.tux.access.release()
+        self.tux.server.disconnect()
+        self.tux.destroy()
+ 
+
+class BatteryPlugin(SimplePlugin):
+    """This class override the SimplePlugin class to make easy
+    the plugin coding.
+    """
+
+    def __init__(self):
+        """Initialization of the class.
+        """
+        # Call the super class
+        SimplePlugin.__init__(self)
+        self.sbattery = Battery(self)
+        
+
+    def start(self):
+        """Plugin entry point.
+        This method should be used to dispatch commands.
+        """
+        self.run()
+
+    def run(self):
+        """Plugin entry point for the "run" command.
+        """
+        self.sbattery.start()
+
+    def onPluginStop(self):
+        """Callback on plugin stop.
+        """
+        # Stop the fake daemon loop
+        self.sbattery.stop()
+        
+if __name__ == "__main__":
+    plugin = BatteryPlugin()
+    plugin.boot(sys.argv[1:], SimplePluginConfiguration())


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to