PageRenderTime 31ms CodeModel.GetById 10ms app.highlight 17ms RepoModel.GetById 2ms app.codeStats 0ms

/tortoisehg/hgqt/about.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 194 lines | 162 code | 17 blank | 15 comment | 4 complexity | 434fcf6dfe96997b2048572299a60ea5 MD5 | raw file
  1# about.py - About dialog for TortoiseHg
  2#
  3# Copyright 2007 TK Soh <teekaysoh@gmail.com>
  4# Copyright 2007 Steve Borho <steve@borho.org>
  5# Copyright 2010 Yuki KODAMA <endflow.net@gmail.com>
  6# Copyright 2010 Johan Samyn <johan.samyn@gmail.com>
  7#
  8# This software may be used and distributed according to the terms of the
  9# GNU General Public License version 2, incorporated herein by reference.
 10"""
 11TortoiseHg About dialog - PyQt4 version
 12"""
 13
 14import os, sys, urllib2
 15
 16from tortoisehg.hgqt.i18n import _
 17from tortoisehg.hgqt import qtlib
 18from tortoisehg.util import version, hglib, shlib, paths
 19
 20from PyQt4.QtCore import *
 21from PyQt4.QtGui import *
 22
 23class AboutDialog(QDialog):
 24    """Dialog for showing info about TortoiseHg"""
 25
 26    def __init__(self, parent=None):
 27        super(AboutDialog, self).__init__(parent)
 28
 29        self.updateInfo = {}
 30        self.uthread = None
 31
 32        self.setWindowIcon(qtlib.geticon('thg_logo'))
 33        self.setWindowTitle(_('About'))
 34        self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
 35
 36        self.vbox = QVBoxLayout()
 37        self.vbox.setSpacing(8)
 38
 39        self.logo_lbl = QLabel()
 40        self.logo_lbl.setMinimumSize(QSize(92, 50))
 41        self.logo_lbl.setScaledContents(False)
 42        self.logo_lbl.setAlignment(Qt.AlignCenter)
 43        thglogofile = paths.get_tortoise_icon('thg_logo_92x50.png')
 44        self.logo_lbl.setPixmap(QPixmap(thglogofile))
 45        self.vbox.addWidget(self.logo_lbl)
 46
 47        self.name_version_libs_lbl = QLabel()
 48        self.name_version_libs_lbl.setText(' ')
 49        self.name_version_libs_lbl.setAlignment(Qt.AlignCenter)
 50        self.name_version_libs_lbl.setTextInteractionFlags(
 51                Qt.TextSelectableByMouse)
 52        self.vbox.addWidget(self.name_version_libs_lbl)
 53        self.getVersionInfo()
 54
 55        self.copyright_lbl = QLabel()
 56        self.copyright_lbl.setAlignment(Qt.AlignCenter)
 57        self.copyright_lbl.setText('\n'
 58                + _('Copyright 2008-2010 Steve Borho and others'))
 59        self.vbox.addWidget(self.copyright_lbl)
 60        self.courtesy_lbl = QLabel()
 61        self.courtesy_lbl.setAlignment(Qt.AlignCenter)
 62        self.courtesy_lbl.setText(
 63              _('Several icons are courtesy of the TortoiseSVN project' + '\n'))
 64        self.vbox.addWidget(self.courtesy_lbl)
 65
 66        self.download_url_lbl = QLabel()
 67        self.download_url_lbl.setAlignment(Qt.AlignCenter)
 68        self.download_url_lbl.setMouseTracking(True)
 69        self.download_url_lbl.setAlignment(Qt.AlignCenter)
 70        self.download_url_lbl.setTextInteractionFlags(Qt.LinksAccessibleByMouse)
 71        self.download_url_lbl.setOpenExternalLinks(True)
 72        self.download_url_lbl.setText('<a href=%s>%s</a>' %
 73                ('http://tortoisehg.org', _('You can visit our site here')))
 74        self.vbox.addWidget(self.download_url_lbl)
 75
 76        # Let's have some space between the url and the buttons.
 77        self.blancline_lbl = QLabel()
 78        self.vbox.addWidget(self.blancline_lbl)
 79
 80        self.hbox = QHBoxLayout()
 81        self.license_btn = QPushButton()
 82        self.license_btn.setText(_('&License'))
 83        self.license_btn.setAutoDefault(False)
 84        self.license_btn.clicked.connect(self.showLicense)
 85        self.hspacer = QSpacerItem(40, 20,
 86                QSizePolicy.Expanding, QSizePolicy.Minimum)
 87        self.close_btn = QPushButton()
 88        self.close_btn.setText(_('&Close'))
 89        self.close_btn.setDefault(True)
 90        self.close_btn.clicked.connect(self.close)
 91        self.hbox.addWidget(self.license_btn)
 92        self.hbox.addItem(self.hspacer)
 93        self.hbox.addWidget(self.close_btn)
 94        self.vbox.addLayout(self.hbox)
 95
 96        self.setLayout(self.vbox)
 97        self.layout().setSizeConstraint(QLayout.SetFixedSize)
 98        self._readsettings()
 99
