title: Python : How can two GTK widgets interact with each other?
body: <p>What is the proper way to interact with a button without actually clicking on it?</p>
  
  <p>I have a button "button", that can, upon click : </p>
  
  <ul>
  <li>Call the method "the_method" that will print what argument (here "filename") has been passed to it</li>
  <li>toggle its own attributes, here its icon.</li>
  </ul>
  
  <p>And I have a treeview, whose rows must, upon double click :</p>
  
  <ul>
  <li>Call the method "the_method" that will print what argument (here "filename") has been passed to it</li>
  <li>toggle "button"'s attributes, here its icon.</li>
  </ul>
  
  <p>And only the 1st part works. The "foo" function is called (via a callback for the button, directly for the treeview item) and the argument ("filename") is retrieved OK, but how to execute part 2 of the job (changing "button"'s attributes, here its icon)?</p>
  
  <hr>
  
  <pre><code>import gtk
  
  class Lister(object):
  
      def __init__(self):
          self.hbox = gtk.HBox()
  
          liststore = gtk.ListStore(str)
          liststore.append(["foo"])
          liststore.append(["bar"])
          treeview = gtk.TreeView(liststore)
          self.hbox.pack_start(treeview, False)
          cell = gtk.CellRendererText()
          col = gtk.TreeViewColumn("Column 1")
          col.pack_start(cell, True)
          col.set_attributes(cell,text=0)
          treeview.connect('row-activated', self.open_file)
          treeview.append_column(col)
  
      def open_file(self, button, *args):
          Buttons().the_method(self, "foo")
  
  class Buttons(object):
  
      OPEN_IMAGE = gtk.image_new_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
      CLOSED_IMAGE = gtk.image_new_from_stock(gtk.STOCK_REFRESH, gtk.ICON_SIZE_BUTTON)
  
      def __init__(self):
  
          self.button = gtk.Button() # THIS is the button to modify
          self.hbox = gtk.HBox()
          self.hbox.pack_start(self.button, False)
          self.button.set_image(self.OPEN_IMAGE)
  
          self.button.connect('clicked', self.the_method, "plop")
          self.toggled = True
  
      def the_method(self, button, filename):
          print filename
          print vars(self)
  
          if self.toggled:
              self.button.set_image(self.CLOSED_IMAGE)
              self.toggled = False
          else:
              self.button.set_image(self.OPEN_IMAGE)
              self.toggled = True
  
  class GUI(object):
  
      def delete_event(self, widget, event, data=None):
          gtk.main_quit()
          return False
  
      def __init__(self):
          self.window = gtk.Window()
          self.window.set_size_request(100, 150)
          self.window.connect("delete_event", self.delete_event)
  
          vbox = gtk.VBox()
          vbox.pack_start(Buttons().hbox, False, False, 1)
          vbox.pack_start(Lister().hbox)
  
          self.window.add(vbox)
          self.window.show_all()
          return
  
  def main():
      gtk.main()
  
  if __name__ == "__main__":
      GUI()
      main()
  </code></pre>