[meld] Let glade custom widget constructors come from subpackages



commit eb79783ad651a1e3944b9cf488f4f1fca9d2945c
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Thu Jul 9 09:52:56 2009 +1000

    Let glade custom widget constructors come from subpackages
    
    By default, __import__ always returns the top-level package, even when
    importing subpackages. In order to allow for custom widgets that reside in
    subpackages, we pull the actual module out of sys.modules after import. As
    a result, we now support e.g., meld.ui.findbar.findbar_create() for custom
    widget creation.

 gnomeglade.py |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
---
diff --git a/gnomeglade.py b/gnomeglade.py
index 1557115..459733d 100644
--- a/gnomeglade.py
+++ b/gnomeglade.py
@@ -17,6 +17,8 @@
 """Utility class for working with glade files.
 """
 
+import sys
+
 import gtk
 import gtk.glade
 import re
@@ -24,7 +26,8 @@ import re
 def custom_handler( glade, module_function_name, widget_name, str1, str2, int1, int2):
     assert module_function_name.find(".") != -1, "%s should contain a ." % module_function_name
     module, function_name = module_function_name.rsplit(".",1)
-    return getattr(__import__(module), function_name)(str1, str2, int1, int2)
+    __import__(module)
+    return getattr(sys.modules[module], function_name)(str1, str2, int1, int2)
 
 class Component(object):
     """Base class for all glade objects.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]