meld r1263 - in trunk: . glade2



Author: stevek
Date: Sun Mar 15 17:05:47 2009
New Revision: 1263
URL: http://svn.gnome.org/viewvc/meld?rev=1263&view=rev

Log:
Move custom widget creation code into the module
which contains the widget.

Modified:
   trunk/glade2/dirdiff.glade
   trunk/glade2/filediff.glade
   trunk/glade2/meldapp.glade
   trunk/glade2/vcview.glade
   trunk/gnomeglade.py
   trunk/historyentry.py

Modified: trunk/glade2/dirdiff.glade
==============================================================================
--- trunk/glade2/dirdiff.glade	(original)
+++ trunk/glade2/dirdiff.glade	Sun Mar 15 17:05:47 2009
@@ -111,7 +111,7 @@
 	  <child>
             <widget class="Custom" id="fileentry0">
               <property name="visible">True</property>
-              <property name="creation_function">create_fileentry</property>
+              <property name="creation_function">historyentry.create_fileentry</property>
               <property name="string1">direntry</property>
               <property name="int1">1</property>
               <signal name="activate" handler="on_fileentry_activate"/>
@@ -128,7 +128,7 @@
 	  <child>
             <widget class="Custom" id="fileentry1">
               <property name="visible">True</property>
-              <property name="creation_function">create_fileentry</property>
+              <property name="creation_function">historyentry.create_fileentry</property>
               <property name="string1">direntry</property>
               <property name="int1">1</property>
               <signal name="activate" handler="on_fileentry_activate"/>
@@ -145,7 +145,7 @@
 	  <child>
             <widget class="Custom" id="fileentry2">
               <property name="visible">True</property>
-              <property name="creation_function">create_fileentry</property>
+              <property name="creation_function">historyentry.create_fileentry</property>
               <property name="string1">direntry</property>
               <property name="int1">1</property>
               <signal name="activate" handler="on_fileentry_activate"/>

Modified: trunk/glade2/filediff.glade
==============================================================================
--- trunk/glade2/filediff.glade	(original)
+++ trunk/glade2/filediff.glade	Sun Mar 15 17:05:47 2009
@@ -17,7 +17,7 @@
         <child>
           <widget class="Custom" id="fileentry2">
             <property name="visible">True</property>
-            <property name="creation_function">create_fileentry</property>
+            <property name="creation_function">historyentry.create_fileentry</property>
             <property name="string1">fileentry</property>
             <signal name="activate" handler="on_fileentry_activate"/>
           </widget>
@@ -31,7 +31,7 @@
         <child>
           <widget class="Custom" id="fileentry1">
             <property name="visible">True</property>
-            <property name="creation_function">create_fileentry</property>
+            <property name="creation_function">historyentry.create_fileentry</property>
             <property name="string1">fileentry</property>
             <signal name="activate" handler="on_fileentry_activate"/>
           </widget>
@@ -46,7 +46,7 @@
           <widget class="Custom" id="fileentry0">
             <property name="visible">True</property>
             <property name="string1">fileentry</property>
-            <property name="creation_function">create_fileentry</property>
+            <property name="creation_function">historyentry.create_fileentry</property>
             <signal name="activate" handler="on_fileentry_activate"/>
           </widget>
           <packing>
@@ -445,7 +445,7 @@
               <widget class="Custom" id="gnome_entry_search_for">
                 <property name="visible">True</property>
                 <property name="string1">search_for</property>
-                <property name="creation_function">create_entry</property>
+                <property name="creation_function">historyentry.create_entry</property>
               </widget>
               <packing>
                 <property name="left_attach">1</property>

Modified: trunk/glade2/meldapp.glade
==============================================================================
--- trunk/glade2/meldapp.glade	(original)
+++ trunk/glade2/meldapp.glade	Sun Mar 15 17:05:47 2009
@@ -143,7 +143,7 @@
                 <child>
                   <widget class="Custom" id="fileentry2">
                     <property name="visible">True</property>
-                    <property name="creation_function">create_fileentry</property>
+                    <property name="creation_function">historyentry.create_fileentry</property>
                     <property name="string1">file_comparison</property>
                     <property name="string2">My File</property>
                     <signal name="activate" handler="on_entry_activate"/>
@@ -159,7 +159,7 @@
                 <child>
                   <widget class="Custom" id="fileentry1">
                     <property name="visible">True</property>
-                    <property name="creation_function">create_fileentry</property>
+                    <property name="creation_function">historyentry.create_fileentry</property>
                     <property name="string1">file_comparison</property>
                     <property name="string2">Original File</property>
                     <signal name="activate" handler="on_entry_activate"/>
@@ -176,7 +176,7 @@
                   <widget class="Custom" id="fileentry0">
                     <property name="visible">True</property>
                     <property name="sensitive">False</property>
-                    <property name="creation_function">create_fileentry</property>
+                    <property name="creation_function">historyentry.create_fileentry</property>
                     <property name="string1">file_comparison</property>
                     <property name="string2">Other File</property>
                     <signal name="activate" handler="on_entry_activate"/>
@@ -281,7 +281,7 @@
                 <child>
                   <widget class="Custom" id="direntry2">
                     <property name="visible">True</property>
-                    <property name="creation_function">create_fileentry</property>
+                    <property name="creation_function">historyentry.create_fileentry</property>
                     <property name="string1">dir_comparison</property>
                     <property name="string2">My Directory</property>
                     <property name="int1">1</property>
@@ -298,7 +298,7 @@
                 <child>
                   <widget class="Custom" id="direntry1">
                     <property name="visible">True</property>
-                    <property name="creation_function">create_fileentry</property>
+                    <property name="creation_function">historyentry.create_fileentry</property>
                     <property name="string1">dir_comparison</property>
                     <property name="string2">Original Directory</property>
                     <property name="int1">1</property>
@@ -316,7 +316,7 @@
                   <widget class="Custom" id="direntry0">
                     <property name="visible">True</property>
                     <property name="sensitive">False</property>
-                    <property name="creation_function">create_fileentry</property>
+                    <property name="creation_function">historyentry.create_fileentry</property>
                     <property name="string1">dir_comparison</property>
                     <property name="string2">Other Directory</property>
                     <property name="int1">1</property>
@@ -405,7 +405,7 @@
                 <child>
                   <widget class="Custom" id="vcentry0">
                     <property name="visible">True</property>
-                    <property name="creation_function">create_fileentry</property>
+                    <property name="creation_function">historyentry.create_fileentry</property>
                     <property name="string1">vc_directory</property>
                     <property name="string2">VC Directory</property>
                     <property name="int1">1</property>

Modified: trunk/glade2/vcview.glade
==============================================================================
--- trunk/glade2/vcview.glade	(original)
+++ trunk/glade2/vcview.glade	Sun Mar 15 17:05:47 2009
@@ -33,7 +33,7 @@
 	  <child>
 	    <widget class="Custom" id="fileentry">
 	      <property name="visible">True</property>
-	      <property name="creation_function">create_fileentry</property>
+	      <property name="creation_function">historyentry.create_fileentry</property>
 	      <property name="string1">direntry</property>
 	      <property name="int1">1</property>
 	      <signal name="activate" handler="on_fileentry_activate"/>
@@ -479,7 +479,7 @@
 			  <property name="border_width">5</property>
               <property name="visible">True</property>
               <property name="string1">previousentry</property>
-              <property name="creation_function">create_entry</property>
+              <property name="creation_function">historyentry.create_entry</property>
               <signal name="changed" handler="on_previousentry_activate"/>
             </widget>
 			<packing>

Modified: trunk/gnomeglade.py
==============================================================================
--- trunk/gnomeglade.py	(original)
+++ trunk/gnomeglade.py	Sun Mar 15 17:05:47 2009
@@ -19,9 +19,13 @@
 
 import gtk
 import gtk.glade
-import historyentry
 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)
+
 class Component(object):
     """Base class for all glade objects.
 
@@ -39,7 +43,7 @@
     def __init__(self, filename, root, override=None):
         """Load the widgets from the node 'root' in file 'filename'.
         """
-        gtk.glade.set_custom_handler(self.get_custom_handler)
+        gtk.glade.set_custom_handler(custom_handler)
         if override is None:
             override = {}
         self.xml = gtk.glade.XML(filename, root, typedict=override)
@@ -76,38 +80,6 @@
                 lst.append(val)
                 i += 1
 
-    # Taken from the pygtk FAQ
-    def get_custom_handler(self, glade, function_name, widget_name,
-                           str1, str2, int1, int2):
-        """
-        Generic handler for creating custom widgets, used to
-        enable custom widgets.
-
-        The custom widgets have a creation function specified in design time.
-        Those creation functions are always called with str1,str2,int1,int2 as
-        arguments, that are values specified in design time.
-
-        This handler assumes that we have a method for every custom widget
-        creation function specified in glade.
-
-        If a custom widget has create_foo as creation function, then the
-        method named create_foo is called with str1,str2,int1,int2 as arguments.
-        """
-        if hasattr(self, function_name):
-            handler = getattr(self, function_name)
-            return handler(str1, str2, int1, int2)
-        else:
-            return None
-
-    def create_fileentry(self, history_id, dialog_title, is_directory_entry, int2):
-        w = historyentry.HistoryFileEntry(history_id, dialog_title)
-        w.directory_entry = is_directory_entry
-        return w
-
-    def create_entry(self, history_id, str2, int1, int2):
-        w = historyentry.HistoryEntry(history_id)
-        return w
-
 # Regular expression to match handler method names patterns
 # on_widget__signal and after_widget__signal.  Note that we use two
 # underscores between the Glade widget name and the signal name.

Modified: trunk/historyentry.py
==============================================================================
--- trunk/historyentry.py	(original)
+++ trunk/historyentry.py	Sun Mar 15 17:05:47 2009
@@ -475,3 +475,12 @@
     do_nothing = lambda *args: None
     setattr(HistoryFileEntry, '_setup_dnd', do_nothing)
 
+def create_fileentry( history_id, dialog_title, is_directory_entry, int2):
+    w = HistoryFileEntry(history_id, dialog_title)
+    w.directory_entry = is_directory_entry
+    return w
+
+def create_entry( history_id, str2, int1, int2):
+    w = HistoryEntry(history_id)
+    return w
+



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