From 2230abab2b68ea572b676641e441a0b403ee29c5 2011-10-17 08:46:32 From: Matthias BUSSONNIER Date: 2011-10-17 08:46:32 Subject: [PATCH] disable some QAction by default, remove OSX only, wrap in try/except --- diff --git a/IPython/frontend/qt/console/console_widget.py b/IPython/frontend/qt/console/console_widget.py index 8acacfc..d965466 100644 --- a/IPython/frontend/qt/console/console_widget.py +++ b/IPython/frontend/qt/console/console_widget.py @@ -279,6 +279,7 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): shortcut="Ctrl+Z", statusTip="Undo last action if possible", triggered=self._control.undo) + self.undo_action.setDisabled(True) self.addAction(self.undo_action) self.redo_action = QtGui.QAction("Redo", @@ -286,36 +287,42 @@ class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): shortcut="Ctrl+Shift+Z", statusTip="Redo last action if possible", triggered=self._control.redo) + self.redo_action.setDisabled(True) self.addAction(self.redo_action) self.reset_action = QtGui.QAction("Reset", self, statusTip="Clear all varible from workspace", triggered=self.reset_magic) + self.reset_action.setDisabled(True) self.addAction(self.reset_action) self.clear_action = QtGui.QAction("Clear", self, statusTip="Clear the console", triggered=self.clear_magic) + self.clear_action.setDisabled(True) self.addAction(self.clear_action) self.who_action = QtGui.QAction("Who", self, statusTip="List interactive variable", triggered=self.who_magic) + self.who_action.setDisabled(True) self.addAction(self.who_action) self.whos_action = QtGui.QAction("Whos", self, statusTip="List interactive variable with detail", triggered=self.whos_magic) + self.whos_action.setDisabled(True) self.addAction(self.whos_action) self.who_ls_action = QtGui.QAction("Who ls", self, statusTip="Return a list of interactive variable", triggered=self.who_ls_magic) + self.who_ls_action.setDisabled(True) self.addAction(self.who_ls_action) diff --git a/IPython/frontend/qt/console/history_console_widget.py b/IPython/frontend/qt/console/history_console_widget.py index dcf3c96..6bd18d4 100644 --- a/IPython/frontend/qt/console/history_console_widget.py +++ b/IPython/frontend/qt/console/history_console_widget.py @@ -35,12 +35,14 @@ class HistoryConsoleWidget(ConsoleWidget): self, statusTip="show command history", triggered=self.history_magic) + self.history_action.setDisabled(True) self.addAction(self.history_action) self.save_action = QtGui.QAction("Export History ", self, statusTip="Export History as Python File", triggered=self.save_magic) + self.save_action.setDisabled(True) self.addAction(self.save_action) #--------------------------------------------------------------------------- diff --git a/IPython/frontend/qt/console/qtconsoleapp.py b/IPython/frontend/qt/console/qtconsoleapp.py index a6c2317..a01b8e1 100644 --- a/IPython/frontend/qt/console/qtconsoleapp.py +++ b/IPython/frontend/qt/console/qtconsoleapp.py @@ -103,44 +103,110 @@ class MainWindow(QtGui.QMainWindow): # it with possible action, don't do it on other platform # as some user might not want the menu bar, or give them # an option to remove it - if sys.platform == 'darwin': - #create menu in the order they should appear in the menu bar - self.fileMenu = self.menuBar().addMenu("File") - self.editMenu = self.menuBar().addMenu("Edit") - self.fontMenu = self.menuBar().addMenu("Font") - self.windowMenu = self.menuBar().addMenu("Window") - self.magicMenu = self.menuBar().addMenu("Magic") - - # 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 loose - # this search field fonctionnality - - self.helpMenu = self.menuBar().addMenu("Help") - - # sould wrap every line of the following block into a try/except, - # as we are not sure of instanciating a _frontend which support all - # theses actions, but there might be a better way + def initMenuBar(self): + #create menu in the order they should appear in the menu bar + self.fileMenu = self.menuBar().addMenu("File") + self.editMenu = self.menuBar().addMenu("Edit") + self.fontMenu = self.menuBar().addMenu("Font") + self.windowMenu = self.menuBar().addMenu("Window") + self.magicMenu = self.menuBar().addMenu("Magic") + + # 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 loose + # this search field fonctionnality + + self.helpMenu = self.menuBar().addMenu("Help") + + # sould wrap every line of the following block into a try/except, + # as we are not sure of instanciating a _frontend which support all + # theses actions, but there might be a better way + try: self.fileMenu.addAction(self._frontend.print_action) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.fileMenu.addAction(self._frontend.export_action) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.fileMenu.addAction(self._frontend.select_all_action) + except AttributeError: + print "trying to add unexisting action, skipping" + try: self.editMenu.addAction(self._frontend.undo_action) + self._frontend.undo_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.editMenu.addAction(self._frontend.redo_action) + self._frontend.redo_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + try: self.fontMenu.addAction(self._frontend.increase_font_size) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.fontMenu.addAction(self._frontend.decrease_font_size) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.fontMenu.addAction(self._frontend.reset_font_size) + except AttributeError: + print "trying to add unexisting action, skipping" + try: self.magicMenu.addAction(self._frontend.reset_action) + self._frontend.reset_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.magicMenu.addAction(self._frontend.history_action) + self._frontend.history_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.magicMenu.addAction(self._frontend.save_action) + self._frontend.save_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.magicMenu.addAction(self._frontend.clear_action) + self._frontend.clear_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.magicMenu.addAction(self._frontend.who_action) + self._frontend.who_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.magicMenu.addAction(self._frontend.who_ls_action) + self._frontend.who_ls_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + + try: self.magicMenu.addAction(self._frontend.whos_action) + self._frontend.whos_action.setEnabled(True) + except AttributeError: + print "trying to add unexisting action, skipping" + #--------------------------------------------------------------------------- # QWidget interface @@ -537,6 +603,7 @@ class IPythonQtConsoleApp(BaseIPythonApplication): self.window = MainWindow(self.app, self.widget, self.existing, may_close=local_kernel, confirm_exit=self.confirm_exit) + self.window.initMenuBar() self.window.setWindowTitle('Python' if self.pure else 'IPython') def init_colors(self):