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_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_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.help_action = QtGui.QAction("Show &QtConsole help", self, triggered=self._show_help) self.online_help_action = QtGui.QAction("Open online &help", self, triggered=self._open_online_help) self.add_menu_action(self.help_menu, self.help_action) self.add_menu_action(self.help_menu, self.online_help_action)
def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.history_s = 20.0 self.next_color = 0 self.paused = False self.last_draw_time = 0.0 self.figure = matplotlib.figure.Figure() self.canvas = FigureCanvas(self.figure) self.canvas.mpl_connect('key_press_event', self.handle_key_press) self.canvas.mpl_connect('key_release_event', self.handle_key_release) self.left_axis = self.figure.add_subplot(111) self.left_axis.grid() self.left_axis.fmt_xdata = lambda x: '%.3f' % x self.left_axis.legend_loc = LEFT_LEGEND_LOC self.right_axis = None self.toolbar = qt_backend.NavigationToolbar2QT(self.canvas, self) self.pause_action = QtGui.QAction(u'Pause', self) self.pause_action.setCheckable(True) self.pause_action.toggled.connect(self._handle_pause) self.toolbar.addAction(self.pause_action) layout = QtGui.QVBoxLayout(self) layout.addWidget(self.toolbar, 0) layout.addWidget(self.canvas, 1) self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
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 Cell/&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__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.history_s = 20.0 self.next_color = 0 self.paused = False self.last_draw_time = 0.0 self.figure = matplotlib.figure.Figure() self.canvas = FigureCanvas(self.figure) self.canvas.mpl_connect('key_press_event', self.handle_key_press) self.canvas.mpl_connect('key_release_event', self.handle_key_release) self.left_axis = self.figure.add_subplot(111) self.left_axis.grid() self.left_axis.fmt_xdata = lambda x: '%.3f' % x self.left_axis.legend_loc = LEFT_LEGEND_LOC self.right_axis = None def draw(): # NOTE jpieper: For some reason, on the first repaint # event, the height is negative, which throws spurious # errors. Paper over that here. l, b, w, h = self.figure.bbox.bounds if h < 0: return FigureCanvas.draw(self.canvas) self.canvas.repaint() self.canvas.draw = draw self.toolbar = backend_qt4agg.NavigationToolbar2QT(self.canvas, self) self.pause_action = QtGui.QAction(u'Pause', self) self.pause_action.setCheckable(True) self.pause_action.toggled.connect(self._handle_pause) self.toolbar.addAction(self.pause_action) layout = QtGui.QVBoxLayout(self) layout.addWidget(self.toolbar, 0) layout.addWidget(self.canvas, 1) self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
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_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) available_syntax_styles = self.get_available_syntax_styles() if len(available_syntax_styles) > 0: self.syntax_style_menu = self.view_menu.addMenu("&Syntax Style") style_group = QtGui.QActionGroup(self) for style in available_syntax_styles: action = QtGui.QAction( "{}".format(style), self, triggered=lambda v, syntax_style=style: self. set_syntax_style(syntax_style=syntax_style)) action.setCheckable(True) style_group.addAction(action) self.syntax_style_menu.addAction(action) if style == 'default': action.setChecked(True) self.syntax_style_menu.setDefaultAction(action)
def initUI(self): """Initialise the user-interface elements""" # Create the main-frame widget, and the layout self.mainFrame = QtGui.QWidget() self.setCentralWidget(self.mainFrame) self.hbox = QtGui.QHBoxLayout() # HBox contains all widgets # Menu item: open par/tim files self.openParTimAction = QtGui.QAction('&Open par/tim', self) self.openParTimAction.setShortcut('Ctrl+O') self.openParTimAction.setStatusTip('Open par/tim') self.openParTimAction.triggered.connect(self.openParTim) # Menu item: exit Qtip self.exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self) self.exitAction.setShortcut('Ctrl+Q') self.exitAction.setStatusTip('Exit application') self.exitAction.triggered.connect(self.close) # Previously, it was possible to switch out the 'plk' widget for another # main widget (the binary pulsar one). That one has been stripped out # now, so for now it makes no sense to 'toggle' on or off the plk # widget. However, the option is still there for now... self.togglePlkAction = QtGui.QAction('&Plk', self) self.togglePlkAction.setShortcut('Ctrl+P') self.togglePlkAction.setStatusTip('Toggle plk widget') self.togglePlkAction.triggered.connect(self.togglePlk) # Menu item: toggle the Jupyter window self.toggleJupyterAction = QtGui.QAction('&Jupyter', self) self.toggleJupyterAction.setShortcut('Ctrl+J') self.toggleJupyterAction.setStatusTip('Toggle Jupyter') self.toggleJupyterAction.triggered.connect(self.toggleJupyter) # Menu item: about Qtip self.aboutAction = QtGui.QAction('&About', self) self.aboutAction.setShortcut('Ctrl+A') self.aboutAction.setStatusTip('About Qtip') self.aboutAction.triggered.connect(self.onAbout) # The status bar self.theStatusBar = QtGui.QStatusBar() #self.statusBar() self.setStatusBar(self.theStatusBar) # A label that shows what engine is being used (hardcoded: PINT) self.engine_label = QtGui.QLabel("PINT") self.engine_label.setFrameStyle( QtGui.QFrame.Sunken|QtGui.QFrame.Panel) self.engine_label.setLineWidth(4) self.engine_label.setMidLineWidth(4) self.engine_label.setStyleSheet("QLabel{color:black;background-color:red}") self.theStatusBar.addPermanentWidget(self.engine_label) # On OSX, make sure the menu can be displayed (in the window itself) if sys.platform == 'darwin': # On OSX, the menubar is usually on the top of the screen, not in # the window. To make it in the window: QtGui.qt_mac_set_native_menubar(False) # Otherwise, if we'd like to get the system menubar at the top, then # we need another menubar object, not self.menuBar as below. In that # case, use: # self.menubar = QtGui.QMenuBar() # TODO: Somehow this does not work. Per-window one does though # Create the menu bar, and link the action items self.menubar = self.menuBar() self.fileMenu = self.menubar.addMenu('&File') self.fileMenu.addAction(self.openParTimAction) self.fileMenu.addAction(self.exitAction) self.viewMenu = self.menubar.addMenu('&View') self.viewMenu.addAction(self.togglePlkAction) self.viewMenu.addAction(self.toggleJupyterAction) self.helpMenu = self.menubar.addMenu('&Help') self.helpMenu.addAction(self.aboutAction) # What is the status quo of the user interface? self.showJupyter = False self.whichWidget = 'None' self.prevShowJupyter = None self.prevWhichWidget = 'None'
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)
def initUI(self): """ Initialise the user-interface elements """ # Create the main-frame widget, and the layout self.mainFrame = QtGui.QWidget() self.setCentralWidget(self.mainFrame) self.hbox = QtGui.QHBoxLayout() # HBox contains all widgets # Create the menu action items self.openParTimAction = QtGui.QAction('&Open par/tim', self) self.openParTimAction.setShortcut('Ctrl+O') self.openParTimAction.setStatusTip('Open par/tim') self.openParTimAction.triggered.connect(self.openParTim) self.exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self) self.exitAction.setShortcut('Ctrl+Q') self.exitAction.setStatusTip('Exit application') self.exitAction.triggered.connect(self.close) self.togglePlkAction = QtGui.QAction('&Plk', self) self.togglePlkAction.setShortcut('Ctrl+P') self.togglePlkAction.setStatusTip('Toggle plk widget') self.togglePlkAction.triggered.connect(self.togglePlk) self.toggleIPythonAction = QtGui.QAction('&IPython', self) self.toggleIPythonAction.setShortcut('Ctrl+I') self.toggleIPythonAction.setStatusTip('Toggle IPython') self.toggleIPythonAction.triggered.connect(self.toggleIPython) self.toggleParEditAction = QtGui.QAction('&ParEdit', self) self.toggleParEditAction.setShortcut('Ctrl+E') self.toggleParEditAction.setStatusTip('Toggle ParEdit') self.toggleParEditAction.triggered.connect(self.toggleParEdit) self.aboutAction = QtGui.QAction('&About', self) self.aboutAction.setShortcut('Ctrl+A') self.aboutAction.setStatusTip('About Qtip') self.aboutAction.triggered.connect(self.onAbout) self.theStatusBar = QtGui.QStatusBar() #self.statusBar() self.setStatusBar(self.theStatusBar) self.engine_label = QtGui.QLabel("PINT") self.engine_label.setFrameStyle(QtGui.QFrame.Sunken | QtGui.QFrame.Panel) self.engine_label.setLineWidth(4) self.engine_label.setMidLineWidth(4) self.engine_label.setStyleSheet( "QLabel{color:black;background-color:red}") self.theStatusBar.addPermanentWidget(self.engine_label) # On OSX, make sure the menu can be displayed (in the window itself) if sys.platform == 'darwin': # On OSX, the menubar is usually on the top of the screen, not in # the window. To make it in the window: QtGui.qt_mac_set_native_menubar(False) # Otherwise, if we'd like to get the system menubar at the top, then # we need another menubar object, not self.menuBar as below. In that # case, use: # self.menubar = QtGui.QMenuBar() # TODO: Somehow this does not work. Per-window one does though # Create the menu self.menubar = self.menuBar() self.fileMenu = self.menubar.addMenu('&File') self.fileMenu.addAction(self.openParTimAction) self.fileMenu.addAction(self.exitAction) self.viewMenu = self.menubar.addMenu('&View') self.viewMenu.addAction(self.togglePlkAction) self.viewMenu.addAction(self.toggleParEditAction) self.viewMenu.addAction(self.toggleIPythonAction) self.helpMenu = self.menubar.addMenu('&Help') self.helpMenu.addAction(self.aboutAction) # What is the status quo of the user interface? self.showIPython = False self.whichWidget = 'None' self.prevShowIPython = None self.prevWhichWidget = 'None'
def initUI(self): # Create a toolbar self.toolbar = self.addToolBar('Tools') # Add the tool buttons iconDir = os.path.join(os.path.dirname(sys.argv[0]), 'icons') # Loading a new city loadAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'open.png')), '&Tools', self) loadAction.setShortcuts(['o']) self.setTip(loadAction, 'Open city') loadAction.triggered.connect(self.getCityFromUser) self.toolbar.addAction(loadAction) # Open previous image backAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'back.png')), '&Tools', self) backAction.setShortcut('left') backAction.setStatusTip('Previous image') backAction.triggered.connect(self.prevImage) self.toolbar.addAction(backAction) self.actImageNotFirst.append(backAction) # Open next image nextAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'next.png')), '&Tools', self) nextAction.setShortcut('right') self.setTip(nextAction, 'Next image') nextAction.triggered.connect(self.nextImage) self.toolbar.addAction(nextAction) self.actImageNotLast.append(nextAction) # Play playAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'play.png')), '&Tools', self) playAction.setShortcut(' ') playAction.setCheckable(True) playAction.setChecked(False) self.setTip(playAction, 'Play all images') playAction.triggered.connect(self.playImages) self.toolbar.addAction(playAction) self.actImageNotLast.append(playAction) self.playAction = playAction # Select image selImageAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'shuffle.png')), '&Tools', self) selImageAction.setShortcut('i') self.setTip(selImageAction, 'Select image') selImageAction.triggered.connect(self.selectImage) self.toolbar.addAction(selImageAction) self.actImage.append(selImageAction) # Enable/disable disparity visu. Toggle button if self.enableDisparity: dispAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'disp.png')), '&Tools', self) dispAction.setShortcuts(['d']) dispAction.setCheckable(True) dispAction.setChecked(self.showDisparity) self.setTip(dispAction, 'Enable/disable depth visualization') dispAction.toggled.connect(self.dispToggle) self.toolbar.addAction(dispAction) self.actImage.append(dispAction) # Enable/disable zoom. Toggle button zoomAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'zoom.png')), '&Tools', self) zoomAction.setShortcuts(['z']) zoomAction.setCheckable(True) zoomAction.setChecked(self.zoom) self.setTip(zoomAction, 'Enable/disable permanent zoom') zoomAction.toggled.connect(self.zoomToggle) self.toolbar.addAction(zoomAction) self.actImage.append(zoomAction) # Decrease transparency minusAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'minus.png')), '&Tools', self) minusAction.setShortcut('-') self.setTip(minusAction, 'Decrease transparency') minusAction.triggered.connect(self.minus) self.toolbar.addAction(minusAction) # Increase transparency plusAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'plus.png')), '&Tools', self) plusAction.setShortcut('+') self.setTip(plusAction, 'Increase transparency') plusAction.triggered.connect(self.plus) self.toolbar.addAction(plusAction) # Display path to current image in message bar displayFilepathAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'filepath.png')), '&Tools', self) displayFilepathAction.setShortcut('f') self.setTip(displayFilepathAction, 'Show path to current image') displayFilepathAction.triggered.connect(self.displayFilepath) self.toolbar.addAction(displayFilepathAction) # Display help message helpAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'help19.png')), '&Tools', self) helpAction.setShortcut('h') self.setTip(helpAction, 'Help') helpAction.triggered.connect(self.displayHelpMessage) self.toolbar.addAction(helpAction) # Close the application exitAction = QtGui.QAction(QtGui.QIcon(os.path.join(iconDir, 'exit.png')), '&Tools', self) exitAction.setShortcuts(['Esc']) self.setTip(exitAction, 'Exit') exitAction.triggered.connect(self.close) self.toolbar.addAction(exitAction) # The default text for the status bar self.defaultStatusbar = 'Ready' # Create a statusbar. Init with default self.statusBar().showMessage(self.defaultStatusbar) # Enable mouse move events self.setMouseTracking(True) self.toolbar.setMouseTracking(True) # Open in full screen self.showFullScreen() # Set a title self.applicationTitle = 'Cityscapes Viewer v1.0' self.setWindowTitle(self.applicationTitle) self.displayHelpMessage() self.getCityFromUser() # And show the application self.show()