Show More
@@ -247,7 +247,12 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
247 |
|
247 | |||
248 | action = QtGui.QAction('Select All', None) |
|
248 | action = QtGui.QAction('Select All', None) | |
249 | action.setEnabled(True) |
|
249 | action.setEnabled(True) | |
250 |
|
|
250 | selectall = QtGui.QKeySequence(QtGui.QKeySequence.SelectAll) | |
|
251 | if selectall.matches("Ctrl+A") and sys.platform != 'darwin': | |||
|
252 | # Only override the default if there is a collision. | |||
|
253 | # Qt ctrl = cmd on OSX, so the match gets a false positive on OSX. | |||
|
254 | selectall = "Ctrl+Shift+A" | |||
|
255 | action.setShortcut(selectall) | |||
251 | action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) |
|
256 | action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) | |
252 | action.triggered.connect(self.select_all) |
|
257 | action.triggered.connect(self.select_all) | |
253 | self.addAction(action) |
|
258 | self.addAction(action) | |
@@ -255,14 +260,14 b' class ConsoleWidget(LoggingConfigurable, QtGui.QWidget):' | |||||
255 |
|
260 | |||
256 | self.increase_font_size = QtGui.QAction("Bigger Font", |
|
261 | self.increase_font_size = QtGui.QAction("Bigger Font", | |
257 | self, |
|
262 | self, | |
258 |
shortcut= |
|
263 | shortcut=QtGui.QKeySequence.ZoomIn, | |
259 | statusTip="Increase the font size by one point", |
|
264 | statusTip="Increase the font size by one point", | |
260 | triggered=self._increase_font_size) |
|
265 | triggered=self._increase_font_size) | |
261 | self.addAction(self.increase_font_size) |
|
266 | self.addAction(self.increase_font_size) | |
262 |
|
267 | |||
263 | self.decrease_font_size = QtGui.QAction("Smaller Font", |
|
268 | self.decrease_font_size = QtGui.QAction("Smaller Font", | |
264 | self, |
|
269 | self, | |
265 |
shortcut= |
|
270 | shortcut=QtGui.QKeySequence.ZoomOut, | |
266 | statusTip="Decrease the font size by one point", |
|
271 | statusTip="Decrease the font size by one point", | |
267 | triggered=self._decrease_font_size) |
|
272 | triggered=self._decrease_font_size) | |
268 | self.addAction(self.decrease_font_size) |
|
273 | self.addAction(self.decrease_font_size) |
@@ -301,14 +301,21 b' class MainWindow(QtGui.QMainWindow):' | |||||
301 | return slave_list |
|
301 | return slave_list | |
302 |
|
302 | |||
303 | # Populate the menu bar with common actions and shortcuts |
|
303 | # Populate the menu bar with common actions and shortcuts | |
304 | def add_menu_action(self, menu, action): |
|
304 | def add_menu_action(self, menu, action, defer_shortcut=False): | |
305 | """Add action to menu as well as self |
|
305 | """Add action to menu as well as self | |
306 |
|
306 | |||
307 | So that when the menu bar is invisible, its actions are still available. |
|
307 | So that when the menu bar is invisible, its actions are still available. | |
|
308 | ||||
|
309 | If defer_shortcut is True, set the shortcut context to widget-only, | |||
|
310 | where it will avoid conflict with shortcuts already bound to the | |||
|
311 | widgets themselves. | |||
308 | """ |
|
312 | """ | |
309 | menu.addAction(action) |
|
313 | menu.addAction(action) | |
310 | self.addAction(action) |
|
314 | self.addAction(action) | |
311 |
|
315 | |||
|
316 | if defer_shortcut: | |||
|
317 | action.setShortcutContext(QtCore.Qt.WidgetShortcut) | |||
|
318 | ||||
312 | def init_menu_bar(self): |
|
319 | def init_menu_bar(self): | |
313 | #create menu in the order they should appear in the menu bar |
|
320 | #create menu in the order they should appear in the menu bar | |
314 | self.init_file_menu() |
|
321 | self.init_file_menu() | |
@@ -338,28 +345,30 b' class MainWindow(QtGui.QMainWindow):' | |||||
338 |
|
345 | |||
339 | self.close_action=QtGui.QAction("&Close Tab", |
|
346 | self.close_action=QtGui.QAction("&Close Tab", | |
340 | self, |
|
347 | self, | |
341 |
shortcut= |
|
348 | shortcut=QtGui.QKeySequence.Close, | |
342 | triggered=self.close_active_frontend |
|
349 | triggered=self.close_active_frontend | |
343 | ) |
|
350 | ) | |
344 | self.add_menu_action(self.file_menu, self.close_action) |
|
351 | self.add_menu_action(self.file_menu, self.close_action) | |
345 |
|
352 | |||
346 | self.export_action=QtGui.QAction("&Save to HTML/XHTML", |
|
353 | self.export_action=QtGui.QAction("&Save to HTML/XHTML", | |
347 | self, |
|
354 | self, | |
348 |
shortcut= |
|
355 | shortcut=QtGui.QKeySequence.Save, | |
349 | triggered=self.export_action_active_frontend |
|
356 | triggered=self.export_action_active_frontend | |
350 | ) |
|
357 | ) | |
351 | self.add_menu_action(self.file_menu, self.export_action) |
|
358 | self.add_menu_action(self.file_menu, self.export_action, True) | |
352 |
|
359 | |||
353 | self.file_menu.addSeparator() |
|
360 | self.file_menu.addSeparator() | |
354 |
|
361 | |||
355 | # Ctrl actually maps to Cmd on OSX, which avoids conflict with history |
|
362 | printkey = QtGui.QKeySequence(QtGui.QKeySequence.Print) | |
356 | # action, which is already bound to true Ctrl+P |
|
363 | if printkey.matches("Ctrl+P") and sys.platform != 'darwin': | |
357 | print_shortcut = "Ctrl+P" if sys.platform == 'darwin' else 'Ctrl+Shift+P' |
|
364 | # Only override the default if there is a collision. | |
|
365 | # Qt ctrl = cmd on OSX, so the match gets a false positive on OSX. | |||
|
366 | printkey = "Ctrl+Shift+P" | |||
358 | self.print_action = QtGui.QAction("&Print", |
|
367 | self.print_action = QtGui.QAction("&Print", | |
359 | self, |
|
368 | self, | |
360 |
shortcut=print |
|
369 | shortcut=printkey, | |
361 | triggered=self.print_action_active_frontend) |
|
370 | triggered=self.print_action_active_frontend) | |
362 | self.add_menu_action(self.file_menu, self.print_action) |
|
371 | self.add_menu_action(self.file_menu, self.print_action, True) | |
363 |
|
372 | |||
364 | if sys.platform != 'darwin': |
|
373 | if sys.platform != 'darwin': | |
365 | # OSX always has Quit in the Application menu, only add it |
|
374 | # OSX always has Quit in the Application menu, only add it | |
@@ -380,7 +389,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
380 |
|
389 | |||
381 | self.undo_action = QtGui.QAction("&Undo", |
|
390 | self.undo_action = QtGui.QAction("&Undo", | |
382 | self, |
|
391 | self, | |
383 |
shortcut= |
|
392 | shortcut=QtGui.QKeySequence.Undo, | |
384 | statusTip="Undo last action if possible", |
|
393 | statusTip="Undo last action if possible", | |
385 | triggered=self.undo_active_frontend |
|
394 | triggered=self.undo_active_frontend | |
386 | ) |
|
395 | ) | |
@@ -388,7 +397,7 b' class MainWindow(QtGui.QMainWindow):' | |||||
388 |
|
397 | |||
389 | self.redo_action = QtGui.QAction("&Redo", |
|
398 | self.redo_action = QtGui.QAction("&Redo", | |
390 | self, |
|
399 | self, | |
391 | shortcut="Ctrl+Shift+Z", |
|
400 | shortcut=QtGui.QKeySequence.Redo, | |
392 | statusTip="Redo last action if possible", |
|
401 | statusTip="Redo last action if possible", | |
393 | triggered=self.redo_active_frontend) |
|
402 | triggered=self.redo_active_frontend) | |
394 | self.add_menu_action(self.edit_menu, self.redo_action) |
|
403 | self.add_menu_action(self.edit_menu, self.redo_action) | |
@@ -400,37 +409,42 b' class MainWindow(QtGui.QMainWindow):' | |||||
400 | shortcut=QtGui.QKeySequence.Cut, |
|
409 | shortcut=QtGui.QKeySequence.Cut, | |
401 | triggered=self.cut_active_frontend |
|
410 | triggered=self.cut_active_frontend | |
402 | ) |
|
411 | ) | |
403 | self.add_menu_action(self.edit_menu, self.cut_action) |
|
412 | self.add_menu_action(self.edit_menu, self.cut_action, True) | |
404 |
|
413 | |||
405 | self.copy_action = QtGui.QAction("&Copy", |
|
414 | self.copy_action = QtGui.QAction("&Copy", | |
406 | self, |
|
415 | self, | |
407 | shortcut=QtGui.QKeySequence.Copy, |
|
416 | shortcut=QtGui.QKeySequence.Copy, | |
408 | triggered=self.copy_active_frontend |
|
417 | triggered=self.copy_active_frontend | |
409 | ) |
|
418 | ) | |
410 | self.add_menu_action(self.edit_menu, self.copy_action) |
|
419 | self.add_menu_action(self.edit_menu, self.copy_action, True) | |
411 |
|
420 | |||
412 | self.copy_raw_action = QtGui.QAction("Copy (&Raw Text)", |
|
421 | self.copy_raw_action = QtGui.QAction("Copy (&Raw Text)", | |
413 | self, |
|
422 | self, | |
414 | shortcut="Ctrl+Shift+C", |
|
423 | shortcut="Ctrl+Shift+C", | |
415 | triggered=self.copy_raw_active_frontend |
|
424 | triggered=self.copy_raw_active_frontend | |
416 | ) |
|
425 | ) | |
417 | self.add_menu_action(self.edit_menu, self.copy_raw_action) |
|
426 | self.add_menu_action(self.edit_menu, self.copy_raw_action, True) | |
418 |
|
427 | |||
419 | self.paste_action = QtGui.QAction("&Paste", |
|
428 | self.paste_action = QtGui.QAction("&Paste", | |
420 | self, |
|
429 | self, | |
421 | shortcut=QtGui.QKeySequence.Paste, |
|
430 | shortcut=QtGui.QKeySequence.Paste, | |
422 | triggered=self.paste_active_frontend |
|
431 | triggered=self.paste_active_frontend | |
423 | ) |
|
432 | ) | |
424 | self.add_menu_action(self.edit_menu, self.paste_action) |
|
433 | self.add_menu_action(self.edit_menu, self.paste_action, True) | |
425 |
|
434 | |||
426 | self.edit_menu.addSeparator() |
|
435 | self.edit_menu.addSeparator() | |
427 |
|
436 | |||
|
437 | selectall = QtGui.QKeySequence(QtGui.QKeySequence.SelectAll) | |||
|
438 | if selectall.matches("Ctrl+A") and sys.platform != 'darwin': | |||
|
439 | # Only override the default if there is a collision. | |||
|
440 | # Qt ctrl = cmd on OSX, so the match gets a false positive on OSX. | |||
|
441 | selectall = "Ctrl+Shift+A" | |||
428 | self.select_all_action = QtGui.QAction("Select &All", |
|
442 | self.select_all_action = QtGui.QAction("Select &All", | |
429 | self, |
|
443 | self, | |
430 |
shortcut= |
|
444 | shortcut=selectall, | |
431 | triggered=self.select_all_active_frontend |
|
445 | triggered=self.select_all_active_frontend | |
432 | ) |
|
446 | ) | |
433 | self.add_menu_action(self.edit_menu, self.select_all_action) |
|
447 | self.add_menu_action(self.edit_menu, self.select_all_action, True) | |
434 |
|
448 | |||
435 |
|
449 | |||
436 | def init_view_menu(self): |
|
450 | def init_view_menu(self): | |
@@ -457,24 +471,24 b' class MainWindow(QtGui.QMainWindow):' | |||||
457 |
|
471 | |||
458 | self.increase_font_size = QtGui.QAction("Zoom &In", |
|
472 | self.increase_font_size = QtGui.QAction("Zoom &In", | |
459 | self, |
|
473 | self, | |
460 | shortcut="Ctrl++", |
|
474 | shortcut=QtGui.QKeySequence.ZoomIn, | |
461 | triggered=self.increase_font_size_active_frontend |
|
475 | triggered=self.increase_font_size_active_frontend | |
462 | ) |
|
476 | ) | |
463 | self.add_menu_action(self.view_menu, self.increase_font_size) |
|
477 | self.add_menu_action(self.view_menu, self.increase_font_size, True) | |
464 |
|
478 | |||
465 | self.decrease_font_size = QtGui.QAction("Zoom &Out", |
|
479 | self.decrease_font_size = QtGui.QAction("Zoom &Out", | |
466 | self, |
|
480 | self, | |
467 | shortcut="Ctrl+-", |
|
481 | shortcut=QtGui.QKeySequence.ZoomOut, | |
468 | triggered=self.decrease_font_size_active_frontend |
|
482 | triggered=self.decrease_font_size_active_frontend | |
469 | ) |
|
483 | ) | |
470 | self.add_menu_action(self.view_menu, self.decrease_font_size) |
|
484 | self.add_menu_action(self.view_menu, self.decrease_font_size, True) | |
471 |
|
485 | |||
472 | self.reset_font_size = QtGui.QAction("Zoom &Reset", |
|
486 | self.reset_font_size = QtGui.QAction("Zoom &Reset", | |
473 | self, |
|
487 | self, | |
474 | shortcut="Ctrl+0", |
|
488 | shortcut="Ctrl+0", | |
475 | triggered=self.reset_font_size_active_frontend |
|
489 | triggered=self.reset_font_size_active_frontend | |
476 | ) |
|
490 | ) | |
477 | self.add_menu_action(self.view_menu, self.reset_font_size) |
|
491 | self.add_menu_action(self.view_menu, self.reset_font_size, True) | |
478 |
|
492 | |||
479 | self.view_menu.addSeparator() |
|
493 | self.view_menu.addSeparator() | |
480 |
|
494 | |||
@@ -696,16 +710,22 b' class MainWindow(QtGui.QMainWindow):' | |||||
696 | self.active_frontend.request_interrupt_kernel() |
|
710 | self.active_frontend.request_interrupt_kernel() | |
697 |
|
711 | |||
698 | def cut_active_frontend(self): |
|
712 | def cut_active_frontend(self): | |
699 |
self.active_frontend |
|
713 | widget = self.active_frontend | |
|
714 | if widget.can_cut(): | |||
|
715 | widget.cut() | |||
700 |
|
716 | |||
701 | def copy_active_frontend(self): |
|
717 | def copy_active_frontend(self): | |
702 |
self.active_frontend |
|
718 | widget = self.active_frontend | |
|
719 | if widget.can_copy(): | |||
|
720 | widget.copy() | |||
703 |
|
721 | |||
704 | def copy_raw_active_frontend(self): |
|
722 | def copy_raw_active_frontend(self): | |
705 | self.active_frontend._copy_raw_action.trigger() |
|
723 | self.active_frontend._copy_raw_action.trigger() | |
706 |
|
724 | |||
707 | def paste_active_frontend(self): |
|
725 | def paste_active_frontend(self): | |
708 |
self.active_frontend |
|
726 | widget = self.active_frontend | |
|
727 | if widget.can_paste(): | |||
|
728 | widget.paste() | |||
709 |
|
729 | |||
710 | def undo_active_frontend(self): |
|
730 | def undo_active_frontend(self): | |
711 | self.active_frontend.undo() |
|
731 | self.active_frontend.undo() |
General Comments 0
You need to be logged in to leave comments.
Login now