944:1b59c4ba121e | 945:8cd4d08fa9f6 |
---|---|
25 | 25 |
26 from Debugger.DebugClientCapabilities import HasCompleter | 26 from Debugger.DebugClientCapabilities import HasCompleter |
27 | 27 |
28 from .ShellHistoryDialog import ShellHistoryDialog | 28 from .ShellHistoryDialog import ShellHistoryDialog |
29 | 29 |
30 | |
30 class Shell(QsciScintillaCompat): | 31 class Shell(QsciScintillaCompat): |
31 """ | 32 """ |
32 Class implementing a graphical Python shell. | 33 Class implementing a graphical Python shell. |
33 | 34 |
34 A user can enter commands that are executed in the remote | 35 A user can enter commands that are executed in the remote |
35 Python interpreter. | 36 Python interpreter. |
36 """ | 37 """ |
37 def __init__(self, dbs, vm, parent = None): | 38 def __init__(self, dbs, vm, parent=None): |
38 """ | 39 """ |
39 Constructor | 40 Constructor |
40 | 41 |
41 @param dbs reference to the debug server object | 42 @param dbs reference to the debug server object |
42 @param vm reference to the viewmanager object | 43 @param vm reference to the viewmanager object |
136 if self.passive: | 137 if self.passive: |
137 self.__getBanner() | 138 self.__getBanner() |
138 | 139 |
139 # Create a little language context menu | 140 # Create a little language context menu |
140 self.lmenu = QMenu(self.trUtf8('Start')) | 141 self.lmenu = QMenu(self.trUtf8('Start')) |
141 self.clientLanguages = self.dbs.getSupportedLanguages(shellOnly = True) | 142 self.clientLanguages = self.dbs.getSupportedLanguages(shellOnly=True) |
142 self.clientLanguages.sort() | 143 self.clientLanguages.sort() |
143 for language in self.clientLanguages: | 144 for language in self.clientLanguages: |
144 act = self.lmenu.addAction(language) | 145 act = self.lmenu.addAction(language) |
145 act.setData(language) | 146 act.setData(language) |
146 self.lmenu.triggered.connect(self.__startDebugClient) | 147 self.lmenu.triggered.connect(self.__startDebugClient) |
179 | 180 |
180 self.incrementalSearchString = "" | 181 self.incrementalSearchString = "" |
181 self.incrementalSearchActive = False | 182 self.incrementalSearchActive = False |
182 | 183 |
183 self.supportedEditorCommands = { | 184 self.supportedEditorCommands = { |
184 QsciScintilla.SCI_LINEDELETE : self.__clearCurrentLine, | 185 QsciScintilla.SCI_LINEDELETE: self.__clearCurrentLine, |
185 QsciScintilla.SCI_TAB : self.__QScintillaTab, | 186 QsciScintilla.SCI_TAB: self.__QScintillaTab, |
186 QsciScintilla.SCI_NEWLINE : self.__QScintillaNewline, | 187 QsciScintilla.SCI_NEWLINE: self.__QScintillaNewline, |
187 | 188 |
188 QsciScintilla.SCI_DELETEBACK : self.__QScintillaDeleteBack, | 189 QsciScintilla.SCI_DELETEBACK: self.__QScintillaDeleteBack, |
189 QsciScintilla.SCI_CLEAR : self.__QScintillaDelete, | 190 QsciScintilla.SCI_CLEAR: self.__QScintillaDelete, |
190 QsciScintilla.SCI_DELWORDLEFT : self.__QScintillaDeleteWordLeft, | 191 QsciScintilla.SCI_DELWORDLEFT: self.__QScintillaDeleteWordLeft, |
191 QsciScintilla.SCI_DELWORDRIGHT : self.__QScintillaDeleteWordRight, | 192 QsciScintilla.SCI_DELWORDRIGHT: self.__QScintillaDeleteWordRight, |
192 QsciScintilla.SCI_DELLINELEFT : self.__QScintillaDeleteLineLeft, | 193 QsciScintilla.SCI_DELLINELEFT: self.__QScintillaDeleteLineLeft, |
193 QsciScintilla.SCI_DELLINERIGHT : self.__QScintillaDeleteLineRight, | 194 QsciScintilla.SCI_DELLINERIGHT: self.__QScintillaDeleteLineRight, |
194 | 195 |
195 QsciScintilla.SCI_CHARLEFT : self.__QScintillaCharLeft, | 196 QsciScintilla.SCI_CHARLEFT: self.__QScintillaCharLeft, |
196 QsciScintilla.SCI_CHARRIGHT : self.__QScintillaCharRight, | 197 QsciScintilla.SCI_CHARRIGHT: self.__QScintillaCharRight, |
197 QsciScintilla.SCI_WORDLEFT : self.__QScintillaWordLeft, | 198 QsciScintilla.SCI_WORDLEFT: self.__QScintillaWordLeft, |
198 QsciScintilla.SCI_WORDRIGHT : self.__QScintillaWordRight, | 199 QsciScintilla.SCI_WORDRIGHT: self.__QScintillaWordRight, |
199 QsciScintilla.SCI_VCHOME : self.__QScintillaVCHome, | 200 QsciScintilla.SCI_VCHOME: self.__QScintillaVCHome, |
200 QsciScintilla.SCI_LINEEND : self.__QScintillaLineEnd, | 201 QsciScintilla.SCI_LINEEND: self.__QScintillaLineEnd, |
201 QsciScintilla.SCI_LINEUP : self.__QScintillaLineUp, | 202 QsciScintilla.SCI_LINEUP: self.__QScintillaLineUp, |
202 QsciScintilla.SCI_LINEDOWN : self.__QScintillaLineDown, | 203 QsciScintilla.SCI_LINEDOWN: self.__QScintillaLineDown, |
203 | 204 |
204 QsciScintilla.SCI_PAGEUP : self.__QScintillaAutoCompletionCommand, | 205 QsciScintilla.SCI_PAGEUP: self.__QScintillaAutoCompletionCommand, |
205 QsciScintilla.SCI_PAGEDOWN : self.__QScintillaAutoCompletionCommand, | 206 QsciScintilla.SCI_PAGEDOWN: self.__QScintillaAutoCompletionCommand, |
206 QsciScintilla.SCI_CANCEL : self.__QScintillaAutoCompletionCommand, | 207 QsciScintilla.SCI_CANCEL: self.__QScintillaAutoCompletionCommand, |
207 | 208 |
208 QsciScintilla.SCI_CHARLEFTEXTEND : self.__QScintillaCharLeftExtend, | 209 QsciScintilla.SCI_CHARLEFTEXTEND: self.__QScintillaCharLeftExtend, |
209 QsciScintilla.SCI_CHARRIGHTEXTEND : self.extendSelectionRight, | 210 QsciScintilla.SCI_CHARRIGHTEXTEND: self.extendSelectionRight, |
210 QsciScintilla.SCI_WORDLEFTEXTEND : self.__QScintillaWordLeftExtend, | 211 QsciScintilla.SCI_WORDLEFTEXTEND: self.__QScintillaWordLeftExtend, |
211 QsciScintilla.SCI_WORDRIGHTEXTEND : self.extendSelectionWordRight, | 212 QsciScintilla.SCI_WORDRIGHTEXTEND: self.extendSelectionWordRight, |
212 QsciScintilla.SCI_VCHOMEEXTEND : self.__QScintillaVCHomeExtend, | 213 QsciScintilla.SCI_VCHOMEEXTEND: self.__QScintillaVCHomeExtend, |
213 QsciScintilla.SCI_LINEENDEXTEND : self.extendSelectionToEOL, | 214 QsciScintilla.SCI_LINEENDEXTEND: self.extendSelectionToEOL, |
214 } | 215 } |
215 | 216 |
216 def closeShell(self): | 217 def closeShell(self): |
217 """ | 218 """ |
218 Public method to shutdown the shell. | 219 Public method to shutdown the shell. |
219 """ | 220 """ |
220 for key in list(self.historyLists.keys()): | 221 for key in list(self.historyLists.keys()): |
221 self.saveHistory(key) | 222 self.saveHistory(key) |
222 | 223 |
223 def __bindLexer(self, language = 'Python3'): | 224 def __bindLexer(self, language='Python3'): |
224 """ | 225 """ |
225 Private slot to set the lexer. | 226 Private slot to set the lexer. |
226 | 227 |
227 @param language lexer language to set (string) | 228 @param language lexer language to set (string) |
228 """ | 229 """ |
353 self.__setMargin0() | 354 self.__setMargin0() |
354 self.setFont(Preferences.getShell("MonospacedFont")) | 355 self.setFont(Preferences.getShell("MonospacedFont")) |
355 | 356 |
356 self.useMonospaced = on | 357 self.useMonospaced = on |
357 | 358 |
358 def __setAutoCompletion(self, language = 'Python'): | 359 def __setAutoCompletion(self, language='Python'): |
359 """ | 360 """ |
360 Private method to configure the autocompletion function. | 361 Private method to configure the autocompletion function. |
361 | 362 |
362 @param language of the autocompletion set to set (string) | 363 @param language of the autocompletion set to set (string) |
363 """ | 364 """ |
365 Preferences.getEditor("AutoCompletionCaseSensitivity")) | 366 Preferences.getEditor("AutoCompletionCaseSensitivity")) |
366 self.setAutoCompletionThreshold(-1) | 367 self.setAutoCompletionThreshold(-1) |
367 | 368 |
368 self.racEnabled = Preferences.getShell("AutoCompletionEnabled") | 369 self.racEnabled = Preferences.getShell("AutoCompletionEnabled") |
369 | 370 |
370 def __setCallTips(self, language = 'Python'): | 371 def __setCallTips(self, language='Python'): |
371 """ | 372 """ |
372 Private method to configure the calltips function. | 373 Private method to configure the calltips function. |
373 | 374 |
374 @param language of the calltips set to set (string) | 375 @param language of the calltips set to set (string) |
375 """ | 376 """ |
516 | 517 |
517 It requests the interpreter version and platform running on the | 518 It requests the interpreter version and platform running on the |
518 debug client side. | 519 debug client side. |
519 """ | 520 """ |
520 if self.passive: | 521 if self.passive: |
521 self.__writeBanner('','','') | 522 self.__writeBanner('', '', '') |
522 else: | 523 else: |
523 self.dbs.remoteBanner() | 524 self.dbs.remoteBanner() |
524 | 525 |
525 def __writeBanner(self, version, platform, dbgclient): | 526 def __writeBanner(self, version, platform, dbgclient): |
526 """ | 527 """ |
618 self.setFocus() | 619 self.setFocus() |
619 self.inRawMode = True | 620 self.inRawMode = True |
620 self.echoInput = echo | 621 self.echoInput = echo |
621 self.__write(s) | 622 self.__write(s) |
622 line, col = self.__getEndPos() | 623 line, col = self.__getEndPos() |
623 self.setCursorPosition(line,col) | 624 self.setCursorPosition(line, col) |
624 self.prompt = self.text(line)\ | 625 self.prompt = self.text(line)\ |
625 .replace(sys.ps1, "").replace(sys.ps2, "") | 626 .replace(sys.ps1, "").replace(sys.ps2, "") |
626 # move cursor to end of line | 627 # move cursor to end of line |
627 self.moveCursorToEOL() | 628 self.moveCursorToEOL() |
628 | 629 |
658 fullline = False | 659 fullline = False |
659 | 660 |
660 self.__insertTextAtEnd(line) | 661 self.__insertTextAtEnd(line) |
661 if fullline: | 662 if fullline: |
662 self.__executeCommand(cmd) | 663 self.__executeCommand(cmd) |
663 if self.interruptCommandExecution: | 664 if self.interruptCommandExecution: |
664 self.__executeCommand("") | 665 self.__executeCommand("") |
665 break | 666 break |
666 | 667 |
667 def __clearCurrentLine(self): | 668 def __clearCurrentLine(self): |
668 """ | 669 """ |
775 if self.isListActive(): | 776 if self.isListActive(): |
776 self.SendScintilla(cmd) | 777 self.SendScintilla(cmd) |
777 elif self.__isCursorOnLastLine(): | 778 elif self.__isCursorOnLastLine(): |
778 line, index = self.getCursorPosition() | 779 line, index = self.getCursorPosition() |
779 buf = self.text(line).replace(sys.ps1, "").replace(sys.ps2, "") | 780 buf = self.text(line).replace(sys.ps1, "").replace(sys.ps2, "") |
780 if self.inContinue and not buf[:index-len(sys.ps2)].strip(): | 781 if self.inContinue and not buf[:index - len(sys.ps2)].strip(): |
781 self.SendScintilla(cmd) | 782 self.SendScintilla(cmd) |
782 elif self.racEnabled: | 783 elif self.racEnabled: |
783 self.dbs.remoteCompletion(buf) | 784 self.dbs.remoteCompletion(buf) |
784 | 785 |
785 def __QScintillaLeftDeleteCommand(self, method): | 786 def __QScintillaLeftDeleteCommand(self, method): |
870 self.SendScintilla(cmd) | 871 self.SendScintilla(cmd) |
871 else: | 872 else: |
872 self.incrementalSearchString = "" | 873 self.incrementalSearchString = "" |
873 self.incrementalSearchActive = False | 874 self.incrementalSearchActive = False |
874 line, col = self.__getEndPos() | 875 line, col = self.__getEndPos() |
875 self.setCursorPosition(line,col) | 876 self.setCursorPosition(line, col) |
876 buf = self.text(line).replace(sys.ps1, "").replace(sys.ps2, "") | 877 buf = self.text(line).replace(sys.ps1, "").replace(sys.ps2, "") |
877 self.insert('\n') | 878 self.insert('\n') |
878 self.__executeCommand(buf) | 879 self.__executeCommand(buf) |
879 | 880 |
880 def __QScintillaLeftCommand(self, method, allLinesAllowed = False): | 881 def __QScintillaLeftCommand(self, method, allLinesAllowed=False): |
881 """ | 882 """ |
882 Private method to handle a QScintilla command working to the left. | 883 Private method to handle a QScintilla command working to the left. |
883 | 884 |
884 @param method shell method to execute | 885 @param method shell method to execute |
885 @param allLinesAllowed flag indicating that the command may be executed | 886 @param allLinesAllowed flag indicating that the command may be executed |
981 else: | 982 else: |
982 line, col = self.__getEndPos() | 983 line, col = self.__getEndPos() |
983 buf = self.text(line).replace(sys.ps1, "").replace(sys.ps2, "") | 984 buf = self.text(line).replace(sys.ps1, "").replace(sys.ps2, "") |
984 if buf and self.incrementalSearchActive: | 985 if buf and self.incrementalSearchActive: |
985 if self.incrementalSearchString: | 986 if self.incrementalSearchString: |
986 idx = self.__rsearchHistory(self.incrementalSearchString, | 987 idx = self.__rsearchHistory(self.incrementalSearchString, |
987 self.histidx) | 988 self.histidx) |
988 if idx >= 0: | 989 if idx >= 0: |
989 self.histidx = idx | 990 self.histidx = idx |
990 self.__useHistory() | 991 self.__useHistory() |
991 else: | 992 else: |
1085 self.histidx = -1 | 1086 self.histidx = -1 |
1086 if cmd.startswith('start '): | 1087 if cmd.startswith('start '): |
1087 if not self.passive: | 1088 if not self.passive: |
1088 cmdList = cmd.split(None, 1) | 1089 cmdList = cmd.split(None, 1) |
1089 if len(cmdList) < 2: | 1090 if len(cmdList) < 2: |
1090 self.dbs.startClient(False) # same as reset | 1091 self.dbs.startClient(False) # same as reset |
1091 else: | 1092 else: |
1092 language = cmdList[1] | 1093 language = cmdList[1] |
1093 if not language in self.clientLanguages: | 1094 if not language in self.clientLanguages: |
1094 language = cmdList[1].capitalize() | 1095 language = cmdList[1].capitalize() |
1095 if not language in self.clientLanguages: | 1096 if not language in self.clientLanguages: |
1154 """ | 1155 """ |
1155 Private method to insert a command selected from the history. | 1156 Private method to insert a command selected from the history. |
1156 | 1157 |
1157 @param cmd history entry to be inserted (string) | 1158 @param cmd history entry to be inserted (string) |
1158 """ | 1159 """ |
1159 self.setCursorPosition(self.prline,self.prcol) | 1160 self.setCursorPosition(self.prline, self.prcol) |
1160 self.setSelection(self.prline,self.prcol,\ | 1161 self.setSelection(self.prline, self.prcol,\ |
1161 self.prline,self.lineLength(self.prline)) | 1162 self.prline, self.lineLength(self.prline)) |
1162 self.removeSelectedText() | 1163 self.removeSelectedText() |
1163 self.__insertText(cmd) | 1164 self.__insertText(cmd) |
1164 | 1165 |
1165 def __searchHistory(self, txt, startIdx = -1): | 1166 def __searchHistory(self, txt, startIdx=-1): |
1166 """ | 1167 """ |
1167 Private method used to search the history. | 1168 Private method used to search the history. |
1168 | 1169 |
1169 @param txt text to match at the beginning (string) | 1170 @param txt text to match at the beginning (string) |
1170 @param startIdx index to start search from (integer) | 1171 @param startIdx index to start search from (integer) |
1177 while idx < len(self.history) and \ | 1178 while idx < len(self.history) and \ |
1178 not self.history[idx].startswith(txt): | 1179 not self.history[idx].startswith(txt): |
1179 idx += 1 | 1180 idx += 1 |
1180 return idx | 1181 return idx |
1181 | 1182 |
1182 def __rsearchHistory(self, txt, startIdx = -1): | 1183 def __rsearchHistory(self, txt, startIdx=-1): |
1183 """ | 1184 """ |
1184 Private method used to reverse search the history. | 1185 Private method used to reverse search the history. |
1185 | 1186 |
1186 @param txt text to match at the beginning (string) | 1187 @param txt text to match at the beginning (string) |
1187 @param startIdx index to start search from (integer) | 1188 @param startIdx index to start search from (integer) |
1207 @return flag indicating the movement | 1208 @return flag indicating the movement |
1208 """ | 1209 """ |
1209 if next and self.inContinue: | 1210 if next and self.inContinue: |
1210 return False | 1211 return False |
1211 | 1212 |
1212 return QsciScintillaCompat.focusNextPrevChild(self,next) | 1213 return QsciScintillaCompat.focusNextPrevChild(self, next) |
1213 | 1214 |
1214 def contextMenuEvent(self,ev): | 1215 def contextMenuEvent(self, ev): |
1215 """ | 1216 """ |
1216 Reimplemented to show our own context menu. | 1217 Reimplemented to show our own context menu. |
1217 | 1218 |
1218 @param ev context menu event (QContextMenuEvent) | 1219 @param ev context menu event (QContextMenuEvent) |
1219 """ | 1220 """ |
1432 l = len(txt) | 1433 l = len(txt) |
1433 line, col = self.getCursorPosition() | 1434 line, col = self.getCursorPosition() |
1434 self.insertAt(txt, line, col) | 1435 self.insertAt(txt, line, col) |
1435 if re.search(self.linesepRegExp, txt) is not None: | 1436 if re.search(self.linesepRegExp, txt) is not None: |
1436 line += 1 | 1437 line += 1 |
1437 self.setCursorPosition(line, col + l) | 1438 self.setCursorPosition(line, col + l) |
1438 | 1439 |
1439 def __configure(self): | 1440 def __configure(self): |
1440 """ | 1441 """ |
1441 Private method to open the configuration dialog. | 1442 Private method to open the configuration dialog. |
1442 """ | 1443 """ |