doc: fix release notes typo
[git-cola.git] / cola / widgets / about.py
blob78883ce9c3ac6f9e39acdb546dfcfdd5695303e0
1 from PyQt4 import QtGui
2 from PyQt4.QtCore import Qt
5 from cola import core
6 from cola import resources
7 from cola import qtutils
8 from cola import version
9 from cola.i18n import N_
10 from cola.widgets import defs
11 from cola.widgets.text import MonoTextView
13 def launch_about_dialog():
14 """Launches the Help -> About dialog"""
15 view = AboutView(qtutils.active_window())
16 view.set_version(version.version())
17 view.show()
20 COPYRIGHT = """git-cola: The highly caffeinated git GUI v$VERSION
22 Copyright (C) 2007-2012, David Aguilar and contributors
24 This program is free software: you can redistribute it and/or
25 modify it under the terms of the GNU General Public License
26 version 2 as published by the Free Software Foundation.
28 This program is distributed in the hope that it will
29 be useful, but WITHOUT ANY WARRANTY; without even the
30 implied warranty of MERCHANTABILITY or
31 FITNESS FOR A PARTICULAR PURPOSE.
33 See the GNU General Public License for more details.
35 You should have received a copy of the
36 GNU General Public License along with this program.
37 If not, see http://www.gnu.org/licenses/.
39 """
41 class AboutView(QtGui.QDialog):
42 """Provides the git-cola 'About' dialog.
43 """
44 def __init__(self, parent=None):
45 QtGui.QDialog.__init__(self, parent)
47 self.setWindowTitle(N_('About git-cola'))
48 self.setWindowModality(Qt.WindowModal)
50 self.label = QtGui.QLabel()
51 self.pixmap = QtGui.QPixmap('icons:logo-top.png')
52 #self.label.setStyleSheet('QWidget {background: #000; }')
53 self.label.setPixmap(self.pixmap)
54 self.label.setAlignment(Qt.AlignRight | Qt.AlignTop)
56 palette = self.label.palette()
57 palette.setColor(QtGui.QPalette.Window, Qt.black)
58 self.label.setAutoFillBackground(True)
59 self.label.setPalette(palette)
61 self.text = MonoTextView(self)
62 self.text.setReadOnly(True)
63 self.text.setPlainText(COPYRIGHT)
65 self.close_button = QtGui.QPushButton()
66 self.close_button.setText(N_('Close'))
67 self.close_button.setDefault(True)
69 self.button_layout = QtGui.QHBoxLayout()
70 self.button_layout.addStretch()
71 self.button_layout.addWidget(self.close_button)
73 self.main_layout = QtGui.QVBoxLayout()
74 self.main_layout.setMargin(0)
75 self.main_layout.setSpacing(defs.spacing)
77 self.main_layout.addWidget(self.label)
78 self.main_layout.addWidget(self.text)
79 self.main_layout.addLayout(self.button_layout)
80 self.setLayout(self.main_layout)
82 self.resize(666, 420)
84 qtutils.connect_button(self.close_button, self.accept)
86 def set_version(self, version):
87 """Sets the version field in the 'about' dialog"""
88 self.text.setPlainText(self.text.toPlainText().replace('$VERSION', version))
91 def show_shortcuts():
92 try:
93 from PyQt4 import QtWebKit
94 except ImportError:
95 # redhat disabled QtWebKit in their qt build but don't punish the
96 # users
97 qtutils.critical(N_('This PyQt4 does not include QtWebKit.\n'
98 'The keyboard shortcuts feature is unavailable.'))
99 return
101 try:
102 html = show_shortcuts.html
103 except AttributeError:
104 hotkeys = resources.doc(N_('hotkeys.html'))
105 html = show_shortcuts.html = core.read(hotkeys)
107 try:
108 widget = show_shortcuts.widget
109 except AttributeError:
110 parent = qtutils.active_window()
111 widget = show_shortcuts.widget = QtGui.QDialog(parent)
112 widget.setWindowModality(Qt.WindowModal)
114 web = QtWebKit.QWebView(parent)
115 web.setHtml(html)
117 layout = QtGui.QHBoxLayout()
118 layout.setMargin(0)
119 layout.setSpacing(0)
120 layout.addWidget(web)
122 widget.setWindowTitle(N_('Shortcuts'))
123 widget.setLayout(layout)
124 widget.resize(800, min(parent.height(), 600))
126 qtutils.add_action(widget, N_('Close'), widget.accept,
127 Qt.Key_Question,
128 Qt.Key_Enter,
129 Qt.Key_Return)
130 widget.show()
131 return widget