Hi there,
I am very new to Python and am trying to code a Python / Glade app to dump the user input into an XML file. As I intend to use the field name associated with the widget as the XML tag, I want to extract the widget name and the content or state of the widget (toggled or untoggled in the case of radio buttons and check boxes) by looping through the widgets using wTree. This does not provide the outcome I was hoping for:
Code:
#!/usr/bin/env python
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
class FormGenGTK:
def __init__(self):
self.gladefile = "formgen.glade"
self.wTree = gtk.glade.XML(self.gladefile)
dic = { "on_button1_clicked" : self.on_button1_clicked,
"on_button2_clicked" : gtk.main_quit ,
"on_window1_destroy" : gtk.main_quit }
self.wTree.signal_autoconnect(dic)
def on_button1_clicked(self, widget):
text = {}
for x in range(1,5):
entry = "entry%s" % (x)
text[x] = self.wTree.get_widget(entry)
print text[x]
if __name__ == "__main__":
hwg = FormGenGTK()
gtk.main()
However, this results in the following output even when the fields entry1 .... 5 are populated:
Code:
<gtk.Entry object at 0x82687d4 (GtkEntry at 0x84cf660)>
<gtk.Entry object at 0x8268af4 (GtkEntry at 0x84cf710)>
<gtk.Entry object at 0x8268b1c (GtkEntry at 0x84d6008)>
<gtk.Entry object at 0x8268b44 (GtkEntry at 0x84d60b8)>
I am guessing that by calling self.wTree.signal_autoconnect(dic) I am loading the buttons and window widgets and overwriting the widgets defined in the XML file.
Can anyone suggest an elegant solution to access a widget without knowing its name and displaying its content?
Many thanks in advance.