The later versions of Glade creates a XML file containing defs of more
than one window in the same file, which seems to be more than the current
pyglade code can handle. I hacked up a class to represent the project
file, which can give you the WidgetTree object corresponding to a
particular "window" in the .glade file. This works fine, except for one
detail: When creating a GtkDialog object, the "dialog_new" function
modifies the XML tree from which the dialog should be created, which means
that when you try to create the same dialog the second time around, the
XML tree looks different: particularly, it looks in a way that dialog_new
can't work with, and so you get an exception.
The offending code (~690 in the patched code):
# do some weird stuff because the vbox/action area is already created
node.widget['__wid'] = widget.vbox
children = node.widget.widget
if type(children) != type(()): children = (children,)
for i in range(len(children)):
if children[i].has_key('child_name') and \
children[i].child_name == 'Dialog:action_area':
node['widget'] = (node.widget, children[i])
children[i].parent = node
children[i]['__wid'] = widget.action_area
node.widget[0]['widget'] = children[0:i]+children[i+1:]
break
I can't really get around the problem by cloning the the widget tree, and
it takes too much time reparsing the .glade file every time a widget is
requested so I see no other way than to try to recreate the dialog_new
method so it doesn't need to modify the incoming XML tree. Problem is, I
can't really get to grips with what's going on in the above snippet.
Attached you find a patch for the pyglade/ dir made against 0.6.0 sources
which will allow you to load glade projects.
Anyone got any suggestions?
Anders "Quest" Qvist
NetGuide Scandinavia
-- Why suffer scarcity? Look for the Open Source and enter a world of plenty!
diff -u python-gnome-1.0.2.orig/pygtk/pyglade/__init__.py
../python-gnome-1.0.2.orig/pygtk/pyglade/__init__.py
--- python-gnome-1.0.2.orig/pygtk/pyglade/__init__.py Mon Jan 11 14:30:35 1999
+++ ../python-gnome-1.0.2.orig/pygtk/pyglade/__init__.py Sun May 23 21:26:30
+1999
@@ -3,9 +3,9 @@
def construct(filename):
tree = xmlparse.read(filename)['gtk-interface']
- wtree = build.WidgetTree(tree)
- tree.destroy()
- return wtree
+ project = build.GladeProject(tree)
+ #tree.destroy()
+ return project
# for ni ...
try:
diff -u python-gnome-1.0.2.orig/pygtk/pyglade/build.py
../python-gnome-1.0.2.orig/pygtk/pyglade/build.py
--- python-gnome-1.0.2.orig/pygtk/pyglade/build.py Tue Feb 23 15:22:45 1999
+++ ../python-gnome-1.0.2.orig/pygtk/pyglade/build.py Sun May 23 21:26:30 1999
@@ -29,11 +29,44 @@
_widgets = {}
-class WidgetTree:
+# Begin QuestHack (990508) to add support for glade-0.4 project style
+# resource files
+class GladeProject:
+ __windows = {}
+ __info = {}
def __init__(self, tree):
if tree.has_key('gtk-interface'): tree = tree['gtk-interface']
if tree.tag != 'gtk-interface':
raise error, "first argument not the base of tag tree"
+
+ if tree.has_key ('project'):
+ self.__info = tree.project
+
+ if tree.has_key('widget'):
+ wins = tree.widget
+ if type(wins) != type(()):
+ wins = (wins,)
+ else: wins = ()
+
+ # Create mapping of all top level widgets, 'windows'
+ for win in wins:
+ if win.has_key('name'):
+ self.__windows[win['name']] = win
+ else:
+ raise error, "top widget has no name attr"
+
+ def get_info(self):
+ return self.__info
+
+ def get_toplevel_widget(self, widget_name):
+ if self.__windows.has_key(widget_name):
+ return WidgetTree(self.__windows[widget_name])
+ else:
+ raise error, "no such toplevel widget"
+# End QuestHack
+
+class WidgetTree:
+ def __init__(self, tree):
self.__signals = {} # signals
self.__widgets = {} # widgets by name
self.__paths = {} # widgets by path
@@ -45,10 +78,7 @@
# create widgets
if tree.has_key('widget'):
- children = tree.widget
- if type(children) != type(()): children = (children,)
- for child in children:
- self.__new_widget(child)
+ self.__new_widget(tree)
if self.tooltips:
self.tooltips.enable();
@@ -91,7 +121,7 @@
if node.has_key('widget'):
if not add:
raise error, "don't know how to add " + \
- "widgets to this container"
+ "widgets to " + wclass
children = node.widget
if type(children) != type(()): children = (children,)
for child in children: