[Pychord-commits] r66 - in trunk: . pychord2

danilo at garage.maemo.org danilo at garage.maemo.org
Sun Mar 23 02:10:06 EET 2008


Author: danilo
Date: 2008-03-23 02:10:05 +0200 (Sun, 23 Mar 2008)
New Revision: 66

Modified:
   trunk/pychord.py
   trunk/pychord2/__init__.py
Log:
- Fixed background light problems...
  I need to use try on main loop to get all exceptions and close the thread... It's ugly, I now! How can I let this better?

Modified: trunk/pychord.py
===================================================================
--- trunk/pychord.py	2008-03-22 23:27:15 UTC (rev 65)
+++ trunk/pychord.py	2008-03-23 00:10:05 UTC (rev 66)
@@ -126,8 +126,42 @@
     app = pychord2( options[ "resolution" ], options[ "fullscreen" ] or ismaemo(), pyc)
     app.loop()
 # main()
-         
+    
+
+from threading import Thread
+    
+class Maemolight (Thread):
+    
+    def run(self):
+        
+        import osso, time
+        
+        osso_c = osso.Context("osso_test_device_on", "0.0.1", False)
+        self.device = osso.DeviceState(osso_c)
+        
+        while self.Running:
+            print "lights!"
+            self.device.display_state_on()
+            
+            i = 0
+            while i < 9:
+                time.sleep(1)
+                i +=1
+                if not self.Running:
+                    return
+    
+    def cancel(self):
+            self.Running = False    
+            
+            
 # este comando fala para o python chamar o main se estao executando o script
 if __name__ == '__main__':
-    main( sys.argv )
-
+    lightThread = Maemolight()
+    try:
+        if ismaemo():
+            lightThread.Running = True
+            lightThread.start()
+        main( sys.argv )
+    except:
+        print "Unspected Error"
+        lightThread.cancel()
\ No newline at end of file

Modified: trunk/pychord2/__init__.py
===================================================================
--- trunk/pychord2/__init__.py	2008-03-22 23:27:15 UTC (rev 65)
+++ trunk/pychord2/__init__.py	2008-03-23 00:10:05 UTC (rev 66)
@@ -27,11 +27,7 @@
         pygame.display.set_caption( 'PyChord' )
         
         self.pyc = pyc
-        
-        if fullscreen:  
-            self.lightThread = Maemolight()
-
-        
+       
         self.fullscreen = fullscreen
         
         
@@ -44,32 +40,4 @@
         
         window = main_window(self.screen, self.pyc )
         window.show()
-        del(window)
-        
-
-    def __del__(self):
-        self.lightThread.cancel()
-
-from threading import Timer
-
-    
-class Maemolight ():
-    
-    def __init__(self):
-        import osso, time
-        osso_c = osso.Context("osso_test_device_on", "0.0.1", False)
-        self.device = osso.DeviceState(osso_c)
-        
-        self.t = Timer(9.0, self.run)
-        self.t.start() # after 30 seconds, "hello, world" will be printed
-    
-    def run(self):
-        print "Light!"
-        self.device.display_state_on()
-
-            
-    def cancel(self):
-        self.t.cancel()
-        print "Cancelando"
-    
-                
\ No newline at end of file
+        del(window)
\ No newline at end of file



More information about the Pychord-commits mailing list