PageRenderTime 24ms CodeModel.GetById 16ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/tortoisehg/hgtk/about.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 106 lines | 82 code | 16 blank | 8 comment | 19 complexity | 71043e74ccf850c6083320963d5458df MD5 | raw file
  1# about.py - TortoiseHg About dialog
  2#
  3# Copyright 2007 TK Soh <teekaysoh@gmail.com>
  4# Copyright 2007 Steve Borho <steve@borho.org>
  5#
  6# This software may be used and distributed according to the terms of the
  7# GNU General Public License version 2, incorporated herein by reference.
  8
  9import os
 10import sys
 11import gtk
 12import urllib2
 13
 14from tortoisehg.util.i18n import _
 15from tortoisehg.util import version, paths, hglib, shlib
 16
 17from tortoisehg.hgtk import gtklib, hgtk
 18
 19_verurl = 'http://tortoisehg.bitbucket.org/curversion.txt'
 20
 21def url_handler(dialog, link, user_data):
 22    shlib.browse_url(link)
 23
 24gtk.about_dialog_set_url_hook(url_handler, None)
 25
 26def make_version(tuple):
 27    vers = ".".join([str(x) for x in tuple])
 28    return vers
 29
 30class AboutDialog(gtk.AboutDialog):
 31    def __init__(self):
 32        super(AboutDialog, self).__init__()
 33        gtklib.set_tortoise_keys(self)
 34
 35        lib_versions = ', '.join([
 36                "Mercurial-%s" % hglib.hgversion,
 37                "Python-%s" % make_version(sys.version_info[0:3]),
 38                "PyGTK-%s" % make_version(gtk.pygtk_version),
 39                "GTK-%s" % make_version(gtk.gtk_version),
 40            ])
 41
 42        comment = _("Several icons are courtesy of the TortoiseSVN project")
 43
 44        newver = (0,0,0)
 45        upgradeurl = 'http://tortoisehg.org'
 46        try:
 47            f = urllib2.urlopen(_verurl).read().splitlines()
 48            newver = tuple([int(p) for p in f[0].split('.')])
 49            upgradeurl = f[1] # generic download URL
 50            platform = sys.platform
 51            if platform == 'win32':
 52                from win32process import IsWow64Process as IsX64
 53                platform = IsX64() and 'x64' or 'x86'
 54            # linux2 for Linux, darwin for OSX
 55            for line in f[2:]:
 56                p, url = line.split(':')
 57                if platform == p:
 58                    upgradeurl = url.strip()
 59                    break
 60        except:
 61            pass
 62        ver = version.version()
 63        if '+' in ver:
 64            ver = ver[:ver.index('+')]
 65        try:
 66            curver = tuple([int(p) for p in ver.split('.')])
 67        except:
 68            curver = (0,0,0)
 69        if newver > curver:
 70            comment = _('A new version of TortoiseHg is ready for download!')
 71            self.set_website(upgradeurl)
 72        else:
 73            self.set_website('http://tortoisehg.org')
 74
 75        self.set_name("TortoiseHg")
 76        self.set_version(_("(version %s)") % version.version())
 77        if hasattr(self, 'set_wrap_license'):
 78            self.set_wrap_license(False)
 79        self.set_copyright(_("Copyright 2008-2010 Steve Borho and others"))
 80
 81        thg_logo = paths.get_tortoise_icon('thg_logo_92x50.png')
 82        thg_icon = paths.get_tortoise_icon('thg_logo.ico')
 83        try:
 84            license_file = paths.get_license_path()
 85            if license_file.endswith('.gz'):
 86                import gzip
 87                lic = gzip.open(license_file, 'rb').read()
 88            else:
 89                lic = open(license_file, 'rb').read()
 90            self.set_license(lic)
 91        except (ImportError, IOError):
 92            license = hgtk.shortlicense.splitlines()[1:]
 93            self.set_license('\n'.join(license))
 94
 95        self.set_comments(_("with %s") % lib_versions + "\n\n" + comment)
 96        if thg_logo:
 97            self.set_logo(gtk.gdk.pixbuf_new_from_file(thg_logo))
 98        if thg_icon:
 99            self.set_icon_from_file(thg_icon)
100        self.connect('response', self.response)
101
102    def response(self, widget, respid):
103        self.destroy()
104
105def run(_ui, *pats, **opts):
106    return AboutDialog()