QScintilla/ShellWindow.py

changeset 5710
b5809b948010
parent 5709
f81d0eca2c62
child 5711
50b6867ffcd3
--- a/QScintilla/ShellWindow.py	Thu Apr 20 20:09:53 2017 +0200
+++ b/QScintilla/ShellWindow.py	Fri Apr 21 19:39:31 2017 +0200
@@ -9,10 +9,10 @@
 
 from __future__ import unicode_literals
 
-from PyQt5.QtCore import QCoreApplication, QPoint, QSize, QSignalMapper
+from PyQt5.QtCore import Qt, QCoreApplication, QPoint, QSize, QSignalMapper
 from PyQt5.QtGui import QKeySequence
 from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QAction, \
-    QWhatsThis
+    QWhatsThis, QDialog
 from PyQt5.Qsci import QsciScintilla
 
 from E5Gui.E5MainWindow import E5MainWindow
@@ -21,6 +21,7 @@
 from E5Gui.E5ZoomWidget import E5ZoomWidget
 from E5Gui import E5MessageBox
 
+import UI.Config
 import UI.PixmapCache
 import Preferences
 
@@ -58,9 +59,9 @@
         self.__apisManager = APIsManager(parent=self)
         
         # initialize the debug server and shell widgets
-        self.__debugServer = DebugServer()
+        self.__debugServer = DebugServer(preventPassiveDebugging=True)
         self.__shell = Shell(self.__debugServer, self, True, self)
-        self.__searchWidget = SearchWidget(self.__shell, self)
+        self.__searchWidget = SearchWidget(self.__shell, self, showLine=True)
         
         centralWidget = QWidget()
         layout = QVBoxLayout()
@@ -71,7 +72,6 @@
         self.setCentralWidget(centralWidget)
         self.__searchWidget.hide()
         
-        
         self.__searchWidget.searchNext.connect(self.__shell.searchNext)
         self.__searchWidget.searchPrevious.connect(self.__shell.searchPrev)
         self.__shell.searchStringFound.connect(
@@ -80,8 +80,8 @@
         self.__shell.zoomValueChanged.connect(self.__zoomValueChanged)
         
         self.__createActions()
-##        self.__createMenus()
-##        self.__createToolBars()
+        self.__createMenus()
+        self.__createToolBars()
         self.__createStatusBar()
         
         self.__readSettings()
@@ -155,7 +155,9 @@
         self.__createFileActions()
         self.__createEditActions()
         self.__createSearchActions()
+        self.__createViewActions()
         self.__createHelpActions()
+        self.__createHistoryActions()
         
         # read the keyboard shortcuts and make them identical to the main
         # eric6 shortcuts
@@ -202,6 +204,35 @@
 ##        ))
 ##        self.newWindowAct.triggered.connect(self.__newWindow)
 ##        self.fileActions.append(self.newWindowAct)
+
+        self.restartAct = E5Action(
+            self.tr('Restart'),
+            UI.PixmapCache.getIcon("restart.png"),
+            self.tr('Restart'),
+            0, 0, self, 'shell_restart')
+        self.restartAct.setStatusTip(self.tr(
+            'Restart the shell'))
+        self.restartAct.setWhatsThis(self.tr(
+            """<b>Restart</b>"""
+            """<p>Restart the shell for the currently selected language.</p>"""
+        ))
+        self.restartAct.triggered.connect(self.__doRestart)
+        self.fileActions.append(self.restartAct)
+
+        self.clearRestartAct = E5Action(
+            self.tr('Restart and Clear'),
+            UI.PixmapCache.getIcon("restartDelete.png"),
+            self.tr('Restart and Clear'),
+            Qt.Key_F4, 0, self, 'shell_clear_restart')
+        self.clearRestartAct.setStatusTip(self.tr(
+            'Clear the window and restart the shell'))
+        self.clearRestartAct.setWhatsThis(self.tr(
+            """<b>Restart and Clear</b>"""
+            """<p>Clear the shell window and restart the shell for the"""
+            """ currently selected language.</p>"""
+        ))
+        self.clearRestartAct.triggered.connect(self.__doClearRestart)
+        self.fileActions.append(self.clearRestartAct)
     
     def __createEditActions(self):
         """
@@ -271,7 +302,7 @@
         self.pasteAct.triggered.connect(self.__shell.paste)
         self.editActions.append(self.pasteAct)
         
-        self.deleteAct = E5Action(
+        self.clearAct = E5Action(
             QCoreApplication.translate('ViewManager', 'Clear'),
             UI.PixmapCache.getIcon("editDelete.png"),
             QCoreApplication.translate('ViewManager', 'Clear'),
@@ -279,15 +310,15 @@
                 'ViewManager', "Alt+Shift+C", "Edit|Clear")),
             0,
             self.copyActGrp, 'vm_edit_clear')
-        self.deleteAct.setStatusTip(QCoreApplication.translate(
+        self.clearAct.setStatusTip(QCoreApplication.translate(
             'ViewManager', 'Clear all text'))
-        self.deleteAct.setWhatsThis(QCoreApplication.translate(
+        self.clearAct.setWhatsThis(QCoreApplication.translate(
             'ViewManager',
             """<b>Clear</b>"""
             """<p>Delete all text of the current editor.</p>"""
         ))
-        self.deleteAct.triggered.connect(self.__shell.clear)
-        self.editActions.append(self.deleteAct)
+        self.clearAct.triggered.connect(self.__shell.clear)
+        self.editActions.append(self.clearAct)
         
         self.cutAct.setEnabled(False)
         self.copyAct.setEnabled(False)
@@ -667,7 +698,7 @@
             QKeySequence(QCoreApplication.translate(
                 'ViewManager', "Ctrl+F", "Search|Search")),
             0,
-            self.searchActGrp, 'vm_search')
+            self, 'vm_search')
         self.searchAct.setStatusTip(QCoreApplication.translate(
             'ViewManager', 'Search for a text'))
         self.searchAct.setWhatsThis(QCoreApplication.translate(
@@ -688,7 +719,7 @@
             QKeySequence(QCoreApplication.translate(
                 'ViewManager', "F3", "Search|Search next")),
             0,
-            self.searchActGrp, 'vm_search_next')
+            self, 'vm_search_next')
         self.searchNextAct.setStatusTip(QCoreApplication.translate(
             'ViewManager', 'Search next occurrence of text'))
         self.searchNextAct.setWhatsThis(QCoreApplication.translate(
@@ -709,7 +740,7 @@
             QKeySequence(QCoreApplication.translate(
                 'ViewManager', "Shift+F3", "Search|Search previous")),
             0,
-            self.searchActGrp, 'vm_search_previous')
+            self, 'vm_search_previous')
         self.searchPrevAct.setStatusTip(QCoreApplication.translate(
             'ViewManager', 'Search previous occurrence of text'))
         self.searchPrevAct.setWhatsThis(QCoreApplication.translate(
@@ -729,7 +760,6 @@
         commands.
         """
         self.viewActGrp = createActionGroup(self)
-        self.viewFoldActGrp = createActionGroup(self)
         
         self.zoomInAct = E5Action(
             QCoreApplication.translate('ViewManager', 'Zoom in'),
@@ -807,6 +837,40 @@
         self.zoomToAct.triggered.connect(self.__zoom)
         self.viewActions.append(self.zoomToAct)
     
+    def __createHistoryActions(self):
+        """
+        Private method defining the user interface actions for the history
+        commands.
+        """
+        self.showHistoryAct = E5Action(
+            self.tr('Show History'),
+            UI.PixmapCache.getIcon("history.png"),
+            self.tr('&Show History...'),
+            0, 0,
+            self, 'shell_show_history')
+        self.showHistoryAct.setStatusTip(self.tr(
+            "Show the shell history in a dialog"))
+        self.showHistoryAct.triggered.connect(self.__shell.showHistory)
+        
+        self.clearHistoryAct = E5Action(
+            self.tr('Clear History'),
+            UI.PixmapCache.getIcon("historyClear.png"),
+            self.tr('&Clear History...'),
+            0, 0,
+            self, 'shell_clear_history')
+        self.clearHistoryAct.setStatusTip(self.tr(
+            "Clear the shell history"))
+        self.clearHistoryAct.triggered.connect(self.__shell.clearHistory)
+        
+        self.selectHistoryAct = E5Action(
+            self.tr('Select History Entry'),
+            self.tr('Select History &Entry'),
+            0, 0,
+            self, 'shell_select_history')
+        self.selectHistoryAct.setStatusTip(self.tr(
+            "Select an entry of the shell history"))
+        self.selectHistoryAct.triggered.connect(self.__shell.selectHistory)
+    
     def __createHelpActions(self):
         """
         Private method to create the Help actions.
@@ -857,13 +921,17 @@
     
     def __showFind(self):
         """
-        Public method to display the search widget.
+        Private method to display the search widget.
         """
-        self.__searchWidget.showFind("")
+        txt = self.__shell.selectedText()
+        self.__searchWidget.showFind(txt)
     
     def activeWindow(self):
         """
         Public method to get a reference to the active shell.
+        
+        @return reference to the shell widget
+        @rtype Shell
         """
         return self.__shell
     
@@ -891,6 +959,19 @@
         """
         e5App().closeAllWindows()
     
+    def __doRestart(self):
+        """
+        Private slot to handle the 'restart' menu entry.
+        """
+        self.__debugServer.startClient(False)
+    
+    def __doClearRestart(self):
+        """
+        Private slot to handle the 'restart and clear' menu entry.
+        """
+        self.__doRestart()
+        self.__shell.clear()
+    
     ##################################################################
     ## Below are the action methods for the view menu
     ##################################################################
@@ -951,21 +1032,19 @@
         """
         Private slot to show a little About message.
         """
-        # TODO: change this text
         E5MessageBox.about(
             self,
-            self.tr("About eric6 Mini Editor"),
+            self.tr("About eric6 Shell Window"),
             self.tr(
-                "The eric6 Mini Editor is an editor component"
-                " based on QScintilla. It may be used for simple"
-                " editing tasks, that don't need the power of"
-                " a full blown editor."))
+                "The eric6 Shell is a standalone shell window."
+                " It uses the same backend as the debugger of"
+                " the full IDE, but is executed independently."))
     
     def __aboutQt(self):
         """
         Private slot to handle the About Qt dialog.
         """
