src/eric7/QScintilla/Shell.py

branch
eric7
changeset 10431
64157aeb0312
parent 10373
093dcebe5ecb
child 10432
2fe91fe443dd
equal deleted inserted replaced
10430:e440aaf179ce 10431:64157aeb0312
83 83
84 def showFind(self, txt=""): 84 def showFind(self, txt=""):
85 """ 85 """
86 Public method to display the search widget. 86 Public method to display the search widget.
87 87
88 @param txt text to be shown in the combo (string) 88 @param txt text to be shown in the combo
89 @type str
89 """ 90 """
90 self.__searchWidget.showFind(txt) 91 self.__searchWidget.showFind(txt)
91 92
92 def shell(self): 93 def shell(self):
93 """ 94 """
94 Public method to get a reference to the shell widget. 95 Public method to get a reference to the shell widget.
95 96
96 @return reference to the shell widget (Shell) 97 @return reference to the shell widget
98 @rtype Shell
97 """ 99 """
98 return self.__shell 100 return self.__shell
99 101
100 102
101 class ShellHistoryStyle(enum.Enum): 103 class ShellHistoryStyle(enum.Enum):
409 411
410 def __bindLexer(self, language="Python3"): 412 def __bindLexer(self, language="Python3"):
411 """ 413 """
412 Private slot to set the lexer. 414 Private slot to set the lexer.
413 415
414 @param language lexer language to set (string) 416 @param language lexer language to set
417 @type str
415 """ 418 """
416 self.language = language 419 self.language = language
417 if Preferences.getShell("SyntaxHighlightingEnabled"): 420 if Preferences.getShell("SyntaxHighlightingEnabled"):
418 self.lexer_ = Lexers.getLexer(self.language, self) 421 self.lexer_ = Lexers.getLexer(self.language, self)
419 else: 422 else:
539 542
540 def __setMonospaced(self, on): 543 def __setMonospaced(self, on):
541 """ 544 """
542 Private method to set/reset a monospaced font. 545 Private method to set/reset a monospaced font.
543 546
544 @param on flag to indicate usage of a monospace font (boolean) 547 @param on flag to indicate usage of a monospace font
548 @type bool
545 """ 549 """
546 if on: 550 if on:
547 if not self.lexer_: 551 if not self.lexer_:
548 f = Preferences.getShell("MonospacedFont") 552 f = Preferences.getShell("MonospacedFont")
549 self.monospacedStyles(f) 553 self.monospacedStyles(f)
603 607
604 def setDebuggerUI(self, ui): 608 def setDebuggerUI(self, ui):
605 """ 609 """
606 Public method to set the debugger UI. 610 Public method to set the debugger UI.
607 611
608 @param ui reference to the debugger UI object (DebugUI) 612 @param ui reference to the debugger UI object
613 @type DebugUI
609 """ 614 """
610 ui.exceptionInterrupt.connect(self.__writePrompt) 615 ui.exceptionInterrupt.connect(self.__writePrompt)
611 self.registerDebuggerIdMethod(ui.getSelectedDebuggerId) 616 self.registerDebuggerIdMethod(ui.getSelectedDebuggerId)
612 617
613 def registerDebuggerIdMethod(self, method): 618 def registerDebuggerIdMethod(self, method):
723 728
724 def loadHistory(self, clientType): 729 def loadHistory(self, clientType):
725 """ 730 """
726 Public method to load the history for the given client type. 731 Public method to load the history for the given client type.
727 732
728 @param clientType type of the debug client (string) 733 @param clientType type of the debug client
734 @type str
729 """ 735 """
730 hl = Preferences.getSettings().value("Shell/Histories/" + clientType) 736 hl = Preferences.getSettings().value("Shell/Histories/" + clientType)
731 if hl is not None: 737 if hl is not None:
732 self.__historyLists[clientType] = hl[-self.__maxHistoryEntries :] 738 self.__historyLists[clientType] = hl[-self.__maxHistoryEntries :]
733 else: 739 else:
744 750
745 def saveHistory(self, clientType): 751 def saveHistory(self, clientType):
746 """ 752 """
747 Public method to save the history for the given client type. 753 Public method to save the history for the given client type.
748 754
749 @param clientType type of the debug client (string) 755 @param clientType type of the debug client
756 @type str
750 """ 757 """
751 if clientType in self.__historyLists: 758 if clientType in self.__historyLists:
752 Preferences.getSettings().setValue( 759 Preferences.getSettings().setValue(
753 "Shell/Histories/" + clientType, self.__historyLists[clientType] 760 "Shell/Histories/" + clientType, self.__historyLists[clientType]
754 ) 761 )
755 762
756 def getHistory(self, clientType): 763 def getHistory(self, clientType):
757 """ 764 """
758 Public method to get the history for the given client type. 765 Public method to get the history for the given client type.
759 766
760 @param clientType type of the debug client (string). 767 @param clientType type of the debug client. If it is None, the current
761 If it is None, the current history is returned. 768 history is returned.
762 @return reference to the history list (list of strings) 769 @type str
770 @return reference to the history list
771 @rtype list of str
763 """ 772 """
764 if clientType is None: 773 if clientType is None:
765 return self.__history 774 return self.__history
766 elif clientType in self.__historyLists: 775 elif clientType in self.__historyLists:
767 return self.__historyLists[clientType] 776 return self.__historyLists[clientType]
846 855
847 def getClientType(self): 856 def getClientType(self):
848 """ 857 """
849 Public slot to get the clients type. 858 Public slot to get the clients type.
850 859
851 @return client type (string) 860 @return client type
861 @rtype str
852 """ 862 """
853 return self.clientType 863 return self.clientType
854 864
855 def __getBanner(self): 865 def __getBanner(self):
856 """ 866 """
915 925
916 def __clientException(self, exceptionType, exceptionMessage, stackTrace): 926 def __clientException(self, exceptionType, exceptionMessage, stackTrace):
917 """ 927 """
918 Private method to handle an exception of the client. 928 Private method to handle an exception of the client.
919 929
920 @param exceptionType type of exception raised (string) 930 @param exceptionType type of exception raised
921 @param exceptionMessage message given by the exception (string) 931 @type str
922 @param stackTrace list of stack entries (list of string) 932 @param exceptionMessage message given by the exception
933 @type str
934 @param stackTrace list of stack entries
935 @type list of str
923 """ 936 """
924 self.__clientError() 937 self.__clientError()
925 938
926 if ( 939 if (
927 not self.__windowed 940 not self.__windowed
946 959
947 def __clientSyntaxError(self, message, filename, lineNo, characterNo): 960 def __clientSyntaxError(self, message, filename, lineNo, characterNo):
948 """ 961 """
949 Private method to handle a syntax error in the debugged program. 962 Private method to handle a syntax error in the debugged program.
950 963
951 @param message message of the syntax error (string) 964 @param message message of the syntax error
965 @type str
952 @param filename translated filename of the syntax error position 966 @param filename translated filename of the syntax error position
953 (string) 967 @type str
954 @param lineNo line number of the syntax error position (integer) 968 @param lineNo line number of the syntax error position
969 @type int
955 @param characterNo character number of the syntax error position 970 @param characterNo character number of the syntax error position
956 (integer) 971 @type int
957 """ 972 """
958 self.__clientError() 973 self.__clientError()
959 974
960 if not self.__windowed and Preferences.getDebugger("ShowExceptionInShell"): 975 if not self.__windowed and Preferences.getDebugger("ShowExceptionInShell"):
961 if message is None: 976 if message is None:
1002 1017
1003 def __getEndPos(self): 1018 def __getEndPos(self):
1004 """ 1019 """
1005 Private method to return the line and column of the last character. 1020 Private method to return the line and column of the last character.
1006 1021
1007 @return tuple of two values (int, int) giving the line and column 1022 @return tuple of two values giving the line and column
1023 @rtype tuple of (int, int)
1008 """ 1024 """
1009 line = self.lines() - 1 1025 line = self.lines() - 1
1010 return (line, len(self.text(line))) 1026 return (line, len(self.text(line)))
1011 1027
1012 def __writeQueued(self, s): 1028 def __writeQueued(self, s):
1013 """ 1029 """
1014 Private method to display some text using a write queue. 1030 Private method to display some text using a write queue.
1015 1031
1016 @param s text to be displayed (string) 1032 @param s text to be displayed
1033 @type str
1017 """ 1034 """
1018 self.queueText.emit(s) 1035 self.queueText.emit(s)
1019 1036
1020 def __concatenateText(self, text): 1037 def __concatenateText(self, text):
1021 """ 1038 """
1064 1081
1065 def __writeStdOut(self, s): 1082 def __writeStdOut(self, s):
1066 """ 1083 """
1067 Private method to display some text with StdOut label. 1084 Private method to display some text with StdOut label.
1068 1085
1069 @param s text to be displayed (string) 1086 @param s text to be displayed
1087 @type str
1070 """ 1088 """
1071 self.__write(self.tr("StdOut: {0}").format(s)) 1089 self.__write(self.tr("StdOut: {0}").format(s))
1072 1090
1073 def __writeStdErr(self, s): 1091 def __writeStdErr(self, s):
1074 """ 1092 """
1075 Private method to display some text with StdErr label. 1093 Private method to display some text with StdErr label.
1076 1094
1077 @param s text to be displayed (string) 1095 @param s text to be displayed
1096 @type str
1078 """ 1097 """
1079 self.__write(self.tr("StdErr: {0}").format(s)) 1098 self.__write(self.tr("StdErr: {0}").format(s))
1080 1099
1081 def __raw_input(self, prompt, echo, debuggerId): 1100 def __raw_input(self, prompt, echo, debuggerId):
1082 """ 1101 """
1234 1253
1235 def __insertText(self, s): 1254 def __insertText(self, s):
1236 """ 1255 """
1237 Private method to insert some text at the current cursor position. 1256 Private method to insert some text at the current cursor position.
1238 1257
1239 @param s text to be inserted (string) 1258 @param s text to be inserted
1259 @type str
1240 """ 1260 """
1241 line, col = self.getCursorPosition() 1261 line, col = self.getCursorPosition()
1242 self.insertAt(Utilities.filterAnsiSequences(s), line, col) 1262 self.insertAt(Utilities.filterAnsiSequences(s), line, col)
1243 self.setCursorPosition(line, col + len(s)) 1263 self.setCursorPosition(line, col + len(s))
1244 1264
1245 def __insertTextAtEnd(self, s): 1265 def __insertTextAtEnd(self, s):
1246 """ 1266 """
1247 Private method to insert some text at the end of the command line. 1267 Private method to insert some text at the end of the command line.
1248 1268
1249 @param s text to be inserted (string) 1269 @param s text to be inserted
1270 @type str
1250 """ 1271 """
1251 line, col = self.__getEndPos() 1272 line, col = self.__getEndPos()
1252 self.setCursorPosition(line, col) 1273 self.setCursorPosition(line, col)
1253 self.insert(Utilities.filterAnsiSequences(s)) 1274 self.insert(Utilities.filterAnsiSequences(s))
1254 self.prline, _ = self.getCursorPosition() 1275 self.prline, _ = self.getCursorPosition()
1256 def __insertTextNoEcho(self, s): 1277 def __insertTextNoEcho(self, s):
1257 """ 1278 """
1258 Private method to insert some text at the end of the buffer without 1279 Private method to insert some text at the end of the buffer without
1259 echoing it. 1280 echoing it.
1260 1281
1261 @param s text to be inserted (string) 1282 @param s text to be inserted
1283 @type str
1262 """ 1284 """
1263 self.buff += s 1285 self.buff += s
1264 self.prline, self.prcol = self.getCursorPosition() 1286 self.prline, self.prcol = self.getCursorPosition()
1265 1287
1266 def mousePressEvent(self, event): 1288 def mousePressEvent(self, event):
1267 """ 1289 """
1268 Protected method to handle the mouse press event. 1290 Protected method to handle the mouse press event.
1269 1291
1270 @param event the mouse press event (QMouseEvent) 1292 @param event the mouse press event
1293 @type QMouseEvent
1271 """ 1294 """
1272 self.setFocus(Qt.FocusReason.MouseFocusReason) 1295 self.setFocus(Qt.FocusReason.MouseFocusReason)
1273 if event.button() == Qt.MouseButton.MiddleButton: 1296 if event.button() == Qt.MouseButton.MiddleButton:
1274 lines = QApplication.clipboard().text(QClipboard.Mode.Selection) 1297 lines = QApplication.clipboard().text(QClipboard.Mode.Selection)
1275 self.paste(lines) 1298 self.paste(lines)
1278 1301
1279 def wheelEvent(self, evt): 1302 def wheelEvent(self, evt):
1280 """ 1303 """
1281 Protected method to handle wheel events. 1304 Protected method to handle wheel events.
1282 1305
1283 @param evt reference to the wheel event (QWheelEvent) 1306 @param evt reference to the wheel event
1307 @type QWheelEvent
1284 """ 1308 """
1285 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier: 1309 if evt.modifiers() & Qt.KeyboardModifier.ControlModifier:
1286 delta = evt.angleDelta().y() 1310 delta = evt.angleDelta().y()
1287 if delta < 0: 1311 if delta < 0:
1288 self.zoomOut() 1312 self.zoomOut()
1295 1319
1296 def event(self, evt): 1320 def event(self, evt):
1297 """ 1321 """
1298 Public method handling events. 1322 Public method handling events.
1299 1323
1300 @param evt reference to the event (QEvent) 1324 @param evt reference to the event
1301 @return flag indicating, if the event was handled (boolean) 1325 @type QEvent
1326 @return flag indicating, if the event was handled
1327 @rtype bool
1302 """ 1328 """
1303 if evt.type() == QEvent.Type.Gesture: 1329 if evt.type() == QEvent.Type.Gesture:
1304 self.gestureEvent(evt) 1330 self.gestureEvent(evt)
1305 return True 1331 return True
1306 1332
1309 def gestureEvent(self, evt): 1335 def gestureEvent(self, evt):
1310 """ 1336 """
1311 Protected method handling gesture events. 1337 Protected method handling gesture events.
1312 1338
1313 @param evt reference to the gesture event (QGestureEvent 1339 @param evt reference to the gesture event (QGestureEvent
1340 @type int
1314 """ 1341 """
1315 pinch = evt.gesture(Qt.GestureType.PinchGesture) 1342 pinch = evt.gesture(Qt.GestureType.PinchGesture)
1316 if pinch: 1343 if pinch:
1317 if pinch.state() == Qt.GestureState.GestureStarted: 1344 if pinch.state() == Qt.GestureState.GestureStarted:
1318 zoom = (self.getZoom() + 10) / 10.0 1345 zoom = (self.getZoom() + 10) / 10.0
1331 def editorCommand(self, cmd): 1358 def editorCommand(self, cmd):
1332 """ 1359 """
1333 Public method to perform an editor command. 1360 Public method to perform an editor command.
1334 1361
1335 @param cmd the scintilla command to be performed 1362 @param cmd the scintilla command to be performed
1363 @type int
1336 """ 1364 """
1337 try: 1365 try:
1338 self.supportedEditorCommands[cmd]() 1366 self.supportedEditorCommands[cmd]()
1339 except TypeError: 1367 except TypeError:
1340 self.supportedEditorCommands[cmd](cmd) 1368 self.supportedEditorCommands[cmd](cmd)
1343 1371
1344 def __isCursorOnLastLine(self): 1372 def __isCursorOnLastLine(self):
1345 """ 1373 """
1346 Private method to check, if the cursor is on the last line. 1374 Private method to check, if the cursor is on the last line.
1347 1375
1348 @return flag indicating that the cursor is on the last line (boolean) 1376 @return flag indicating that the cursor is on the last line
1377 @rtype bool
1349 """ 1378 """
1350 cline, ccol = self.getCursorPosition() 1379 cline, ccol = self.getCursorPosition()
1351 return cline == self.lines() - 1 1380 return cline == self.lines() - 1
1352 1381
1353 def keyPressEvent(self, ev): 1382 def keyPressEvent(self, ev):
1354 """ 1383 """
1355 Protected method to handle the user input a key at a time. 1384 Protected method to handle the user input a key at a time.
1356 1385
1357 @param ev key event (QKeyEvent) 1386 @param ev key event (QKeyEvent)
1387 @type int
1358 """ 1388 """
1359 txt = ev.text() 1389 txt = ev.text()
1360 1390
1361 # See it is text to insert. 1391 # See it is text to insert.
1362 if len(txt) and txt >= " ": 1392 if len(txt) and txt >= " ":
1380 def __QScintillaCommand(self, cmd): 1410 def __QScintillaCommand(self, cmd):
1381 """ 1411 """
1382 Private method to send the command to QScintilla. 1412 Private method to send the command to QScintilla.
1383 1413
1384 @param cmd QScintilla command 1414 @param cmd QScintilla command
1415 @type int
1385 """ 1416 """
1386 self.SendScintilla(cmd) 1417 self.SendScintilla(cmd)
1387 1418
1388 def __QScintillaTab(self, cmd): 1419 def __QScintillaTab(self, cmd):
1389 """ 1420 """
1390 Private method to handle the Tab key. 1421 Private method to handle the Tab key.
1391 1422
1392 @param cmd QScintilla command 1423 @param cmd QScintilla command
1424 @type int
1393 """ 1425 """
1394 if self.isListActive(): 1426 if self.isListActive():
1395 self.SendScintilla(cmd) 1427 self.SendScintilla(cmd)
1396 elif self.__isCursorOnLastLine(): 1428 elif self.__isCursorOnLastLine():
1397 line, index = self.getCursorPosition() 1429 line, index = self.getCursorPosition()
1409 """ 1441 """
1410 Private method to handle a QScintilla delete command working to 1442 Private method to handle a QScintilla delete command working to
1411 the left. 1443 the left.
1412 1444
1413 @param method shell method to execute 1445 @param method shell method to execute
1446 @type int
1414 """ 1447 """
1415 if self.__isCursorOnLastLine(): 1448 if self.__isCursorOnLastLine():
1416 line, col = self.getCursorPosition() 1449 line, col = self.getCursorPosition()
1417 db = 0 1450 db = 0
1418 ac = self.isListActive() 1451 ac = self.isListActive()
1488 def __QScintillaNewline(self, cmd): 1521 def __QScintillaNewline(self, cmd):
1489 """ 1522 """
1490 Private method to handle the Return key. 1523 Private method to handle the Return key.
1491 1524
1492 @param cmd QScintilla command 1525 @param cmd QScintilla command
1526 @type int
1493 """ 1527 """
1494 if self.__isCursorOnLastLine(): 1528 if self.__isCursorOnLastLine():
1495 if self.isListActive(): 1529 if self.isListActive():
1496 self.SendScintilla(cmd) 1530 self.SendScintilla(cmd)
1497 else: 1531 else:
1526 def __QScintillaLeftCommand(self, method, allLinesAllowed=False): 1560 def __QScintillaLeftCommand(self, method, allLinesAllowed=False):
1527 """ 1561 """
1528 Private method to handle a QScintilla command working to the left. 1562 Private method to handle a QScintilla command working to the left.
1529 1563
1530 @param method shell method to execute 1564 @param method shell method to execute
1565 @type int
1531 @param allLinesAllowed flag indicating that the command may be executed 1566 @param allLinesAllowed flag indicating that the command may be executed
1532 on any line (boolean) 1567 on any line
1568 @type bool
1533 """ 1569 """
1534 if self.__isCursorOnLastLine() or allLinesAllowed: 1570 if self.__isCursorOnLastLine() or allLinesAllowed:
1535 line, col = self.getCursorPosition() 1571 line, col = self.getCursorPosition()
1536 if self.text(line).startswith(sys.ps1): 1572 if self.text(line).startswith(sys.ps1):
1537 if col > len(sys.ps1): 1573 if col > len(sys.ps1):
1559 def __QScintillaRightCommand(self, method): 1595 def __QScintillaRightCommand(self, method):
1560 """ 1596 """
1561 Private method to handle a QScintilla command working to the right. 1597 Private method to handle a QScintilla command working to the right.
1562 1598
1563 @param method shell method to execute 1599 @param method shell method to execute
1564 """ 1600 @type function
1601 """
1602 # TODO: check this!
1565 if self.__isCursorOnLastLine(): 1603 if self.__isCursorOnLastLine():
1566 method() 1604 method()
1567 else: 1605 else:
1568 method() 1606 method()
1569 1607
1594 def __QScintillaVCHome(self, cmd): 1632 def __QScintillaVCHome(self, cmd):
1595 """ 1633 """
1596 Private method to handle the Home key. 1634 Private method to handle the Home key.
1597 1635
1598 @param cmd QScintilla command 1636 @param cmd QScintilla command
1637 @type int
1599 """ 1638 """
1600 if self.isListActive(): 1639 if self.isListActive():
1601 self.SendScintilla(cmd) 1640 self.SendScintilla(cmd)
1602 elif self.__isCursorOnLastLine(): 1641 elif self.__isCursorOnLastLine():
1603 line, col = self.getCursorPosition() 1642 line, col = self.getCursorPosition()
1612 def __QScintillaLineEnd(self, cmd): 1651 def __QScintillaLineEnd(self, cmd):
1613 """ 1652 """
1614 Private method to handle the End key. 1653 Private method to handle the End key.
1615 1654
1616 @param cmd QScintilla command 1655 @param cmd QScintilla command
1656 @type int
1617 """ 1657 """
1618 if self.isListActive(): 1658 if self.isListActive():
1619 self.SendScintilla(cmd) 1659 self.SendScintilla(cmd)
1620 elif self.__isCursorOnLastLine(): 1660 elif self.__isCursorOnLastLine():
1621 self.moveCursorToEOL() 1661 self.moveCursorToEOL()
1623 def __QScintillaCursorCommand(self, cmd): 1663 def __QScintillaCursorCommand(self, cmd):
1624 """ 1664 """
1625 Private method to handle the cursor commands. 1665 Private method to handle the cursor commands.
1626 1666
1627 @param cmd QScintilla command 1667 @param cmd QScintilla command
1668 @type int
1628 """ 1669 """
1629 if self.isListActive() or self.isCallTipActive(): 1670 if self.isListActive() or self.isCallTipActive():
1630 if cmd in (QsciScintilla.SCI_LINEUP, QsciScintilla.SCI_LINEDOWN): 1671 if cmd in (QsciScintilla.SCI_LINEUP, QsciScintilla.SCI_LINEDOWN):
1631 self.SendScintilla(cmd) 1672 self.SendScintilla(cmd)
1632 else: 1673 else:
1652 def __QScintillaLineUp(self, cmd): # noqa: U100 1693 def __QScintillaLineUp(self, cmd): # noqa: U100
1653 """ 1694 """
1654 Private method to handle the cursor up command. 1695 Private method to handle the cursor up command.
1655 1696
1656 @param cmd QScintilla command 1697 @param cmd QScintilla command
1698 @type int
1657 """ 1699 """
1658 self.SendScintilla(QsciScintilla.SCI_LINEUP) 1700 self.SendScintilla(QsciScintilla.SCI_LINEUP)
1659 1701
1660 def __QScintillaLineDown(self, cmd): # noqa: U100 1702 def __QScintillaLineDown(self, cmd): # noqa: U100
1661 """ 1703 """
1662 Private method to handle the cursor down command. 1704 Private method to handle the cursor down command.
1663 1705
1664 @param cmd QScintilla command 1706 @param cmd QScintilla command
1707 @type int
1665 """ 1708 """
1666 self.SendScintilla(QsciScintilla.SCI_LINEDOWN) 1709 self.SendScintilla(QsciScintilla.SCI_LINEDOWN)
1667 1710
1668 def __QScintillaHistoryUp(self, cmd): # noqa: U100 1711 def __QScintillaHistoryUp(self, cmd): # noqa: U100
1669 """ 1712 """
1670 Private method to handle the history up command. 1713 Private method to handle the history up command.
1671 1714
1672 @param cmd QScintilla command 1715 @param cmd QScintilla command
1716 @type int
1673 """ 1717 """
1674 if self.isHistoryEnabled(): 1718 if self.isHistoryEnabled():
1675 line, col = self.__getEndPos() 1719 line, col = self.__getEndPos()
1676 buf = self.text(line) 1720 buf = self.text(line)
1677 if buf.startswith(sys.ps1): 1721 if buf.startswith(sys.ps1):
1713 def __QScintillaHistoryDown(self, cmd): # noqa: U100 1757 def __QScintillaHistoryDown(self, cmd): # noqa: U100
1714 """ 1758 """
1715 Private method to handle the history down command. 1759 Private method to handle the history down command.
1716 1760
1717 @param cmd QScintilla command 1761 @param cmd QScintilla command
1762 @type int
1718 """ 1763 """
1719 if self.isHistoryEnabled(): 1764 if self.isHistoryEnabled():
1720 line, col = self.__getEndPos() 1765 line, col = self.__getEndPos()
1721 buf = self.text(line) 1766 buf = self.text(line)
1722 if buf.startswith(sys.ps1): 1767 if buf.startswith(sys.ps1):
1795 def __QScintillaAutoCompletionCommand(self, cmd): 1840 def __QScintillaAutoCompletionCommand(self, cmd):
1796 """ 1841 """
1797 Private method to handle a command for autocompletion only. 1842 Private method to handle a command for autocompletion only.
1798 1843
1799 @param cmd QScintilla command 1844 @param cmd QScintilla command
1845 @type int
1800 """ 1846 """
1801 if self.isListActive() or self.isCallTipActive(): 1847 if self.isListActive() or self.isCallTipActive():
1802 self.SendScintilla(cmd) 1848 self.SendScintilla(cmd)
1803 1849
1804 def __executeCommand(self, cmd, historyIndex=None): 1850 def __executeCommand(self, cmd, historyIndex=None):
1974 2020
1975 def __insertHistory(self, cmd): 2021 def __insertHistory(self, cmd):
1976 """ 2022 """
1977 Private method to insert a command selected from the history. 2023 Private method to insert a command selected from the history.
1978 2024
1979 @param cmd history entry to be inserted (string) 2025 @param cmd history entry to be inserted
2026 @type str
1980 """ 2027 """
1981 self.setCursorPosition(self.prline, self.prcol) 2028 self.setCursorPosition(self.prline, self.prcol)
1982 self.setSelection( 2029 self.setSelection(
1983 self.prline, self.prcol, self.prline, self.lineLength(self.prline) 2030 self.prline, self.prcol, self.prline, self.lineLength(self.prline)
1984 ) 2031 )
2034 2081
2035 While the user is entering a multi-line command, the movement to 2082 While the user is entering a multi-line command, the movement to
2036 the next window by the Tab key being pressed is suppressed. 2083 the next window by the Tab key being pressed is suppressed.
2037 2084
2038 @param nextChild next window 2085 @param nextChild next window
2086 @type QWidget
2039 @return flag indicating the movement 2087 @return flag indicating the movement
2088 @rtype bool
2040 """ 2089 """
2041 if nextChild and self.inContinue: 2090 if nextChild and self.inContinue:
2042 return False 2091 return False
2043 2092
2044 return QsciScintillaCompat.focusNextPrevChild(self, nextChild) 2093 return QsciScintillaCompat.focusNextPrevChild(self, nextChild)
2081 def __startDebugClient(self, action): 2130 def __startDebugClient(self, action):
2082 """ 2131 """
2083 Private slot to start a debug client according to the action 2132 Private slot to start a debug client according to the action
2084 triggered. 2133 triggered.
2085 2134
2086 @param action context menu action that was triggered (QAction) 2135 @param action context menu action that was triggered
2136 @type QAction
2087 """ 2137 """
2088 venvName = action.text() 2138 venvName = action.text()
2089 if venvName == self.tr("Project"): 2139 if venvName == self.tr("Project"):
2090 if self.__project.isOpen(): 2140 if self.__project.isOpen():
2091 self.__currentWorkingDirectory = self.__project.getProjectPath() 2141 self.__currentWorkingDirectory = self.__project.getProjectPath()
2140 @pyqtSlot(list, str) 2190 @pyqtSlot(list, str)
2141 def __showCompletions(self, completions, text): 2191 def __showCompletions(self, completions, text):
2142 """ 2192 """
2143 Private method to display the possible completions. 2193 Private method to display the possible completions.
2144 2194
2145 @param completions list of possible completions (list of strings) 2195 @param completions list of possible completions
2146 @param text text that is about to be completed (string) 2196 @type list of str
2197 @param text text that is about to be completed
2198 @type str
2147 """ 2199 """
2148 if len(completions) == 0: 2200 if len(completions) == 0:
2149 return 2201 return
2150 2202
2151 if len(completions) > 1: 2203 if len(completions) > 1:
2161 2213
2162 def __completionListSelected(self, listId, txt): 2214 def __completionListSelected(self, listId, txt):
2163 """ 2215 """
2164 Private slot to handle the selection from the completion list. 2216 Private slot to handle the selection from the completion list.
2165 2217
2166 @param listId the ID of the user list (should be 1) (integer) 2218 @param listId the ID of the user list (should be 1)
2167 @param txt the selected text (string) 2219 @type int
2220 @param txt the selected text
2221 @type str
2168 """ 2222 """
2169 if listId == 1: 2223 if listId == 1:
2170 if self.completionText != "": 2224 if self.completionText != "":
2171 txt = txt.replace(self.completionText, "") 2225 txt = txt.replace(self.completionText, "")
2172 self.__insertText(txt) 2226 self.__insertText(txt)
2178 2232
2179 def dragEnterEvent(self, event): 2233 def dragEnterEvent(self, event):
2180 """ 2234 """
2181 Protected method to handle the drag enter event. 2235 Protected method to handle the drag enter event.
2182 2236
2183 @param event the drag enter event (QDragEnterEvent) 2237 @param event the drag enter event
2238 @type QDragEnterEvent
2184 """ 2239 """
2185 self.inDragDrop = event.mimeData().hasUrls() or event.mimeData().hasText() 2240 self.inDragDrop = event.mimeData().hasUrls() or event.mimeData().hasText()
2186 if self.inDragDrop: 2241 if self.inDragDrop:
2187 event.acceptProposedAction() 2242 event.acceptProposedAction()
2188 else: 2243 else:
2190 2245
2191 def dragMoveEvent(self, event): 2246 def dragMoveEvent(self, event):
2192 """ 2247 """
2193 Protected method to handle the drag move event. 2248 Protected method to handle the drag move event.
2194 2249
2195 @param event the drag move event (QDragMoveEvent) 2250 @param event the drag move event
2251 @type QDragMoveEvent
2196 """ 2252 """
2197 if self.inDragDrop: 2253 if self.inDragDrop:
2198 event.accept() 2254 event.accept()
2199 else: 2255 else:
2200 super().dragMoveEvent(event) 2256 super().dragMoveEvent(event)
2201 2257
2202 def dragLeaveEvent(self, event): 2258 def dragLeaveEvent(self, event):
2203 """ 2259 """
2204 Protected method to handle the drag leave event. 2260 Protected method to handle the drag leave event.
2205 2261
2206 @param event the drag leave event (QDragLeaveEvent) 2262 @param event the drag leave event
2263 @type QDragLeaveEvent
2207 """ 2264 """
2208 if self.inDragDrop: 2265 if self.inDragDrop:
2209 self.inDragDrop = False 2266 self.inDragDrop = False
2210 event.accept() 2267 event.accept()
2211 else: 2268 else:
2213 2270
2214 def dropEvent(self, event): 2271 def dropEvent(self, event):
2215 """ 2272 """
2216 Protected method to handle the drop event. 2273 Protected method to handle the drop event.
2217 2274
2218 @param event the drop event (QDropEvent) 2275 @param event the drop event
2276 @type QDropEvent
2219 """ 2277 """
2220 if event.mimeData().hasUrls() and not self.__windowed: 2278 if event.mimeData().hasUrls() and not self.__windowed:
2221 for url in event.mimeData().urls(): 2279 for url in event.mimeData().urls():
2222 fname = url.toLocalFile() 2280 fname = url.toLocalFile()
2223 if fname: 2281 if fname:
2245 2303
2246 def focusInEvent(self, event): 2304 def focusInEvent(self, event):
2247 """ 2305 """
2248 Protected method called when the shell receives focus. 2306 Protected method called when the shell receives focus.
2249 2307
2250 @param event the event object (QFocusEvent) 2308 @param event the event object
2309 @type QFocusEvent
2251 """ 2310 """
2252 if not self.__actionsAdded: 2311 if not self.__actionsAdded:
2253 self.addActions(self.vm.editorActGrp.actions()) 2312 self.addActions(self.vm.editorActGrp.actions())
2254 self.addActions(self.vm.copyActGrp.actions()) 2313 self.addActions(self.vm.copyActGrp.actions())
2255 self.addActions(self.vm.viewActGrp.actions()) 2314 self.addActions(self.vm.viewActGrp.actions())
2287 2346
2288 def focusOutEvent(self, event): 2347 def focusOutEvent(self, event):
2289 """ 2348 """
2290 Protected method called when the shell loses focus. 2349 Protected method called when the shell loses focus.
2291 2350
2292 @param event the event object (QFocusEvent) 2351 @param event the event object
2352 @type QFocusEvent
2293 """ 2353 """
2294 with contextlib.suppress(AttributeError): 2354 with contextlib.suppress(AttributeError):
2295 self.vm.editorActGrp.setEnabled(False) 2355 self.vm.editorActGrp.setEnabled(False)
2296 if not self.__windowed: 2356 if not self.__windowed:
2297 self.__searchShortcut.setEnabled(False) 2357 self.__searchShortcut.setEnabled(False)
2304 """ 2364 """
2305 Public slot to insert text at the current cursor position. 2365 Public slot to insert text at the current cursor position.
2306 2366
2307 The cursor is advanced to the end of the inserted text. 2367 The cursor is advanced to the end of the inserted text.
2308 2368
2309 @param txt text to be inserted (string) 2369 @param txt text to be inserted
2370 @type str
2310 """ 2371 """
2311 txt = Utilities.filterAnsiSequences(txt) 2372 txt = Utilities.filterAnsiSequences(txt)
2312 length = len(txt) 2373 length = len(txt)
2313 line, col = self.getCursorPosition() 2374 line, col = self.getCursorPosition()
2314 self.insertAt(txt, line, col) 2375 self.insertAt(txt, line, col)

eric ide

mercurial