Gtk About Dialog

Posted on November 1, 2007
Filed Under gtk, python |

The example that follow show a gtk about dialog with a working close button and a working external link button. We will obtain something like this:

About Dialog

We will put focus on how to obtain a response when we click on the link. The funcion that do the trick is gtk.about_dialog_set_url_hook that set a callback that will be called on the click action.

Python code

  1.  
  2. import gtk
  3. import subprocess
  4.  
  5. def on_url(d, link, data):
  6.         subprocess.Popen(["firefox", "http://ferama.netsons.org"])
  7.  
  8. gtk.about_dialog_set_url_hook(on_url, None)
  9.  
  10. def create_dialog():
  11.         dlg = gtk.AboutDialog()
  12.         dlg.set_version("0.1")
  13.         dlg.set_name("app")
  14.         dlg.set_license("This code is free")
  15.         dlg.set_authors(["Marco Ferragina"])
  16.         dlg.set_website("http://ferama.netsons.org")
  17.         def close(w, res):
  18.                 if res == gtk.RESPONSE_CANCEL:
  19.                         w.hide()
  20.         dlg.connect("response", close)
  21.         return dlg
  22.  
  23. if __name__ == "__main__":
  24.         dlg = create_dialog()
  25.         dlg.run()

Comments

One Response to “Gtk About Dialog”

  1. Casey on June 1st, 2008 9:44 am

    Thanks for this example, I made this a little more generic in my code:

    Class AboutSetup():
    def __init__(self):
    gc = gconf.client_get_default()
    browser = gc.get_string(’/desktop/gnome/url-handlers/http/command’)
    email = gc.get_string(’/desktop/gnome/url-handlers/mailto/command’)
    gtk.about_dialog_set_url_hook( self._link_handle_cb, browser)
    gtk.about_dialog_set_email_hook( self._link_handle_cb, email)

    def _link_handle_cb( self, win, link, data):
    cmd = data % (link,)
    subprocess.Popen( cmd.split() )

Leave a Reply