-        E5MessageBox.aboutQt(self, "eric6 Shell windindow")
+        E5MessageBox.aboutQt(self, "eric6 Shell Window")
     
     def __whatsThis(self):
         """
@@ -974,6 +1053,126 @@
         QWhatsThis.enterWhatsThisMode()
     
     ##################################################################
+    ## Below are the main menu handling methods
+    ##################################################################
+    
+    def __createMenus(self):
+        """
+        Private method to create the menus of the menu bar.
+        """
+        self.__fileMenu = self.menuBar().addMenu(self.tr("&File"))
+        self.__fileMenu.setTearOffEnabled(True)
+##        self.__fileMenu.addAction(self.newAct)
+##        self.__fileMenu.addSeparator()
+        self.__fileMenu.addAction(self.restartAct)
+        self.__fileMenu.addAction(self.clearRestartAct)
+        self.__fileMenu.addSeparator()
+        self.__fileMenu.addAction(self.exitAct)
+        
+        self.__editMenu = self.menuBar().addMenu(self.tr("&Edit"))
+        self.__editMenu.setTearOffEnabled(True)
+        self.__editMenu.addAction(self.cutAct)
+        self.__editMenu.addAction(self.copyAct)
+        self.__editMenu.addAction(self.pasteAct)
+        self.__editMenu.addAction(self.clearAct)
+        self.__editMenu.addSeparator()
+        self.__editMenu.addAction(self.searchAct)
+        self.__editMenu.addAction(self.searchNextAct)
+        self.__editMenu.addAction(self.searchPrevAct)
+        
+        self.__viewMenu = self.menuBar().addMenu(self.tr("&View"))
+        self.__viewMenu.setTearOffEnabled(True)
+        self.__viewMenu.addAction(self.zoomInAct)
+        self.__viewMenu.addAction(self.zoomOutAct)
+        self.__viewMenu.addAction(self.zoomResetAct)
+        self.__viewMenu.addAction(self.zoomToAct)
+        
+        self.__historyMenu = self.menuBar().addMenu(self.tr("Histor&y"))
+        self.__historyMenu.setTearOffEnabled(True)
+        self.__historyMenu.addAction(self.selectHistoryAct)
+        self.__historyMenu.addAction(self.showHistoryAct)
+        self.__historyMenu.addAction(self.clearHistoryAct)
+        
+        self.__startMenu = self.menuBar().addMenu(self.tr("&Start"))
+        self.__startMenu.aboutToShow.connect(self.__showLanguageMenu)
+        self.__startMenu.triggered.connect(self.__startShell)
+        
+        self.menuBar().addSeparator()
+        
+        self.__helpMenu = self.menuBar().addMenu(self.tr("&Help"))
+        self.__helpMenu.setTearOffEnabled(True)
+        self.__helpMenu.addAction(self.aboutAct)
+        self.__helpMenu.addAction(self.aboutQtAct)
+        self.__helpMenu.addSeparator()
+        self.__helpMenu.addAction(self.whatsThisAct)
+    
+    def __showLanguageMenu(self):
+        """
+        Private slot to prepare the language menu.
+        """
+        self.__startMenu.clear()
+        clientLanguages = self.__debugServer.getSupportedLanguages(
+            shellOnly=True)
+        for language in sorted(clientLanguages):
+            act = self.__startMenu.addAction(language)
+            act.setData(language)
+    
+    def __startShell(self, action):
+        """
+        Private slot to start a shell according to the action triggered.
+        
+        @param action menu action that was triggered (QAction)
+        """
+        language = action.data()
+        self.__debugServer.startClient(False, language)
+    
+    ##################################################################
+    ## Below are the toolbar handling methods
+    ##################################################################
+    
+    def __createToolBars(self):
+        """
+        Private method to create the various toolbars.
+        """
+        filetb = self.addToolBar(self.tr("File"))
+        filetb.setIconSize(UI.Config.ToolBarIconSize)
+##        filetb.addAction(self.newAct)
+        filetb.addSeparator()
+        filetb.addAction(self.restartAct)
+        filetb.addAction(self.clearRestartAct)
+        filetb.addSeparator()
+        filetb.addAction(self.exitAct)
+        
+        edittb = self.addToolBar(self.tr("Edit"))
+        edittb.setIconSize(UI.Config.ToolBarIconSize)
+        edittb.addAction(self.cutAct)
+        edittb.addAction(self.copyAct)
+        edittb.addAction(self.pasteAct)
+        edittb.addAction(self.clearAct)
+        
+        findtb = self.addToolBar(self.tr("Find"))
+        findtb.setIconSize(UI.Config.ToolBarIconSize)
+        findtb.addAction(self.searchAct)
+        findtb.addAction(self.searchNextAct)
+        findtb.addAction(self.searchPrevAct)
+        
+        viewtb = self.addToolBar(self.tr("View"))
+        viewtb.setIconSize(UI.Config.ToolBarIconSize)
+        viewtb.addAction(self.zoomInAct)
+        viewtb.addAction(self.zoomOutAct)
+        viewtb.addAction(self.zoomResetAct)
+        viewtb.addAction(self.zoomToAct)
+        
+        historytb = self.addToolBar(self.tr("History"))
+        historytb.setIconSize(UI.Config.ToolBarIconSize)
+        historytb.addAction(self.showHistoryAct)
+        historytb.addAction(self.clearHistoryAct)
+        
+        helptb = self.addToolBar(self.tr("Help"))
+        helptb.setIconSize(UI.Config.ToolBarIconSize)
+        helptb.addAction(self.whatsThisAct)
+    
+    ##################################################################
     ## Below are the status bar handling methods
     ##################################################################
     

eric ide

mercurial