Show More
This diff has been collapsed as it changes many lines, (577 lines changed) Show them Hide them | |||||
@@ -78,19 +78,36 b' class MainWindow(QtGui.QMainWindow):' | |||||
78 | #--------------------------------------------------------------------------- |
|
78 | #--------------------------------------------------------------------------- | |
79 |
|
79 | |||
80 | def __init__(self, app, frontend, existing=False, may_close=True, |
|
80 | def __init__(self, app, frontend, existing=False, may_close=True, | |
81 |
confirm_exit=True |
|
81 | confirm_exit=True, | |
82 | """ Create a MainWindow for the specified FrontendWidget. |
|
82 | new_frontend_factory=None, slave_frontend_factory=None, | |
|
83 | ): | |||
|
84 | """ Create a tabbed MainWindow for managing IPython FrontendWidgets | |||
83 |
|
85 | |||
84 | The app is passed as an argument to allow for different |
|
86 | Parameters | |
85 | closing behavior depending on whether we are the Kernel's parent. |
|
87 | ---------- | |
86 |
|
88 | |||
87 | If existing is True, then this Console does not own the Kernel. |
|
89 | app : reference to QApplication parent | |
88 |
|
90 | frontend : IPythonWidget | ||
89 | If may_close is True, then this Console is permitted to close the kernel |
|
91 | The first IPython frontend to start with | |
|
92 | existing : bool, optional | |||
|
93 | Whether the first frontend is connected to en existing Kernel, | |||
|
94 | or if we own it. | |||
|
95 | may_close : bool, optional | |||
|
96 | Whether we are permitted to close the kernel (determines close dialog behavior) | |||
|
97 | confirm_exit : bool, optional | |||
|
98 | Whether we should prompt on close of tabs | |||
|
99 | new_frontend_factory : callable | |||
|
100 | A callable that returns a new IPythonWidget instance, attached to | |||
|
101 | its own running kernel. | |||
|
102 | slave_frontend_factory : callable | |||
|
103 | A callable that takes an existing IPythonWidget, and returns a new | |||
|
104 | IPythonWidget instance, attached to the same kernel. | |||
90 | """ |
|
105 | """ | |
91 |
|
106 | |||
92 | super(MainWindow, self).__init__() |
|
107 | super(MainWindow, self).__init__() | |
93 | self._app = app |
|
108 | self._app = app | |
|
109 | self.new_frontend_factory = new_frontend_factory | |||
|
110 | self.slave_frontend_factory = slave_frontend_factory | |||
94 |
|
111 | |||
95 | self.tab_widget = QtGui.QTabWidget(self) |
|
112 | self.tab_widget = QtGui.QTabWidget(self) | |
96 | self.tab_widget.setDocumentMode(True) |
|
113 | self.tab_widget.setDocumentMode(True) | |
@@ -120,6 +137,24 b' class MainWindow(QtGui.QMainWindow):' | |||||
120 | @property |
|
137 | @property | |
121 | def active_frontend(self): |
|
138 | def active_frontend(self): | |
122 | return self.tab_widget.currentWidget() |
|
139 | return self.tab_widget.currentWidget() | |
|
140 | ||||
|
141 | def create_tab_with_new_frontend(self): | |||
|
142 | """create a new frontend and attach it to a new tab""" | |||
|
143 | widget = self.new_frontend_factory() | |||
|
144 | self.add_tab_with_frontend(widget) | |||
|
145 | ||||
|
146 | def create_tab_with_current_kernel(self): | |||
|
147 | """create a new frontend attached to the same kernel as the current tab""" | |||
|
148 | current_widget = self.tab_widget.currentWidget() | |||
|
149 | current_widget_index = self.tab_widget.indexOf(current_widget) | |||
|
150 | current_widget_name = self.tab_widget.tabText(current_widget_index) | |||
|
151 | widget = self.slave_frontend_factory(current_widget) | |||
|
152 | if 'slave' in current_widget_name: | |||
|
153 | # don't keep stacking slaves | |||
|
154 | name = current_widget_name | |||
|
155 | else: | |||
|
156 | name = str('('+current_widget_name+') slave') | |||
|
157 | self.add_tab_with_frontend(widget,name=name) | |||
123 |
|
158 | |||
124 | def close_tab(self,current_tab): |
|
159 | def close_tab(self,current_tab): | |
125 | """ Called when you need to try to close a tab. |
|
160 | """ Called when you need to try to close a tab. | |
@@ -314,190 +349,257 b' class MainWindow(QtGui.QMainWindow):' | |||||
314 |
|
349 | |||
315 | return slave_list |
|
350 | return slave_list | |
316 |
|
351 | |||
317 | # MenuBar is always present on Mac Os, so let's populate it with possible |
|
352 | # Populate the menu bar with common actions and shortcuts | |
318 | # action, don't do it on other platform as some user might not want the |
|
353 | def add_menu_action(self, menu, action): | |
319 | # menu bar, or give them an option to remove it |
|
354 | """Add action to menu as well as self | |
|
355 | ||||
|
356 | So that when the menu bar is invisible, its actions are still available. | |||
|
357 | """ | |||
|
358 | menu.addAction(action) | |||
|
359 | self.addAction(action) | |||
|
360 | ||||
320 | def init_menu_bar(self): |
|
361 | def init_menu_bar(self): | |
321 | #create menu in the order they should appear in the menu bar |
|
362 | #create menu in the order they should appear in the menu bar | |
|
363 | self.init_file_menu() | |||
|
364 | self.init_edit_menu() | |||
|
365 | self.init_view_menu() | |||
|
366 | self.init_kernel_menu() | |||
|
367 | self.init_magic_menu() | |||
|
368 | self.init_window_menu() | |||
|
369 | self.init_help_menu() | |||
|
370 | ||||
|
371 | def init_file_menu(self): | |||
322 | self.file_menu = self.menuBar().addMenu("&File") |
|
372 | self.file_menu = self.menuBar().addMenu("&File") | |
323 | self.edit_menu = self.menuBar().addMenu("&Edit") |
|
373 | ||
324 | self.kernel_menu = self.menuBar().addMenu("&Kernel") |
|
374 | self.new_kernel_tab_act = QtGui.QAction("New Tab with &New kernel", | |
325 | self.window_menu = self.menuBar().addMenu("&Window") |
|
375 | self, | |
326 | self.magic_menu = self.menuBar().addMenu("&Magic") |
|
376 | shortcut="Ctrl+T", | |
327 | self.all_magic_menu = self.magic_menu.addMenu("&All Magics") |
|
377 | triggered=self.create_tab_with_new_frontend) | |
328 |
|
378 | self.add_menu_action(self.file_menu, self.new_kernel_tab_act) | ||
329 | # please keep the Help menu in Mac Os even if empty. It will |
|
|||
330 | # automatically contain a search field to search inside menus and |
|
|||
331 | # please keep it spelled in English, as long as Qt Doesn't support |
|
|||
332 | # a QAction.MenuRole like HelpMenuRole otherwise it will loose |
|
|||
333 | # this search field fonctionnality |
|
|||
334 |
|
379 | |||
335 | self.help_menu = self.menuBar().addMenu("&Help") |
|
380 | self.slave_kernel_tab_act = QtGui.QAction("New Tab with Sa&me kernel", | |
|
381 | self, | |||
|
382 | shortcut="Ctrl+Shift+T", | |||
|
383 | triggered=self.create_tab_with_current_kernel) | |||
|
384 | self.add_menu_action(self.file_menu, self.slave_kernel_tab_act) | |||
|
385 | ||||
|
386 | self.file_menu.addSeparator() | |||
336 |
|
387 | |||
337 |
self. |
|
388 | self.close_action=QtGui.QAction("&Close Tab", | |
338 | self, |
|
389 | self, | |
339 |
shortcut="Ctrl+ |
|
390 | shortcut="Ctrl+W", | |
340 |
triggered=self. |
|
391 | triggered=self.close_active_frontend | |
341 | self.file_menu.addAction(self.print_action) |
|
392 | ) | |
|
393 | self.add_menu_action(self.file_menu, self.close_action) | |||
342 |
|
394 | |||
343 |
self.export_action=QtGui.QAction(" |
|
395 | self.export_action=QtGui.QAction("&Save to HTML/XHTML", | |
344 | self, |
|
396 | self, | |
345 | shortcut="Ctrl+S", |
|
397 | shortcut="Ctrl+S", | |
346 | triggered=self.export_action_active_frontend |
|
398 | triggered=self.export_action_active_frontend | |
347 | ) |
|
399 | ) | |
348 |
self.file_menu |
|
400 | self.add_menu_action(self.file_menu, self.export_action) | |
349 |
|
401 | |||
350 | self.select_all_action = QtGui.QAction("Select &All", |
|
402 | self.file_menu.addSeparator() | |
|
403 | ||||
|
404 | # Ctrl actually maps to Cmd on OSX, which avoids conflict with history | |||
|
405 | # action, which is already bound to true Ctrl+P | |||
|
406 | print_shortcut = "Ctrl+P" if sys.platform == 'darwin' else 'Ctrl+Shift+P' | |||
|
407 | self.print_action = QtGui.QAction("&Print", | |||
351 | self, |
|
408 | self, | |
352 |
shortcut= |
|
409 | shortcut=print_shortcut, | |
353 |
triggered=self. |
|
410 | triggered=self.print_action_active_frontend) | |
|
411 | self.add_menu_action(self.file_menu, self.print_action) | |||
|
412 | ||||
|
413 | if sys.platform == 'darwin': | |||
|
414 | # OSX always has Quit in the Application menu, only add it | |||
|
415 | # to the File menu elsewhere. | |||
|
416 | ||||
|
417 | self.file_menu.addSeparator() | |||
|
418 | ||||
|
419 | self.quit_action = QtGui.QAction("&Quit", | |||
|
420 | self, | |||
|
421 | shortcut=QtGui.QKeySequence.Quit, | |||
|
422 | triggered=self.close, | |||
354 | ) |
|
423 | ) | |
355 | self.file_menu.addAction(self.select_all_action) |
|
424 | self.add_menu_action(self.file_menu, self.quit_action) | |
356 |
|
425 | |||
357 | self.paste_action = QtGui.QAction("&Paste", |
|
426 | ||
|
427 | def init_edit_menu(self): | |||
|
428 | self.edit_menu = self.menuBar().addMenu("&Edit") | |||
|
429 | ||||
|
430 | self.undo_action = QtGui.QAction("&Undo", | |||
358 | self, |
|
431 | self, | |
359 |
shortcut= |
|
432 | shortcut="Ctrl+Z", | |
360 | triggered=self.paste_active_frontend |
|
433 | statusTip="Undo last action if possible", | |
|
434 | triggered=self.undo_active_frontend | |||
|
435 | ) | |||
|
436 | self.add_menu_action(self.edit_menu, self.undo_action) | |||
|
437 | ||||
|
438 | self.redo_action = QtGui.QAction("&Redo", | |||
|
439 | self, | |||
|
440 | shortcut="Ctrl+Shift+Z", | |||
|
441 | statusTip="Redo last action if possible", | |||
|
442 | triggered=self.redo_active_frontend) | |||
|
443 | self.add_menu_action(self.edit_menu, self.redo_action) | |||
|
444 | ||||
|
445 | self.edit_menu.addSeparator() | |||
|
446 | ||||
|
447 | self.cut_action = QtGui.QAction("&Cut", | |||
|
448 | self, | |||
|
449 | shortcut=QtGui.QKeySequence.Cut, | |||
|
450 | triggered=self.cut_active_frontend | |||
361 | ) |
|
451 | ) | |
362 |
self. |
|
452 | self.add_menu_action(self.edit_menu, self.cut_action) | |
363 |
|
453 | |||
364 | self.copy_action = QtGui.QAction("&Copy", |
|
454 | self.copy_action = QtGui.QAction("&Copy", | |
365 | self, |
|
455 | self, | |
366 | shortcut=QtGui.QKeySequence.Copy, |
|
456 | shortcut=QtGui.QKeySequence.Copy, | |
367 | triggered=self.copy_active_frontend |
|
457 | triggered=self.copy_active_frontend | |
368 | ) |
|
458 | ) | |
369 |
self.edit_menu |
|
459 | self.add_menu_action(self.edit_menu, self.copy_action) | |
370 |
|
460 | |||
371 | self.copy_raw_action = QtGui.QAction("Copy (&Raw Text)", |
|
461 | self.copy_raw_action = QtGui.QAction("Copy (&Raw Text)", | |
372 | self, |
|
462 | self, | |
373 | shortcut="Ctrl+Shift+C", |
|
463 | shortcut="Ctrl+Shift+C", | |
374 | triggered=self.copy_raw_active_frontend |
|
464 | triggered=self.copy_raw_active_frontend | |
375 | ) |
|
465 | ) | |
376 |
self.edit_menu |
|
466 | self.add_menu_action(self.edit_menu, self.copy_raw_action) | |
377 |
|
467 | |||
378 |
self. |
|
468 | self.paste_action = QtGui.QAction("&Paste", | |
379 | self, |
|
469 | self, | |
380 |
shortcut=QtGui.QKeySequence. |
|
470 | shortcut=QtGui.QKeySequence.Paste, | |
381 |
triggered=self. |
|
471 | triggered=self.paste_active_frontend | |
382 | ) |
|
472 | ) | |
383 |
self. |
|
473 | self.add_menu_action(self.edit_menu, self.paste_action) | |
384 |
|
474 | |||
385 | self.edit_menu.addSeparator() |
|
475 | self.edit_menu.addSeparator() | |
386 |
|
476 | |||
387 |
self. |
|
477 | self.select_all_action = QtGui.QAction("Select &All", | |
388 | self, |
|
478 | self, | |
389 |
shortcut="Ctrl+ |
|
479 | shortcut="Ctrl+A", | |
390 | statusTip="Undo last action if possible", |
|
480 | triggered=self.select_all_active_frontend | |
391 | triggered=self.undo_active_frontend |
|
|||
392 | ) |
|
481 | ) | |
393 | self.edit_menu.addAction(self.undo_action) |
|
482 | self.add_menu_action(self.edit_menu, self.select_all_action) | |
394 |
|
483 | |||
395 | self.redo_action = QtGui.QAction("&Redo", |
|
484 | ||
|
485 | def init_view_menu(self): | |||
|
486 | self.view_menu = self.menuBar().addMenu("&View") | |||
|
487 | ||||
|
488 | if sys.platform != 'darwin': | |||
|
489 | # disable on OSX, where there is always a menu bar | |||
|
490 | self.toggle_menu_bar_act = QtGui.QAction("Toggle &Menu Bar", | |||
|
491 | self, | |||
|
492 | shortcut="Ctrl+Meta+M", | |||
|
493 | statusTip="Toggle visibility of menubar", | |||
|
494 | triggered=self.toggle_menu_bar) | |||
|
495 | self.add_menu_action(self.view_menu, self.toggle_menu_bar_act) | |||
|
496 | ||||
|
497 | fs_key = "Ctrl+Meta+F" if sys.platform == 'darwin' else "F11" | |||
|
498 | self.full_screen_act = QtGui.QAction("&Full Screen", | |||
396 | self, |
|
499 | self, | |
397 |
shortcut= |
|
500 | shortcut=fs_key, | |
398 | statusTip="Redo last action if possible", |
|
501 | statusTip="Toggle between Fullscreen and Normal Size", | |
399 |
triggered=self. |
|
502 | triggered=self.toggleFullScreen) | |
400 |
self. |
|
503 | self.add_menu_action(self.view_menu, self.full_screen_act) | |
401 |
|
504 | |||
402 |
self. |
|
505 | self.view_menu.addSeparator() | |
403 |
|
506 | |||
404 |
self.increase_font_size = QtGui.QAction("&In |
|
507 | self.increase_font_size = QtGui.QAction("Zoom &In", | |
405 | self, |
|
508 | self, | |
406 | shortcut="Ctrl++", |
|
509 | shortcut="Ctrl++", | |
407 | triggered=self.increase_font_size_active_frontend |
|
510 | triggered=self.increase_font_size_active_frontend | |
408 | ) |
|
511 | ) | |
409 |
self. |
|
512 | self.add_menu_action(self.view_menu, self.increase_font_size) | |
410 |
|
513 | |||
411 |
self.decrease_font_size = QtGui.QAction(" |
|
514 | self.decrease_font_size = QtGui.QAction("Zoom &Out", | |
412 | self, |
|
515 | self, | |
413 | shortcut="Ctrl+-", |
|
516 | shortcut="Ctrl+-", | |
414 | triggered=self.decrease_font_size_active_frontend |
|
517 | triggered=self.decrease_font_size_active_frontend | |
415 | ) |
|
518 | ) | |
416 |
self. |
|
519 | self.add_menu_action(self.view_menu, self.decrease_font_size) | |
417 |
|
520 | |||
418 |
self.reset_font_size = QtGui.QAction("&Reset |
|
521 | self.reset_font_size = QtGui.QAction("Zoom &Reset", | |
419 | self, |
|
522 | self, | |
420 | shortcut="Ctrl+0", |
|
523 | shortcut="Ctrl+0", | |
421 | triggered=self.reset_font_size_active_frontend |
|
524 | triggered=self.reset_font_size_active_frontend | |
422 | ) |
|
525 | ) | |
423 |
self. |
|
526 | self.add_menu_action(self.view_menu, self.reset_font_size) | |
424 |
|
527 | |||
425 |
self. |
|
528 | self.view_menu.addSeparator() | |
426 |
|
529 | |||
|
530 | self.clear_action = QtGui.QAction("&Clear Screen", | |||
|
531 | self, | |||
|
532 | shortcut='Ctrl+L', | |||
|
533 | statusTip="Clear the console", | |||
|
534 | triggered=self.clear_magic_active_frontend) | |||
|
535 | self.add_menu_action(self.view_menu, self.clear_action) | |||
|
536 | ||||
|
537 | def init_kernel_menu(self): | |||
|
538 | self.kernel_menu = self.menuBar().addMenu("&Kernel") | |||
|
539 | # Qt on OSX maps Ctrl to Cmd, and Meta to Ctrl | |||
|
540 | # keep the signal shortcuts to ctrl, rather than | |||
|
541 | # platform-default like we do elsewhere. | |||
|
542 | ||||
|
543 | ctrl = "Meta" if sys.platform == 'darwin' else "Ctrl" | |||
|
544 | ||||
|
545 | self.interrupt_kernel_action = QtGui.QAction("Interrupt current Kernel", | |||
|
546 | self, | |||
|
547 | triggered=self.interrupt_kernel_active_frontend, | |||
|
548 | shortcut=ctrl+"+C", | |||
|
549 | ) | |||
|
550 | self.add_menu_action(self.kernel_menu, self.interrupt_kernel_action) | |||
|
551 | ||||
|
552 | self.restart_kernel_action = QtGui.QAction("Restart current Kernel", | |||
|
553 | self, | |||
|
554 | triggered=self.restart_kernel_active_frontend, | |||
|
555 | shortcut=ctrl+"+.", | |||
|
556 | ) | |||
|
557 | self.add_menu_action(self.kernel_menu, self.restart_kernel_action) | |||
|
558 | ||||
|
559 | self.kernel_menu.addSeparator() | |||
|
560 | ||||
|
561 | def init_magic_menu(self): | |||
|
562 | self.magic_menu = self.menuBar().addMenu("&Magic") | |||
|
563 | self.all_magic_menu = self.magic_menu.addMenu("&All Magics") | |||
|
564 | ||||
427 | self.reset_action = QtGui.QAction("&Reset", |
|
565 | self.reset_action = QtGui.QAction("&Reset", | |
428 | self, |
|
566 | self, | |
429 | statusTip="Clear all varible from workspace", |
|
567 | statusTip="Clear all varible from workspace", | |
430 | triggered=self.reset_magic_active_frontend) |
|
568 | triggered=self.reset_magic_active_frontend) | |
431 |
self.magic_menu |
|
569 | self.add_menu_action(self.magic_menu, self.reset_action) | |
432 |
|
570 | |||
433 | self.history_action = QtGui.QAction("&History", |
|
571 | self.history_action = QtGui.QAction("&History", | |
434 | self, |
|
572 | self, | |
435 | statusTip="show command history", |
|
573 | statusTip="show command history", | |
436 | triggered=self.history_magic_active_frontend) |
|
574 | triggered=self.history_magic_active_frontend) | |
437 |
self.magic_menu |
|
575 | self.add_menu_action(self.magic_menu, self.history_action) | |
438 |
|
576 | |||
439 | self.save_action = QtGui.QAction("E&xport History ", |
|
577 | self.save_action = QtGui.QAction("E&xport History ", | |
440 | self, |
|
578 | self, | |
441 | statusTip="Export History as Python File", |
|
579 | statusTip="Export History as Python File", | |
442 | triggered=self.save_magic_active_frontend) |
|
580 | triggered=self.save_magic_active_frontend) | |
443 |
self.magic_menu |
|
581 | self.add_menu_action(self.magic_menu, self.save_action) | |
444 |
|
||||
445 | self.clear_action = QtGui.QAction("&Clear Screen", |
|
|||
446 | self, |
|
|||
447 | shortcut='Ctrl+L', |
|
|||
448 | statusTip="Clear the console", |
|
|||
449 | triggered=self.clear_magic_active_frontend) |
|
|||
450 | self.window_menu.addAction(self.clear_action) |
|
|||
451 |
|
582 | |||
452 | self.who_action = QtGui.QAction("&Who", |
|
583 | self.who_action = QtGui.QAction("&Who", | |
453 | self, |
|
584 | self, | |
454 | statusTip="List interactive variable", |
|
585 | statusTip="List interactive variable", | |
455 | triggered=self.who_magic_active_frontend) |
|
586 | triggered=self.who_magic_active_frontend) | |
456 |
self.magic_menu |
|
587 | self.add_menu_action(self.magic_menu, self.who_action) | |
457 |
|
588 | |||
458 | self.who_ls_action = QtGui.QAction("Wh&o ls", |
|
589 | self.who_ls_action = QtGui.QAction("Wh&o ls", | |
459 | self, |
|
590 | self, | |
460 | statusTip="Return a list of interactive variable", |
|
591 | statusTip="Return a list of interactive variable", | |
461 | triggered=self.who_ls_magic_active_frontend) |
|
592 | triggered=self.who_ls_magic_active_frontend) | |
462 |
self.magic_menu |
|
593 | self.add_menu_action(self.magic_menu, self.who_ls_action) | |
463 |
|
594 | |||
464 | self.whos_action = QtGui.QAction("Who&s", |
|
595 | self.whos_action = QtGui.QAction("Who&s", | |
465 | self, |
|
596 | self, | |
466 | statusTip="List interactive variable with detail", |
|
597 | statusTip="List interactive variable with detail", | |
467 | triggered=self.whos_magic_active_frontend) |
|
598 | triggered=self.whos_magic_active_frontend) | |
468 |
self.magic_menu |
|
599 | self.add_menu_action(self.magic_menu, self.whos_action) | |
469 |
|
600 | |||
470 | self.intro_active_frontend_action = QtGui.QAction("Intro to IPython", |
|
601 | # allmagics submenu: | |
471 |
|
|
602 | ||
472 | triggered=self.intro_active_frontend |
|
|||
473 | ) |
|
|||
474 | self.help_menu.addAction(self.intro_active_frontend_action) |
|
|||
475 |
|
||||
476 | self.quickref_active_frontend_action = QtGui.QAction("IPython Cheat Sheet", |
|
|||
477 | self, |
|
|||
478 | triggered=self.quickref_active_frontend |
|
|||
479 | ) |
|
|||
480 | self.help_menu.addAction(self.quickref_active_frontend_action) |
|
|||
481 |
|
||||
482 | self.guiref_active_frontend_action = QtGui.QAction("Qt Console", |
|
|||
483 | self, |
|
|||
484 | triggered=self.guiref_active_frontend |
|
|||
485 | ) |
|
|||
486 | self.help_menu.addAction(self.guiref_active_frontend_action) |
|
|||
487 |
|
||||
488 | self.interrupt_kernel_action = QtGui.QAction("Interrupt current Kernel", |
|
|||
489 | self, |
|
|||
490 | triggered=self.interrupt_kernel_active_frontend |
|
|||
491 | ) |
|
|||
492 | self.kernel_menu.addAction(self.interrupt_kernel_action) |
|
|||
493 |
|
||||
494 | self.restart_kernel_action = QtGui.QAction("Restart current Kernel", |
|
|||
495 | self, |
|
|||
496 | triggered=self.restart_kernel_active_frontend |
|
|||
497 | ) |
|
|||
498 | self.kernel_menu.addAction(self.restart_kernel_action) |
|
|||
499 | self.kernel_menu.addSeparator() |
|
|||
500 |
|
||||
501 | #for now this is just a copy and paste, but we should get this dynamically |
|
603 | #for now this is just a copy and paste, but we should get this dynamically | |
502 | magiclist=["%alias", "%autocall", "%automagic", "%bookmark", "%cd", "%clear", |
|
604 | magiclist=["%alias", "%autocall", "%automagic", "%bookmark", "%cd", "%clear", | |
503 | "%colors", "%debug", "%dhist", "%dirs", "%doctest_mode", "%ed", "%edit", "%env", "%gui", |
|
605 | "%colors", "%debug", "%dhist", "%dirs", "%doctest_mode", "%ed", "%edit", "%env", "%gui", | |
@@ -522,6 +624,119 b' class MainWindow(QtGui.QMainWindow):' | |||||
522 | triggered=make_dynamic_magic(magic) |
|
624 | triggered=make_dynamic_magic(magic) | |
523 | ) |
|
625 | ) | |
524 | self.all_magic_menu.addAction(xaction) |
|
626 | self.all_magic_menu.addAction(xaction) | |
|
627 | ||||
|
628 | def init_window_menu(self): | |||
|
629 | self.window_menu = self.menuBar().addMenu("&Window") | |||
|
630 | if sys.platform == 'darwin': | |||
|
631 | # add min/maximize actions to OSX, which lacks default bindings. | |||
|
632 | self.minimizeAct = QtGui.QAction("Mini&mize", | |||
|
633 | self, | |||
|
634 | shortcut="Ctrl+m", | |||
|
635 | statusTip="Minimize the window/Restore Normal Size", | |||
|
636 | triggered=self.toggleMinimized) | |||
|
637 | # maximize is called 'Zoom' on OSX for some reason | |||
|
638 | self.maximizeAct = QtGui.QAction("&Zoom", | |||
|
639 | self, | |||
|
640 | shortcut="Ctrl+Shift+M", | |||
|
641 | statusTip="Maximize the window/Restore Normal Size", | |||
|
642 | triggered=self.toggleMaximized) | |||
|
643 | ||||
|
644 | self.add_menu_action(self.window_menu, self.minimizeAct) | |||
|
645 | self.add_menu_action(self.window_menu, self.maximizeAct) | |||
|
646 | self.window_menu.addSeparator() | |||
|
647 | ||||
|
648 | prev_key = "Ctrl+Shift+Left" if sys.platform == 'darwin' else "Ctrl+PgDown" | |||
|
649 | self.prev_tab_act = QtGui.QAction("Pre&vious Tab", | |||
|
650 | self, | |||
|
651 | shortcut=prev_key, | |||
|
652 | statusTip="Select previous tab", | |||
|
653 | triggered=self.prev_tab) | |||
|
654 | self.add_menu_action(self.window_menu, self.prev_tab_act) | |||
|
655 | ||||
|
656 | next_key = "Ctrl+Shift+Right" if sys.platform == 'darwin' else "Ctrl+PgUp" | |||
|
657 | self.next_tab_act = QtGui.QAction("Ne&xt Tab", | |||
|
658 | self, | |||
|
659 | shortcut=next_key, | |||
|
660 | statusTip="Select next tab", | |||
|
661 | triggered=self.next_tab) | |||
|
662 | self.add_menu_action(self.window_menu, self.next_tab_act) | |||
|
663 | ||||
|
664 | def init_help_menu(self): | |||
|
665 | # please keep the Help menu in Mac Os even if empty. It will | |||
|
666 | # automatically contain a search field to search inside menus and | |||
|
667 | # please keep it spelled in English, as long as Qt Doesn't support | |||
|
668 | # a QAction.MenuRole like HelpMenuRole otherwise it will loose | |||
|
669 | # this search field fonctionality | |||
|
670 | ||||
|
671 | self.help_menu = self.menuBar().addMenu("&Help") | |||
|
672 | ||||
|
673 | ||||
|
674 | # Help Menu | |||
|
675 | ||||
|
676 | self.intro_active_frontend_action = QtGui.QAction("&Intro to IPython", | |||
|
677 | self, | |||
|
678 | triggered=self.intro_active_frontend | |||
|
679 | ) | |||
|
680 | self.add_menu_action(self.help_menu, self.intro_active_frontend_action) | |||
|
681 | ||||
|
682 | self.quickref_active_frontend_action = QtGui.QAction("IPython &Cheat Sheet", | |||
|
683 | self, | |||
|
684 | triggered=self.quickref_active_frontend | |||
|
685 | ) | |||
|
686 | self.add_menu_action(self.help_menu, self.quickref_active_frontend_action) | |||
|
687 | ||||
|
688 | self.guiref_active_frontend_action = QtGui.QAction("&Qt Console", | |||
|
689 | self, | |||
|
690 | triggered=self.guiref_active_frontend | |||
|
691 | ) | |||
|
692 | self.add_menu_action(self.help_menu, self.guiref_active_frontend_action) | |||
|
693 | ||||
|
694 | self.onlineHelpAct = QtGui.QAction("Open Online &Help", | |||
|
695 | self, | |||
|
696 | triggered=self._open_online_help) | |||
|
697 | self.add_menu_action(self.help_menu, self.onlineHelpAct) | |||
|
698 | ||||
|
699 | # minimize/maximize/fullscreen actions: | |||
|
700 | ||||
|
701 | def toggle_menu_bar(self): | |||
|
702 | menu_bar = self.menuBar(); | |||
|
703 | if menu_bar.isVisible(): | |||
|
704 | menu_bar.setVisible(False) | |||
|
705 | else: | |||
|
706 | menu_bar.setVisible(True) | |||
|
707 | ||||
|
708 | def toggleMinimized(self): | |||
|
709 | if not self.isMinimized(): | |||
|
710 | self.showMinimized() | |||
|
711 | else: | |||
|
712 | self.showNormal() | |||
|
713 | ||||
|
714 | def _open_online_help(self): | |||
|
715 | filename="http://ipython.org/ipython-doc/stable/index.html" | |||
|
716 | webbrowser.open(filename, new=1, autoraise=True) | |||
|
717 | ||||
|
718 | def toggleMaximized(self): | |||
|
719 | if not self.isMaximized(): | |||
|
720 | self.showMaximized() | |||
|
721 | else: | |||
|
722 | self.showNormal() | |||
|
723 | ||||
|
724 | # Min/Max imizing while in full screen give a bug | |||
|
725 | # when going out of full screen, at least on OSX | |||
|
726 | def toggleFullScreen(self): | |||
|
727 | if not self.isFullScreen(): | |||
|
728 | self.showFullScreen() | |||
|
729 | if sys.platform == 'darwin': | |||
|
730 | self.maximizeAct.setEnabled(False) | |||
|
731 | self.minimizeAct.setEnabled(False) | |||
|
732 | else: | |||
|
733 | self.showNormal() | |||
|
734 | if sys.platform == 'darwin': | |||
|
735 | self.maximizeAct.setEnabled(True) | |||
|
736 | self.minimizeAct.setEnabled(True) | |||
|
737 | ||||
|
738 | def close_active_frontend(self): | |||
|
739 | self.close_tab(self.active_frontend) | |||
525 |
|
740 | |||
526 | def restart_kernel_active_frontend(self): |
|
741 | def restart_kernel_active_frontend(self): | |
527 | self.active_frontend.request_restart_kernel() |
|
742 | self.active_frontend.request_restart_kernel() | |
@@ -910,8 +1125,8 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
910 | self.kernel_manager.write_connection_file() |
|
1125 | self.kernel_manager.write_connection_file() | |
911 | self.kernel_manager.start_channels() |
|
1126 | self.kernel_manager.start_channels() | |
912 |
|
1127 | |||
913 |
def |
|
1128 | def new_frontend_master(self): | |
914 |
""" Create |
|
1129 | """ Create and return new frontend attached to new kernel, launched on localhost. | |
915 | """ |
|
1130 | """ | |
916 | ip = self.ip if self.ip in LOCAL_IPS else LOCALHOST |
|
1131 | ip = self.ip if self.ip in LOCAL_IPS else LOCALHOST | |
917 | kernel_manager = QtKernelManager( |
|
1132 | kernel_manager = QtKernelManager( | |
@@ -927,16 +1142,19 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
927 | widget = self.widget_factory(config=self.config, |
|
1142 | widget = self.widget_factory(config=self.config, | |
928 | local_kernel=True) |
|
1143 | local_kernel=True) | |
929 | widget.kernel_manager = kernel_manager |
|
1144 | widget.kernel_manager = kernel_manager | |
930 |
widget._existing=False |
|
1145 | widget._existing=False | |
931 |
widget._confirm_exit=True |
|
1146 | widget._confirm_exit=True | |
932 |
widget._may_close=True |
|
1147 | widget._may_close=True | |
933 | self.window.add_tab_with_frontend(widget) |
|
1148 | return widget | |
934 |
|
1149 | |||
935 | def create_tab_attached_to_current_tab_kernel(self): |
|
1150 | def new_frontend_slave(self, current_widget): | |
936 | current_widget = self.window.tab_widget.currentWidget() |
|
1151 | """Create and return a new frontend attached to an existing kernel. | |
937 | current_widget_index = self.window.tab_widget.indexOf(current_widget) |
|
1152 | ||
938 | current_widget.kernel_manager = current_widget.kernel_manager; |
|
1153 | Parameters | |
939 | current_widget_name = self.window.tab_widget.tabText(current_widget_index); |
|
1154 | ---------- | |
|
1155 | current_widget : IPythonWidget | |||
|
1156 | The IPythonWidget whose kernel this frontend is to share | |||
|
1157 | """ | |||
940 | kernel_manager = QtKernelManager( |
|
1158 | kernel_manager = QtKernelManager( | |
941 | connection_file=current_widget.kernel_manager.connection_file, |
|
1159 | connection_file=current_widget.kernel_manager.connection_file, | |
942 | config = self.config, |
|
1160 | config = self.config, | |
@@ -948,7 +1166,7 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
948 | widget._confirm_exit=True; |
|
1166 | widget._confirm_exit=True; | |
949 | widget._may_close=False; |
|
1167 | widget._may_close=False; | |
950 | widget.kernel_manager = kernel_manager |
|
1168 | widget.kernel_manager = kernel_manager | |
951 | self.window.add_tab_with_frontend(widget,name=str('('+current_widget_name+') slave')) |
|
1169 | return widget | |
952 |
|
1170 | |||
953 | def init_qt_elements(self): |
|
1171 | def init_qt_elements(self): | |
954 | # Create the widget. |
|
1172 | # Create the widget. | |
@@ -969,7 +1187,10 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
969 | self.widget.kernel_manager = self.kernel_manager |
|
1187 | self.widget.kernel_manager = self.kernel_manager | |
970 | self.window = MainWindow(self.app, self.widget, self.existing, |
|
1188 | self.window = MainWindow(self.app, self.widget, self.existing, | |
971 | may_close=local_kernel, |
|
1189 | may_close=local_kernel, | |
972 |
confirm_exit=self.confirm_exit |
|
1190 | confirm_exit=self.confirm_exit, | |
|
1191 | new_frontend_factory=self.new_frontend_master, | |||
|
1192 | slave_frontend_factory=self.new_frontend_slave, | |||
|
1193 | ) | |||
973 | self.window.log = self.log |
|
1194 | self.window.log = self.log | |
974 | self.window.add_tab_with_frontend(self.widget) |
|
1195 | self.window.add_tab_with_frontend(self.widget) | |
975 | self.window.init_menu_bar() |
|
1196 | self.window.init_menu_bar() | |
@@ -1046,124 +1267,6 b' class IPythonQtConsoleApp(BaseIPythonApplication):' | |||||
1046 | self.init_kernel_manager() |
|
1267 | self.init_kernel_manager() | |
1047 | self.init_qt_elements() |
|
1268 | self.init_qt_elements() | |
1048 | self.init_colors() |
|
1269 | self.init_colors() | |
1049 | self.init_window_shortcut() |
|
|||
1050 |
|
||||
1051 | def init_window_shortcut(self): |
|
|||
1052 |
|
||||
1053 | self.prev_tab_act = QtGui.QAction("Pre&vious Tab", |
|
|||
1054 | self.window, |
|
|||
1055 | shortcut="Ctrl+PgDown", |
|
|||
1056 | statusTip="Cahange to next tab", |
|
|||
1057 | triggered=self.window.prev_tab) |
|
|||
1058 |
|
||||
1059 | self.next_tab_act = QtGui.QAction("Ne&xt Tab", |
|
|||
1060 | self.window, |
|
|||
1061 | shortcut="Ctrl+PgUp", |
|
|||
1062 | statusTip="Cahange to next tab", |
|
|||
1063 | triggered=self.window.next_tab) |
|
|||
1064 |
|
||||
1065 | self.fullScreenAct = QtGui.QAction("&Full Screen", |
|
|||
1066 | self.window, |
|
|||
1067 | shortcut="Ctrl+Meta+Space", |
|
|||
1068 | statusTip="Toggle between Fullscreen and Normal Size", |
|
|||
1069 | triggered=self.toggleFullScreen) |
|
|||
1070 |
|
||||
1071 |
|
||||
1072 |
|
||||
1073 | self.tabAndNewKernelAct =QtGui.QAction("Tab with &New kernel", |
|
|||
1074 | self.window, |
|
|||
1075 | shortcut="Ctrl+T", |
|
|||
1076 | triggered=self.create_tab_with_new_frontend) |
|
|||
1077 | self.window.kernel_menu.addAction(self.tabAndNewKernelAct) |
|
|||
1078 |
|
||||
1079 | self.tabSameKernalAct =QtGui.QAction("Tab with Sa&me kernel", |
|
|||
1080 | self.window, |
|
|||
1081 | shortcut="Ctrl+Shift+T", |
|
|||
1082 | triggered=self.create_tab_attached_to_current_tab_kernel) |
|
|||
1083 | self.window.kernel_menu.addAction(self.tabSameKernalAct) |
|
|||
1084 | self.window.kernel_menu.addSeparator() |
|
|||
1085 |
|
||||
1086 | self.onlineHelpAct = QtGui.QAction("Open Online &Help", |
|
|||
1087 | self.window, |
|
|||
1088 | triggered=self._open_online_help) |
|
|||
1089 | self.window.help_menu.addAction(self.onlineHelpAct) |
|
|||
1090 | # creating shortcut in menubar only for Mac OS as I don't |
|
|||
1091 | # know the shortcut or if the windows manager assign it in |
|
|||
1092 | # other platform. |
|
|||
1093 | if sys.platform == 'darwin': |
|
|||
1094 | self.minimizeAct = QtGui.QAction("Mini&mize", |
|
|||
1095 | self.window, |
|
|||
1096 | shortcut="Ctrl+m", |
|
|||
1097 | statusTip="Minimize the window/Restore Normal Size", |
|
|||
1098 | triggered=self.toggleMinimized) |
|
|||
1099 | self.maximizeAct = QtGui.QAction("Ma&ximize", |
|
|||
1100 | self.window, |
|
|||
1101 | shortcut="Ctrl+Shift+M", |
|
|||
1102 | statusTip="Maximize the window/Restore Normal Size", |
|
|||
1103 | triggered=self.toggleMaximized) |
|
|||
1104 |
|
||||
1105 |
|
||||
1106 | self.window_menu = self.window.window_menu |
|
|||
1107 | self.kernel_menu = self.window.kernel_menu |
|
|||
1108 |
|
||||
1109 | self.kernel_menu.addAction(self.next_tab_act) |
|
|||
1110 | self.kernel_menu.addAction(self.prev_tab_act) |
|
|||
1111 | self.window_menu.addSeparator() |
|
|||
1112 | self.window_menu.addAction(self.minimizeAct) |
|
|||
1113 | self.window_menu.addAction(self.maximizeAct) |
|
|||
1114 | self.window_menu.addSeparator() |
|
|||
1115 | self.window_menu.addAction(self.fullScreenAct) |
|
|||
1116 |
|
||||
1117 | else: |
|
|||
1118 | # if we don't put it in a menu, we add it to the window so |
|
|||
1119 | # that it can still be triggerd by shortcut |
|
|||
1120 | self.window.addAction(self.fullScreenAct) |
|
|||
1121 |
|
||||
1122 | # Don't activate toggleMenubar on mac, doen't work, |
|
|||
1123 | # as toolbar always here |
|
|||
1124 | self.toggle_menu_bar_act = QtGui.QAction("&Toggle Menu Bar", |
|
|||
1125 | self.window, |
|
|||
1126 | shortcut="Ctrl+Meta+H", |
|
|||
1127 | statusTip="Toggle menubar betwin visible and not", |
|
|||
1128 | triggered=self.toggle_menu_bar) |
|
|||
1129 | self.window.window_menu.addAction(self.toggle_menu_bar_act) |
|
|||
1130 |
|
||||
1131 | def toggle_menu_bar(self): |
|
|||
1132 | menu_bar = self.window.menuBar(); |
|
|||
1133 | if not menu_bar.isVisible(): |
|
|||
1134 | menu_bar.setVisible(False) |
|
|||
1135 | else: |
|
|||
1136 | menu_bar.setVisible(True) |
|
|||
1137 |
|
||||
1138 | def toggleMinimized(self): |
|
|||
1139 | if not self.window.isMinimized(): |
|
|||
1140 | self.window.showMinimized() |
|
|||
1141 | else: |
|
|||
1142 | self.window.showNormal() |
|
|||
1143 |
|
||||
1144 | def _open_online_help(self): |
|
|||
1145 | filename="http://ipython.org/ipython-doc/stable/index.html" |
|
|||
1146 | webbrowser.open(filename, new=1, autoraise=True) |
|
|||
1147 |
|
||||
1148 | def toggleMaximized(self): |
|
|||
1149 | if not self.window.isMaximized(): |
|
|||
1150 | self.window.showMaximized() |
|
|||
1151 | else: |
|
|||
1152 | self.window.showNormal() |
|
|||
1153 |
|
||||
1154 | # Min/Max imizing while in full screen give a bug |
|
|||
1155 | # when going out of full screen, at least on OSX |
|
|||
1156 | def toggleFullScreen(self): |
|
|||
1157 | if not self.window.isFullScreen(): |
|
|||
1158 | self.window.showFullScreen() |
|
|||
1159 | if sys.platform == 'darwin': |
|
|||
1160 | self.maximizeAct.setEnabled(False) |
|
|||
1161 | self.minimizeAct.setEnabled(False) |
|
|||
1162 | else: |
|
|||
1163 | self.window.showNormal() |
|
|||
1164 | if sys.platform == 'darwin': |
|
|||
1165 | self.maximizeAct.setEnabled(True) |
|
|||
1166 | self.minimizeAct.setEnabled(True) |
|
|||
1167 |
|
1270 | |||
1168 | def start(self): |
|
1271 | def start(self): | |
1169 |
|
1272 |
General Comments 0
You need to be logged in to leave comments.
Login now