Author: dmeyer
Date: Sun Apr 16 21:47:12 2006
New Revision: 1399

Modified:
   trunk/base/src/notifier/__init__.py
   trunk/base/src/notifier/callback.py

Log:
small code to support gtk notifier

Modified: trunk/base/src/notifier/__init__.py
==============================================================================
--- trunk/base/src/notifier/__init__.py (original)
+++ trunk/base/src/notifier/__init__.py Sun Apr 16 21:47:12 2006
@@ -36,6 +36,7 @@
 import traceback
 import time
 import signal
+import atexit
 
 # kaa.notifier imports
 from popen import *
@@ -157,4 +158,20 @@
 def _signal_handler(signum, frame):
     shutdown()
 
+# catch SIGTERM
 signal.signal(signal.SIGTERM, _signal_handler)
+
+def _shutdown_check():
+    # Helper function to shutdown kaa on system exit
+    # The problem is that pytgtk just exits python and
+    # does not simply return from the main loop and kaa
+    # can't call the shutdown handler. This is not a perfect
+    # solution, e.g. with the generic notifier you can do
+    # stuff after kaa.main() which is not possible with gtk
+    global running
+    if running:
+        running = False
+        shutdown()
+
+# check to make sure we really call our shutdown function
+atexit.register(_shutdown_check)

Modified: trunk/base/src/notifier/callback.py
==============================================================================
--- trunk/base/src/notifier/callback.py (original)
+++ trunk/base/src/notifier/callback.py Sun Apr 16 21:47:12 2006
@@ -43,11 +43,21 @@
         # notifier to be sure it is the correct version
         raise ImportError
     import notifier
-    if not notifier.loop:
-        # init pyNotifier with the generic notifier
-        notifier.init(notifier.GENERIC)
+    if notifier.loop:
+        # pyNotifier should be used and already active
+        log = logging.getLogger('notifier')
+        log.info('pynotifier already running, I hope you know what you are 
doing')
+    else:
+        # pyNotifier is installed, so we use it
+        if sys.modules.has_key('gtk'):
+            # The gtk module is loaded, this means that we will hook
+            # ourself into the gtk main loop
+            notifier.init(notifier.GTK)
+        else:
+            # init pyNotifier with the generic notifier
+            notifier.init(notifier.GENERIC)
     use_pynotifier = True
-
+        
     # delete basic notifier handler
     log = logging.getLogger('notifier')
     for l in log.handlers:
@@ -55,6 +65,10 @@
 
 except ImportError:
     # use a copy of nf_generic
+    if sys.modules.has_key('gtk'):
+        log = logging.getLogger('notifier')
+        log.error('To use gtk with kaa.notifier requires pynotifier to be 
installed')
+        sys.exit(1)
     import nf_generic as notifier
     use_pynotifier = False
 


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to