1073 buf = buf.replace(sys.ps2, "") |
1073 buf = buf.replace(sys.ps2, "") |
1074 self.prompt = buf |
1074 self.prompt = buf |
1075 # move cursor to end of line |
1075 # move cursor to end of line |
1076 self.moveCursorToEOL() |
1076 self.moveCursorToEOL() |
1077 |
1077 |
1078 def paste(self): |
1078 def paste(self, lines=None): |
1079 """ |
1079 """ |
1080 Public slot to handle the paste action. |
1080 Public slot to handle the paste action. |
|
1081 |
|
1082 @param lines list of lines to be inserted |
|
1083 @type list of str |
1081 """ |
1084 """ |
1082 if self.__isCursorOnLastLine(): |
1085 if self.__isCursorOnLastLine(): |
1083 line, col = self.getCursorPosition() |
1086 line, col = self.getCursorPosition() |
1084 lastLine = self.text(line) |
1087 lastLine = self.text(line) |
1085 if lastLine.startswith(sys.ps1): |
1088 if lastLine.startswith(sys.ps1): |
1111 col = indexFrom |
1114 col = indexFrom |
1112 |
1115 |
1113 self.setCursorPosition(line, len(prompt)) |
1116 self.setCursorPosition(line, len(prompt)) |
1114 self.deleteLineRight() |
1117 self.deleteLineRight() |
1115 |
1118 |
1116 lines = QApplication.clipboard().text() |
1119 if lines is None: |
|
1120 lines = QApplication.clipboard().text() |
|
1121 |
1117 lines = lastLine[:col] + lines + lastLine[col:] |
1122 lines = lastLine[:col] + lines + lastLine[col:] |
1118 self.executeLines(lines) |
1123 self.executeLines(lines) |
1119 line, _ = self.getCursorPosition() |
1124 line, _ = self.getCursorPosition() |
1120 pos = len(self.text(line)) - (len(lastLine) - col) |
1125 pos = len(self.text(line)) - (len(lastLine) - col) |
1121 self.setCursorPosition(line, pos) |
1126 self.setCursorPosition(line, pos) |
1122 |
1127 |
1123 def __middleMouseButton(self): |
|
1124 """ |
|
1125 Private method to handle the middle mouse button press. |
|
1126 """ |
|
1127 lines = QApplication.clipboard().text(QClipboard.Selection) |
|
1128 self.executeLines(lines) |
|
1129 |
|
1130 def executeLines(self, lines, historyIndex=None): |
1128 def executeLines(self, lines, historyIndex=None): |
1131 """ |
1129 """ |
1132 Public method to execute a set of lines as multiple commands. |
1130 Public method to execute a set of lines as multiple commands. |
1133 |
1131 |
1134 @param lines multiple lines of text to be executed as |
1132 @param lines multiple lines of text to be executed as |
1148 elif line.startswith(sys.ps2): |
1146 elif line.startswith(sys.ps2): |
1149 line = line[len(sys.ps2) + indentLen:] |
1147 line = line[len(sys.ps2) + indentLen:] |
1150 else: |
1148 else: |
1151 line = line[indentLen:] |
1149 line = line[indentLen:] |
1152 |
1150 |
1153 if line.endswith("\r\n"): |
1151 if line.endswith(("\r\n", "\r", "\n")): |
1154 fullline = True |
1152 fullline = True |
1155 cmd = line[:-2] |
1153 cmd = line.rstrip() |
1156 elif line.endswith("\r") or line.endswith("\n"): |
|
1157 fullline = True |
|
1158 cmd = line[:-1] |
|
1159 else: |
1154 else: |
1160 fullline = False |
1155 fullline = False |
1161 |
1156 |
1162 self.incrementalSearchActive = True |
1157 self.incrementalSearchActive = True |
1163 self.__insertTextAtEnd(line) |
1158 self.__insertTextAtEnd(line) |
1235 |
1230 |
1236 @param event the mouse press event (QMouseEvent) |
1231 @param event the mouse press event (QMouseEvent) |
1237 """ |
1232 """ |
1238 self.setFocus() |
1233 self.setFocus() |
1239 if event.button() == Qt.MidButton: |
1234 if event.button() == Qt.MidButton: |
1240 self.__middleMouseButton() |
1235 lines = QApplication.clipboard().text(QClipboard.Selection) |
|
1236 self.paste(lines) |
1241 else: |
1237 else: |
1242 super(Shell, self).mousePressEvent(event) |
1238 super(Shell, self).mousePressEvent(event) |
1243 |
1239 |
1244 def wheelEvent(self, evt): |
1240 def wheelEvent(self, evt): |
1245 """ |
1241 """ |