-   Programming (
-   -   Python / Glade / GTK problem with accessing widget properties (

merville 11-22-2007 09:23 PM

Python / Glade / GTK problem with accessing widget properties
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:


  #!/usr/bin/env python

  import sys
      import pygtk
      import gtk
  class FormGenGTK:
      def __init__(self):
          self.gladefile = "" 
          self.wTree =
          dic = { "on_button1_clicked" : self.on_button1_clicked,
                  "on_button2_clicked" : gtk.main_quit ,
                  "on_window1_destroy" : gtk.main_quit }
      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()

However, this results in the following output even when the fields entry1 .... 5 are populated:


 <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.

All times are GMT -5. The time now is 09:11 PM.