main: Add a keyboard shortcuts screen bound to '?'
[git-cola.git] / cola / widgets / about.py
blob5230a184a7d12a27d2bd6922f63169f95333212a
1 from PyQt4 import QtGui
2 from PyQt4 import QtCore
3 from PyQt4 import QtWebKit
4 from PyQt4.QtCore import SIGNAL
7 from cola import qtutils
8 from cola import version
10 def launch_about_dialog():
11 """Launches the Help -> About dialog"""
12 view = AboutView(qtutils.active_window())
13 view.show()
14 view.set_version(version.version())
17 COPYRIGHT = """git-cola: The highly caffeinated git GUI v$VERSION
19 git-cola is a sweet, carbonated git GUI known for its
20 sugary flavor and caffeine-inspired features.
23 Copyright (C) 2007-2012, David Aguilar and contributors
25 This program is free software: you can redistribute it and/or
26 modify it under the terms of the GNU General Public License
27 version 2 as published by the Free Software Foundation.
29 This program is distributed in the hope that it will
30 be useful, but WITHOUT ANY WARRANTY; without even the
31 implied warranty of MERCHANTABILITY or
32 FITNESS FOR A PARTICULAR PURPOSE.
34 See the GNU General Public License for more details.
36 You should have received a copy of the
37 GNU General Public License along with this program.
38 If not, see http://www.gnu.org/licenses/.
40 """
42 class AboutView(QtGui.QDialog):
43 """Provides the git-cola 'About' dialog.
44 """
45 def __init__(self, parent=None):
46 QtGui.QDialog.__init__(self, parent)
48 self.setWindowTitle('About git-cola')
49 self.setStyleSheet('QWidget { background-color: white; color: #666; }')
51 self.setMinimumSize(QtCore.QSize(280, 420))
52 self.setMaximumSize(QtCore.QSize(280, 420))
54 self.ham = QtGui.QLabel(self)
55 self.ham.setGeometry(QtCore.QRect(0, -10, 291, 121))
56 self.ham.setPixmap(QtGui.QPixmap('images:logo-cola.png'))
58 self.spam = QtGui.QLabel(self)
59 self.spam.setGeometry(QtCore.QRect(10, 110, 261, 261))
61 font = QtGui.QFont()
62 font.setFamily('Sans Serif')
63 font.setPointSize(5)
64 self.spam.setFont(font)
66 self.spam.setTextFormat(QtCore.Qt.LogText)
67 self.spam.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
68 self.spam.setWordWrap(True)
69 self.spam.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
70 self.spam.setText(COPYRIGHT)
72 self.kthx = QtGui.QPushButton(self)
73 self.kthx.setGeometry(QtCore.QRect(60, 380, 160, 24))
74 self.kthx.setText('kthx bye')
75 self.kthx.setDefault(True)
77 self.connect(self.kthx, SIGNAL('clicked()'), self.accept)
79 def set_version(self, version):
80 """Sets the version field in the 'about' dialog"""
81 self.spam.setText(self.spam.text().replace('$VERSION', version))
84 def show_shortcuts():
85 html = """
86 <html>
87 <head>
88 <style type="text/css">
90 body {
91 font-family: Helvetica, Ubuntu, sans;
92 background-color: #303030;
93 color: #fff;
96 table.center {
97 width: 50%;
98 float: left;
99 padding-bottom: 20px;
102 td {
103 vertical-align: top;
106 td.title {
107 color: #ff6;
108 font-weight: bold;
111 td.shortcut {
112 font-family: Ubuntu Mono, Monaco, monospace;
113 color: #ff6;
114 text-align: right;
115 font-size: 0.8em;
118 span.title {
119 font-size: 1.3em;
120 font-weight: bold;
123 </style>
124 </head>
126 <body>
127 <span class="title">Keyboard shortcuts</span>
128 <hr />
130 <!-- Main actions -->
131 <table class="center">
132 <tr>
133 <td width="33%">&nbsp;</td>
134 <td>&nbsp;</td>
135 <td class="title">Main actions</td>
136 </tr>
137 <tr>
138 <td class="shortcut">Alt + a</td>
139 <td>:</td>
140 <td>Stage all modified files</td>
141 </tr>
142 <tr>
143 <td class="shortcut">Alt + u</td>
144 <td>:</td>
145 <td>Stage all untracked files</td>
146 </tr>
147 <tr>
148 <td class="shortcut">Ctrl + b</td>
149 <td>:</td>
150 <td>Create branch</td>
151 </tr>
152 <tr>
153 <td class="shortcut">Alt + b</td>
154 <td>:</td>
155 <td>Checkout branch</td>
156 </tr>
157 <tr>
158 <td class="shortcut">Ctrl + d</td>
159 <td>:</td>
160 <td>Show diffstat</td>
161 </tr>
162 <tr>
163 <td class="shortcut">Ctrl + e</td>
164 <td>:</td>
165 <td>Export patches</td>
166 </tr>
167 <tr>
168 <td class="shortcut">Ctrl + p</td>
169 <td>:</td>
170 <td>Cherry pick</td>
171 </tr>
172 <tr>
173 <td class="shortcut">Ctrl + r</td>
174 <td>:</td>
175 <td>Rescan / refresh repository status</td>
176 </tr>
177 <tr>
178 <td class="shortcut">Shift + Alt + s</td>
179 <td>:</td>
180 <td>Stash</td>
181 </tr>
182 <tr>
183 <td class="shortcut">?</td>
184 <td>:</td>
185 <td>Toggle keyboard shortcuts window</td>
186 </tr>
187 </table>
189 <!-- Diff Viewer -->
190 <table class="center">
191 <tr>
192 <td width="33%">&nbsp;</td>
193 <td>&nbsp;</td>
194 <td class="title">Diff viewer</td>
195 </tr>
196 <tr>
197 <td class="shortcut">s</td>
198 <td>:</td>
199 <td>Stage/unstage selected text or
200 stage/unstage the patch diff section (hunk) beneath
201 the text cursor when nothing is selected
202 </td>
203 </tr>
204 <tr>
205 <td class="shortcut">h</td>
206 <td>:</td>
207 <td>Stage/unstage the patch diff section (hunk) beneath
208 the text cursor
209 </td>
210 </tr>
211 <tr>
212 <td class="shortcut">Ctrl + a</td>
213 <td>:</td>
214 <td>Select All</td>
215 </tr>
216 <tr>
217 <td class="shortcut">Ctrl + c</td>
218 <td>:</td>
219 <td>Copy</td>
220 </tr>
221 </table>
223 <!-- Tree navigation -->
224 <table class="center">
225 <tr>
226 <td width="33%">&nbsp;</td>
227 <td>&nbsp;</td>
228 <td class="title">Tree navigation</td>
229 </tr>
230 <tr>
231 <td class="shortcut">h</td>
232 <td>:</td>
233 <td>Move to parent/collapse</td>
234 </tr>
235 <tr>
236 <td class="shortcut">j</td>
237 <td>:</td>
238 <td>Move down</td>
239 </tr>
240 <tr>
241 <td class="shortcut">k</td>
242 <td>:</td>
243 <td>Move up</td>
244 </tr>
245 <tr>
246 <td class="shortcut">l</td>
247 <td>:</td>
248 <td>Expand directory</td>
249 </tr>
250 </table>
252 <!-- Classic actions -->
253 <table class="center">
254 <tr>
255 <td width="33%">&nbsp;</td>
256 <td>&nbsp;</td>
257 <td class="title">Classic actions</td>
258 </tr>
259 <tr>
260 <td class="shortcut">Ctrl + e</td>
261 <td>:</td>
262 <td>Launch editor</td>
263 </tr>
264 <tr>
265 <td class="shortcut">Ctrl + s</td>
266 <td>:</td>
267 <td>Stage selected</td>
268 </tr>
269 <tr>
270 <td class="shortcut">Ctrl + u</td>
271 <td>:</td>
272 <td>Unstage selected</td>
273 </tr>
274 <tr>
275 <td class="shortcut">Ctrl + u</td>
276 <td>:</td>
277 <td>Unstage selected</td>
278 </tr>
279 <tr>
280 <td class="shortcut">Shift + Ctrl + h</td>
281 <td>:</td>
282 <td>View history</td>
283 </tr>
284 <tr>
285 <td class="shortcut">Ctrl + d</td>
286 <td>:</td>
287 <td>View diff using `git difftool`</td>
288 </tr>
289 <tr>
290 <td class="shortcut">Shift + Ctrl + d</td>
291 <td>:</td>
292 <td>View diff against predecessor</td>
293 </tr>
294 <tr>
295 <td class="shortcut">Ctrl + z</td>
296 <td>:</td>
297 <td>Revert uncommitted changes</td>
298 </tr>
299 </table>
300 </body>
302 try:
303 widget = show_shortcuts.widget
304 except AttributeError:
305 parent = qtutils.active_window()
306 widget = show_shortcuts.widget = QtGui.QDialog(parent)
307 widget.setWindowModality(QtCore.Qt.WindowModal)
308 widget.setAttribute(QtCore.Qt.WA_NoSystemBackground, True)
311 web = QtWebKit.QWebView(parent)
312 web.setHtml(html)
314 layout = QtGui.QHBoxLayout()
315 layout.setMargin(0)
316 layout.setSpacing(0)
317 layout.addWidget(web)
319 widget.setLayout(layout)
320 widget.resize(800, min(parent.height(), 600))
322 qtutils.add_action(widget, 'Close', widget.accept,
323 QtCore.Qt.Key_Question,
324 QtCore.Qt.Key_Enter,
325 QtCore.Qt.Key_Return)
326 widget.show()
327 return widget