LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-22-2007, 08:23 PM   #1
merville
LQ Newbie
 
Registered: Jan 2001
Location: Norfolk, UK
Posts: 3

Rep: Reputation: 0
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:

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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with python program--gtk.glade? David the H. Linux - Software 2 02-08-2007 08:18 AM
Gtk widget problem iali Linux - General 0 01-21-2006 12:56 AM
Is there Paint like program or widget in Glade+GTK+ santhosh.linux Programming 1 01-12-2006 03:55 AM
python/glade attach window content in gtk.fixed() a10392 Linux - Software 3 10-08-2004 09:19 AM
How to program for CTree widget in Glade 2.0 swaviswa Programming 0 03-27-2004 01:50 AM


All times are GMT -5. The time now is 10:19 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration