def init_help_menu(self): # please keep the Help menu in Mac Os even if empty. It will # automatically contain a search field to search inside menus and # please keep it spelled in English, as long as Qt Doesn't support # a QAction.MenuRole like HelpMenuRole otherwise it will lose # this search field functionality self.help_menu = self.menuBar().addMenu("&Help") # Help Menu self.intro_active_frontend_action = QtGui.QAction( "&Intro to IPython", self, triggered=self.intro_active_frontend) self.add_menu_action(self.help_menu, self.intro_active_frontend_action) self.quickref_active_frontend_action = QtGui.QAction( "IPython &Cheat Sheet", self, triggered=self.quickref_active_frontend) self.add_menu_action(self.help_menu, self.quickref_active_frontend_action) self.guiref_active_frontend_action = QtGui.QAction( "&Qt Console", self, triggered=self.guiref_active_frontend) self.add_menu_action(self.help_menu, self.guiref_active_frontend_action) self.onlineHelpAct = QtGui.QAction("Open Online &Help", self, triggered=self._open_online_help) self.add_menu_action(self.help_menu, self.onlineHelpAct)
def init_edit_menu(self): self.edit_menu = self.menuBar().addMenu("&Edit") self.undo_action = QtGui.QAction( "&Undo", self, shortcut=QtGui.QKeySequence.Undo, statusTip="Undo last action if possible", triggered=self.undo_active_frontend) self.add_menu_action(self.edit_menu, self.undo_action) self.redo_action = QtGui.QAction( "&Redo", self, shortcut=QtGui.QKeySequence.Redo, statusTip="Redo last action if possible", triggered=self.redo_active_frontend) self.add_menu_action(self.edit_menu, self.redo_action) self.edit_menu.addSeparator() self.cut_action = QtGui.QAction("&Cut", self, shortcut=QtGui.QKeySequence.Cut, triggered=self.cut_active_frontend) self.add_menu_action(self.edit_menu, self.cut_action, True) self.copy_action = QtGui.QAction("&Copy", self, shortcut=QtGui.QKeySequence.Copy, triggered=self.copy_active_frontend) self.add_menu_action(self.edit_menu, self.copy_action, True) self.copy_raw_action = QtGui.QAction( "Copy (&Raw Text)", self, shortcut="Ctrl+Shift+C", triggered=self.copy_raw_active_frontend) self.add_menu_action(self.edit_menu, self.copy_raw_action, True) self.paste_action = QtGui.QAction("&Paste", self, shortcut=QtGui.QKeySequence.Paste, triggered=self.paste_active_frontend) self.add_menu_action(self.edit_menu, self.paste_action, True) self.edit_menu.addSeparator() selectall = QtGui.QKeySequence(QtGui.QKeySequence.SelectAll) if selectall.matches("Ctrl+A") and sys.platform != 'darwin': # Only override the default if there is a collision. # Qt ctrl = cmd on OSX, so the match gets a false positive on OSX. selectall = "Ctrl+Shift+A" self.select_all_action = QtGui.QAction( "Select &All", self, shortcut=selectall, triggered=self.select_all_active_frontend) self.add_menu_action(self.edit_menu, self.select_all_action, True)
def __init__(self, *args, **kw): super(FrontendWidget, self).__init__(*args, **kw) # FIXME: remove this when PySide min version is updated past 1.0.7 # forcefully disable calltips if PySide is < 1.0.7, because they crash if qt.QT_API == qt.QT_API_PYSIDE: import PySide if PySide.__version_info__ < (1, 0, 7): self.log.warn( "PySide %s < 1.0.7 detected, disabling calltips" % PySide.__version__) self.enable_calltips = False # FrontendWidget protected variables. self._bracket_matcher = BracketMatcher(self._control) self._call_tip_widget = CallTipWidget(self._control) self._copy_raw_action = QtGui.QAction('Copy (Raw Text)', None) self._hidden = False self._highlighter = FrontendHighlighter(self, lexer=self.lexer) self._input_splitter = self._input_splitter_class() self._kernel_manager = None self._kernel_client = None self._request_info = {} self._request_info['execute'] = {} self._callback_dict = {} self._display_banner = True # Configure the ConsoleWidget. self.tab_width = 4 self._set_continuation_prompt('... ') # Configure the CallTipWidget. self._call_tip_widget.setFont(self.font) self.font_changed.connect(self._call_tip_widget.setFont) # Configure actions. action = self._copy_raw_action key = QtCore.Qt.CTRL | QtCore.Qt.SHIFT | QtCore.Qt.Key_C action.setEnabled(False) action.setShortcut(QtGui.QKeySequence(key)) action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut) action.triggered.connect(self.copy_raw) self.copy_available.connect(action.setEnabled) self.addAction(action) # Connect signal handlers. document = self._control.document() document.contentsChange.connect(self._document_contents_change) # Set flag for whether we are connected via localhost. self._local_kernel = kw.get('local_kernel', FrontendWidget._local_kernel) # Whether or not a clear_output call is pending new output. self._pending_clearoutput = False
def init_file_menu(self): self.file_menu = self.menuBar().addMenu("&File") self.new_kernel_tab_act = QtGui.QAction( "New Tab with &New kernel", self, shortcut="Ctrl+T", triggered=self.create_tab_with_new_frontend) self.add_menu_action(self.file_menu, self.new_kernel_tab_act) self.slave_kernel_tab_act = QtGui.QAction( "New Tab with Sa&me kernel", self, shortcut="Ctrl+Shift+T", triggered=self.create_tab_with_current_kernel) self.add_menu_action(self.file_menu, self.slave_kernel_tab_act) self.file_menu.addSeparator() self.close_action = QtGui.QAction("&Close Tab", self, shortcut=QtGui.QKeySequence.Close, triggered=self.close_active_frontend) self.add_menu_action(self.file_menu, self.close_action) self.export_action = QtGui.QAction( "&Save to HTML/XHTML", self, shortcut=QtGui.QKeySequence.Save, triggered=self.export_action_active_frontend) self.add_menu_action(self.file_menu, self.export_action, True) self.file_menu.addSeparator() printkey = QtGui.QKeySequence(QtGui.QKeySequence.Print) if printkey.matches("Ctrl+P") and sys.platform != 'darwin': # Only override the default if there is a collision. # Qt ctrl = cmd on OSX, so the match gets a false positive on OSX. printkey = "Ctrl+Shift+P" self.print_action = QtGui.QAction( "&Print", self, shortcut=printkey, triggered=self.print_action_active_frontend) self.add_menu_action(self.file_menu, self.print_action, True) if sys.platform != 'darwin': # OSX always has Quit in the Application menu, only add it # to the File menu elsewhere. self.file_menu.addSeparator() self.quit_action = QtGui.QAction( "&Quit", self, shortcut=QtGui.QKeySequence.Quit, triggered=self.close, ) self.add_menu_action(self.file_menu, self.quit_action)
def init_window_menu(self): self.window_menu = self.menuBar().addMenu("&Window") if sys.platform == 'darwin': # add min/maximize actions to OSX, which lacks default bindings. self.minimizeAct = QtGui.QAction( "Mini&mize", self, shortcut="Ctrl+m", statusTip="Minimize the window/Restore Normal Size", triggered=self.toggleMinimized) # maximize is called 'Zoom' on OSX for some reason self.maximizeAct = QtGui.QAction( "&Zoom", self, shortcut="Ctrl+Shift+M", statusTip="Maximize the window/Restore Normal Size", triggered=self.toggleMaximized) self.add_menu_action(self.window_menu, self.minimizeAct) self.add_menu_action(self.window_menu, self.maximizeAct) self.window_menu.addSeparator() prev_key = "Ctrl+Shift+Left" if sys.platform == 'darwin' else "Ctrl+PgUp" self.prev_tab_act = QtGui.QAction("Pre&vious Tab", self, shortcut=prev_key, statusTip="Select previous tab", triggered=self.prev_tab) self.add_menu_action(self.window_menu, self.prev_tab_act) next_key = "Ctrl+Shift+Right" if sys.platform == 'darwin' else "Ctrl+PgDown" self.next_tab_act = QtGui.QAction("Ne&xt Tab", self, shortcut=next_key, statusTip="Select next tab", triggered=self.next_tab) self.add_menu_action(self.window_menu, self.next_tab_act)
def init_kernel_menu(self): self.kernel_menu = self.menuBar().addMenu("&Kernel") # Qt on OSX maps Ctrl to Cmd, and Meta to Ctrl # keep the signal shortcuts to ctrl, rather than # platform-default like we do elsewhere. ctrl = "Meta" if sys.platform == 'darwin' else "Ctrl" self.interrupt_kernel_action = QtGui.QAction( "&Interrupt current Kernel", self, triggered=self.interrupt_kernel_active_frontend, shortcut=ctrl + "+C", ) self.add_menu_action(self.kernel_menu, self.interrupt_kernel_action) self.restart_kernel_action = QtGui.QAction( "&Restart current Kernel", self, triggered=self.restart_kernel_active_frontend, shortcut=ctrl + "+.", ) self.add_menu_action(self.kernel_menu, self.restart_kernel_action) self.kernel_menu.addSeparator() self.confirm_restart_kernel_action = QtGui.QAction( "&Confirm kernel restart", self, checkable=True, checked=self.active_frontend.confirm_restart, triggered=self.toggle_confirm_restart_active_frontend) self.add_menu_action(self.kernel_menu, self.confirm_restart_kernel_action) self.tab_widget.currentChanged.connect(self.update_restart_checkbox)
def init_magic_menu(self): self.magic_menu = self.menuBar().addMenu("&Magic") self.add_menu_action(self.magic_menu, self.magic_helper.toggleViewAction()) self.magic_menu_separator = self.magic_menu.addSeparator() self.reset_action = QtGui.QAction( "&Reset", self, statusTip="Clear all variables from workspace", triggered=self.reset_magic_active_frontend) self.add_menu_action(self.magic_menu, self.reset_action) self.history_action = QtGui.QAction( "&History", self, statusTip="show command history", triggered=self.history_magic_active_frontend) self.add_menu_action(self.magic_menu, self.history_action) self.save_action = QtGui.QAction( "E&xport History ", self, statusTip="Export History as Python File", triggered=self.save_magic_active_frontend) self.add_menu_action(self.magic_menu, self.save_action) self.who_action = QtGui.QAction( "&Who", self, statusTip="List interactive variables", triggered=self.who_magic_active_frontend) self.add_menu_action(self.magic_menu, self.who_action) self.who_ls_action = QtGui.QAction( "Wh&o ls", self, statusTip="Return a list of interactive variables", triggered=self.who_ls_magic_active_frontend) self.add_menu_action(self.magic_menu, self.who_ls_action) self.whos_action = QtGui.QAction( "Who&s", self, statusTip="List interactive variables with details", triggered=self.whos_magic_active_frontend) self.add_menu_action(self.magic_menu, self.whos_action)
def init_view_menu(self): self.view_menu = self.menuBar().addMenu("&View") if sys.platform != 'darwin': # disable on OSX, where there is always a menu bar self.toggle_menu_bar_act = QtGui.QAction( "Toggle &Menu Bar", self, shortcut="Ctrl+Shift+M", statusTip="Toggle visibility of menubar", triggered=self.toggle_menu_bar) self.add_menu_action(self.view_menu, self.toggle_menu_bar_act) fs_key = "Ctrl+Meta+F" if sys.platform == 'darwin' else "F11" self.full_screen_act = QtGui.QAction( "&Full Screen", self, shortcut=fs_key, statusTip="Toggle between Fullscreen and Normal Size", triggered=self.toggleFullScreen) self.add_menu_action(self.view_menu, self.full_screen_act) self.view_menu.addSeparator() self.increase_font_size = QtGui.QAction( "Zoom &In", self, shortcut=QtGui.QKeySequence.ZoomIn, triggered=self.increase_font_size_active_frontend) self.add_menu_action(self.view_menu, self.increase_font_size, True) self.decrease_font_size = QtGui.QAction( "Zoom &Out", self, shortcut=QtGui.QKeySequence.ZoomOut, triggered=self.decrease_font_size_active_frontend) self.add_menu_action(self.view_menu, self.decrease_font_size, True) self.reset_font_size = QtGui.QAction( "Zoom &Reset", self, shortcut="Ctrl+0", triggered=self.reset_font_size_active_frontend) self.add_menu_action(self.view_menu, self.reset_font_size, True) self.view_menu.addSeparator() self.clear_action = QtGui.QAction( "&Clear Screen", self, shortcut='Ctrl+L', statusTip="Clear the console", triggered=self.clear_magic_active_frontend) self.add_menu_action(self.view_menu, self.clear_action) self.pager_menu = self.view_menu.addMenu("&Pager") hsplit_action = QtGui.QAction( ".. &Horizontal Split", self, triggered=lambda: self.set_paging_active_frontend('hsplit')) vsplit_action = QtGui.QAction( " : &Vertical Split", self, triggered=lambda: self.set_paging_active_frontend('vsplit')) inside_action = QtGui.QAction( " &Inside Pager", self, triggered=lambda: self.set_paging_active_frontend('inside')) self.pager_menu.addAction(hsplit_action) self.pager_menu.addAction(vsplit_action) self.pager_menu.addAction(inside_action)