thg / hggtk / about.py

#
# TortoiseHg About dialog
#
# Copyright (C) 2007 TK Soh <teekaysoh@gmail.com>
#

import os
import sys

import pygtk
pygtk.require('2.0')
import gtk
import gobject
import pango

import tortoise.version
import mercurial.version
from tortoise.thgutil import get_prog_root

prog_root = get_prog_root()
hg_icon = os.path.join(prog_root, "icons/tortoise/hg.ico")
license_file = os.path.join(prog_root, "COPYING.txt")

def browse_url(url):
    import threading
    def start_browser():
        if os.name == 'nt':
            import win32api, win32con
            win32api.ShellExecute(0, "open", url, None, "", 
                win32con.SW_SHOW)
        else:
            import gconf
            client = gconf.client_get_default()
            browser = client.get_string(
                    '/desktop/gnome/url-handlers/http/command') + '&'
            os.system(browser % url)
    threading.Thread(target=start_browser).start()

def url_handler(dialog, link, user_data):
	browse_url(link)
    
gtk.about_dialog_set_url_hook(url_handler, None)

def make_version(tuple):
    vers = ".".join([str(x) for x in tuple])
    return vers
    
class AboutDialog(gtk.AboutDialog):
    def __init__(self):
        super(AboutDialog, self).__init__()

        lib_versions = ', '.join([
                "Mercurial-%s" % mercurial.version.get_version(),
                "Python-%s" % make_version(sys.version_info[0:3]),
                "PyGTK-%s" % make_version(gtk.pygtk_version),
                "GTK-%s" % make_version(gtk.gtk_version),
            ])
        
        comment = "Several icons are courtesy of the TortoiseSVN project"

        self.set_website("http://tortoisehg.sourceforge.net/")
        self.set_name("TortoiseHg")
        self.set_version("(version %s)" % tortoise.version.get_version())
        self.set_wrap_license(True)
        self.set_copyright("Copyright 2007 TK Soh and others")
        self.set_license(file(license_file).read())
        self.set_comments("with " + lib_versions + "\n\n" + comment)
        self.set_logo(gtk.gdk.pixbuf_new_from_file(hg_icon))      
        self.set_icon_from_file(hg_icon)
        
        # somehow clicking on the Close button doesn't automatically
        # close the About dialog...
        self.connect('response', gtk.main_quit)

def run(*args, **opts):
    dialog = AboutDialog()
    dialog.show_all()
    gtk.gdk.threads_init()
    gtk.gdk.threads_enter()
    gtk.main()
    gtk.gdk.threads_leave()

if __name__ == "__main__":
    run()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.