problem implementing get_filename() method for GtkFileChooser Button in glade and python?
Question: As a newbee I am trying to create a basic theme installer using Glade and
python. Everything is working fine but i am not able to find anywhere how to
use get_filename() method for gtkFileChooserButton. My Glade File Looks Like
this.

    
    
    <?xml version="1.0"?>
    <interface>
      <requires lib="gtk+" version="2.16"/>
      <!-- interface-naming-policy project-wide -->
    <object class="GtkWindow" id="main">
    <property name="title" translatable="yes">Maininin</property>
    <property name="window_position">center</property>
    <signal name="destroy" handler="on_main_destroy"/>
    <child>
      <object class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <child>
          <object class="GtkLabel" id="INFO">
            <property name="visible">True</property>
            <property name="label" translatable="yes">Theme</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="padding">28</property>
            <property name="position">0</property>
          </packing>
        </child>
        <child>
          <object class="GtkHButtonBox" id="hbuttonbox1">
            <property name="visible">True</property>
            <property name="layout_style">spread</property>
            <child>
              <object class="GtkFileChooserButton" id="DD">
                <property name="visible">True</property>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="pack_type">end</property>
                <property name="position">0</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <object class="GtkHButtonBox" id="hbuttonbox2">
            <property name="visible">True</property>
            <property name="layout_style">spread</property>
            <child>
              <object class="GtkButton" id="Add">
                <property name="label">gtk-add</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
                <signal name="clicked" handler="on_Add_clicked"/>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="position">0</property>
              </packing>
            </child>
            <child>
              <object class="GtkButton" id="Quit">
                <property name="label">gtk-quit</property>
                <property name="visible">True</property>
                <property name="can_focus">True</property>
                <property name="receives_default">True</property>
                <property name="use_stock">True</property>
                <signal name="clicked" handler="on_Quit_clicked"/>
              </object>
              <packing>
                <property name="expand">False</property>
                <property name="fill">False</property>
                <property name="pack_type">end</property>
                <property name="position">1</property>
              </packing>
            </child>
          </object>
          <packing>
            <property name="position">2</property>
          </packing>
        </child>
        <child>
          <object class="GtkLabel" id="WARN">
            <property name="visible">True</property>
            <property name="label" translatable="yes">Warning</property>
          </object>
          <packing>
            <property name="expand">False</property>
            <property name="padding">37</property>
            <property name="position">3</property>
          </packing>
        </child>
      </object>
    </child>
    

`

And Python Code is:

    
    
    import sys
    try:  
    import pygtk  
    pygtk.require("2.0")  
    except:  
    pass  
    try:  
    import gtk   
    except:  
    print("GTK Not Availible")
    sys.exit(1)
    
    
    class workplz(object):
    
    
    def __init__( self ):
        builder = gtk.Builder()
        builder.add_from_file("heme.glade")
        builder.connect_signals({"on_main_destroy" : self.quit, "on_Add_clicked" : self.add, "on_Quit_clicked" : self.quit})
        self._window = builder.get_object("main")
        self._window.show()     
    
    def add(self, widget):
        target=DD.get_filename()
        print target
    
    
    def quit(self, widget):
        sys.exit(0)
    
    
    if __name__ == "__main__":
        wine = workplz()
        gtk.main()
    

what is the right way of doing it???


Answer: I believe if you would get your GtkFileChooserButton object from the builder
and save a reference to it as a member of `workplz` class you could query it
in the `add` signal handler. See if script below would work for you:

    
    
    class workplz(object):
        def __init__( self ):
            builder = gtk.Builder()
            builder.add_from_file("heme.glade")
            builder.connect_signals({"on_main_destroy" : self.quit, "on_Add_clicked" : self.add, "on_Quit_clicked" : self.quit})
    
            # get GtkFileChooserButton object 
            self.DD = builder.get_object('DD')
    
            self._window = builder.get_object("main")
            self._window.show()     
    
        def add(self, widget):
            target = self.DD.get_filename()
            print target
    
        def quit(self, widget):
            sys.exit(0)
    

hope this helps, regards

