[Pkg-sugar-commit] [sugar-toolkit] 03/21: Trap X errors in wm.py (#1123)

Jonas Smedegaard dr at jones.dk
Thu Apr 16 18:50:24 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.84.17-1
in repository sugar-toolkit.

commit c5a558aea55f8407742890a14b41adf16ae3452a
Author: Benjamin Berg <benjamin at sipsolutions.net>
Date:   Fri Aug 28 12:18:00 2009 +0200

    Trap X errors in wm.py (#1123)
---
 src/sugar/wm.py | 39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/src/sugar/wm.py b/src/sugar/wm.py
index 4ec9a12..971f3d2 100644
--- a/src/sugar/wm.py
+++ b/src/sugar/wm.py
@@ -20,10 +20,36 @@ UNSTABLE. Used only internally by Activity and jarabe.
 """
 
 import gtk
+import logging
 
+def _property_get_trapped(window, prop, prop_type):
+    gtk.gdk.error_trap_push()
+
+    prop_info = window.property_get('_SUGAR_ACTIVITY_ID', 'STRING')
+
+    # We just log a message
+    error = gtk.gdk.error_trap_pop()
+    if gtk.gdk.error_trap_pop():
+        logging.debug('Received X Error (%i) while getting '
+                      'a property on a window' % error)
+
+    return prop_info
+
+def _property_change_trapped(window, prop, prop_type, format, mode, data):
+    gtk.gdk.error_trap_push()
+
+    window.property_change(prop, prop_type, format, mode, data)
+
+    error = gtk.gdk.error_trap_pop()
+    if error:
+        logging.debug('Received X Error (%i) while setting '
+                      'a property on a window' % error)
+        raise RuntimeError('Received X Error (%i) while setting '
+                           'a property on a window' % error)
+    
 def get_activity_id(wnck_window):
     window = gtk.gdk.window_foreign_new(wnck_window.get_xid())
-    prop_info = window.property_get('_SUGAR_ACTIVITY_ID', 'STRING')
+    prop_info = _property_get_trapped(window, '_SUGAR_ACTIVITY_ID', 'STRING')
     if prop_info is None:
         return None
     else:
@@ -31,16 +57,17 @@ def get_activity_id(wnck_window):
 
 def get_bundle_id(wnck_window):
     window = gtk.gdk.window_foreign_new(wnck_window.get_xid())
-    prop_info = window.property_get('_SUGAR_BUNDLE_ID', 'STRING')
+    prop_info = _property_get_trapped(window, '_SUGAR_BUNDLE_ID', 'STRING')
     if prop_info is None:
         return None
     else:
         return prop_info[2]
 
 def set_activity_id(window, activity_id):
-    window.property_change('_SUGAR_ACTIVITY_ID', 'STRING', 8,
-                           gtk.gdk.PROP_MODE_REPLACE, activity_id)
+    _property_change_trapped(window, '_SUGAR_ACTIVITY_ID', 'STRING', 8,
+                             gtk.gdk.PROP_MODE_REPLACE, activity_id)
 
 def set_bundle_id(window, bundle_id):
-    window.property_change('_SUGAR_BUNDLE_ID', 'STRING', 8,
-                           gtk.gdk.PROP_MODE_REPLACE, bundle_id)
+    _property_change_trapped(window, '_SUGAR_BUNDLE_ID', 'STRING', 8,
+                             gtk.gdk.PROP_MODE_REPLACE, bundle_id)
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-sugar/sugar-toolkit.git



More information about the pkg-sugar-commit mailing list