100        # Spawn it later, so that the dialog gets visible quickly.
101        QTimer.singleShot(0, self.getUpdateInfo)
102
103    def getVersionInfo(self):
104        def make_version(tuple):
105            vers = ".".join([str(x) for x in tuple])
106            return vers
107        thgv = (_('version %s') % version.version())
108        libv = (_('with Mercurial-%s, Python-%s, PyQt-%s, Qt-%s') % \
109              (hglib.hgversion, make_version(sys.version_info[0:3]),
110              PYQT_VERSION_STR, QT_VERSION_STR))
111        thgv = hglib.fromunicode(thgv)
112        libv = hglib.fromunicode(libv)
113        par = ('<p style=\" margin-top:0px; margin-bottom:6px;\">'
114                '<span style=\"font-size:%spt; font-weight:600;\">'
115                '%s</span></p>')
116        name = (par % (14, 'TortoiseHg'))
117        thgv = (par % (10, thgv))
118        thgv = hglib.fromunicode(thgv)
119        nvl = _(''.join([name, thgv, libv]))
120        self.name_version_libs_lbl.setText(nvl)
121
122    @pyqtSlot()
123    def getUpdateInfo(self):
124        self.uthread = AboutUpdateThread()
125        self.uthread.finished.connect(self.uFinished)
126        self.uthread.start()
127
128    def uFinished(self):
129        self.uthread.wait()
130        urldata = self.uthread.urldata
131        self.uthread = None
132        if urldata:
133            self.download_url_lbl.setText(urldata)
134
135    def showLicense(self):
136        from tortoisehg.hgqt import license
137        ld = license.LicenseDialog(self)
138        ld.show()
139
140    def closeEvent(self, event):
141        if self.uthread:
142            self.uthread.wait()
143        self._writesettings()
144        super(AboutDialog, self).closeEvent(event)
145
146    def _readsettings(self):
147        s = QSettings()
148        self.restoreGeometry(s.value('about/geom').toByteArray())
149
150    def _writesettings(self):
151        s = QSettings()
152        s.setValue('about/geom', self.saveGeometry())
153
154
155class AboutUpdateThread(QThread):
156    'Background thread for getting update info'
157    def __init__(self):
158        super(AboutUpdateThread, self).__init__()
159
160    urldata = ''
161
162    def run(self):
163        verurl = 'http://tortoisehg.bitbucket.org/curversion.txt'
164        newver = (0,0,0)
165        try:
166            f = urllib2.urlopen(verurl).read().splitlines()
167            newver = tuple([int(p) for p in f[0].split('.')])
168            upgradeurl = f[1] # generic download URL
169            platform = sys.platform
170            if platform == 'win32':
171                from win32process import IsWow64Process as IsX64
172                platform = IsX64() and 'x64' or 'x86'
173            # linux2 for Linux, darwin for OSX
174            for line in f[2:]:
175                p, url = line.split(':')
176                if platform == p:
177                    upgradeurl = url.strip()
178                    break
179        except:
180            pass
181        try:
182            thgv = version.version()
183            if '+' in thgv:
184                thgv = thgv[:thgv.index('+')]
185            curver = tuple([int(p) for p in thgv.split('.')])
186        except Exception, e:
187            curver = (0,0,0)
188        if newver > curver:
189            url_lbl = _('A new version of TortoiseHg is ready for download!')
190            self.urldata = ('<a href=%s>%s</a>' % (upgradeurl, url_lbl))
191
192
193def run(ui, *pats, **opts):
194    return AboutDialog()