PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/tortoisehg/hgqt/license.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 74 lines | 46 code | 15 blank | 13 comment | 0 complexity | 8c3c8784e4053c7b6a7f071dcbeef649 MD5 | raw file
 1# license.py - license 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 License dialog - PyQt4 version
12"""
13
14
15from PyQt4.QtCore import *
16from PyQt4.QtGui import *
17
18from tortoisehg.hgqt.i18n import _
19from tortoisehg.hgqt import qtlib
20from tortoisehg.util import paths
21
22
23class LicenseDialog(QDialog):
24    """Dialog for showing the TortoiseHg license"""
25    def __init__(self, parent=None):
26        super(LicenseDialog, self).__init__(parent)
27
28        self.setWindowIcon(qtlib.geticon('thg_logo'))
29        self.setWindowTitle(_('License'))
30        self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)
31        self.resize(700, 400)
32
33        self.lic_txt = QPlainTextEdit()
34        self.lic_txt.setFont(QFont('Monospace'))
35        self.lic_txt.setTextInteractionFlags(
36                Qt.TextSelectableByKeyboard|Qt.TextSelectableByMouse)
37        try:
38            lic = open(paths.get_license_path(), 'rb').read()
39            self.lic_txt.setPlainText(lic)
40        except (IOError):
41            pass
42
43        self.hspacer = QSpacerItem(40, 20,
44                QSizePolicy.Expanding, QSizePolicy.Minimum)
45        self.close_btn = QPushButton(_('&Close'))
46        self.close_btn.clicked.connect(self.close)
47
48        self.hbox = QHBoxLayout()
49        self.hbox.addItem(self.hspacer)
50        self.hbox.addWidget(self.close_btn)
51        self.vbox = QVBoxLayout()
52        self.vbox.setSpacing(6)
53        self.vbox.addWidget(self.lic_txt)
54        self.vbox.addLayout(self.hbox)
55
56        self.setLayout(self.vbox)
57        self._readsettings()
58        self.setModal(True)
59
60    def closeEvent(self, event):
61        self._writesettings()
62        super(LicenseDialog, self).closeEvent(event)
63
64    def _readsettings(self):
65        s = QSettings()
66        self.restoreGeometry(s.value('license/geom').toByteArray())
67
68    def _writesettings(self):
69        s = QSettings()
70        s.setValue('license/geom', self.saveGeometry())
71
72
73def run(ui, *args, **opts):
74    return LicenseDialog()