##// END OF EJS Templates
First pass at unicode support in ConsoleWidget....
epatters -
Show More
@@ -254,15 +254,8 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
254 254 def can_paste(self):
255 255 """ Returns whether text can be pasted from the clipboard.
256 256 """
257 # Only accept text that can be ASCII encoded.
258 257 if self._control.textInteractionFlags() & QtCore.Qt.TextEditable:
259 text = QtGui.QApplication.clipboard().text()
260 if not text.isEmpty():
261 try:
262 str(text)
263 return True
264 except UnicodeEncodeError:
265 pass
258 return not QtGui.QApplication.clipboard().text().isEmpty()
266 259 return False
267 260
268 261 def clear(self, keep_input=True):
@@ -390,7 +383,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
390 383
391 384 cursor = self._get_end_cursor()
392 385 cursor.setPosition(self._prompt_pos, QtGui.QTextCursor.KeepAnchor)
393 input_buffer = str(cursor.selection().toPlainText())
386 input_buffer = unicode(cursor.selection().toPlainText())
394 387
395 388 # Strip out continuation prompts.
396 389 return input_buffer.replace('\n' + self._continuation_prompt, '\n')
@@ -453,14 +446,10 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
453 446 in Mac OS. By default, the regular clipboard is used.
454 447 """
455 448 if self._control.textInteractionFlags() & QtCore.Qt.TextEditable:
456 try:
457 # Remove any trailing newline, which confuses the GUI and
458 # forces the user to backspace.
459 text = str(QtGui.QApplication.clipboard().text(mode)).rstrip()
460 except UnicodeEncodeError:
461 pass
462 else:
463 self._insert_plain_text_into_buffer(dedent(text))
449 # Remove any trailing newline, which confuses the GUI and forces the
450 # user to backspace.
451 text = unicode(QtGui.QApplication.clipboard().text(mode)).rstrip()
452 self._insert_plain_text_into_buffer(dedent(text))
464 453
465 454 def print_(self, printer):
466 455 """ Print the contents of the ConsoleWidget to the specified QPrinter.
@@ -623,7 +612,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
623 612 while cursor.movePosition(QtGui.QTextCursor.NextBlock):
624 613 temp_cursor = QtGui.QTextCursor(cursor)
625 614 temp_cursor.select(QtGui.QTextCursor.BlockUnderCursor)
626 text = str(temp_cursor.selection().toPlainText()).lstrip()
615 text = unicode(temp_cursor.selection().toPlainText()).lstrip()
627 616 if not text.startswith(prompt):
628 617 break
629 618 else:
@@ -1089,7 +1078,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1089 1078 if size == 0:
1090 1079 return '\n'
1091 1080 elif size == 1:
1092 return '%s\n' % str(items[0])
1081 return '%s\n' % items[0]
1093 1082
1094 1083 # Try every row count from 1 upwards
1095 1084 array_index = lambda nrows, row, col: nrows*col + row
@@ -1127,7 +1116,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1127 1116 del texts[-1]
1128 1117 for col in range(len(texts)):
1129 1118 texts[col] = texts[col].ljust(colwidths[col])
1130 string += '%s\n' % str(separator.join(texts))
1119 string += '%s\n' % separator.join(texts)
1131 1120 return string
1132 1121
1133 1122 def _get_block_plain_text(self, block):
@@ -1137,7 +1126,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1137 1126 cursor.movePosition(QtGui.QTextCursor.StartOfBlock)
1138 1127 cursor.movePosition(QtGui.QTextCursor.EndOfBlock,
1139 1128 QtGui.QTextCursor.KeepAnchor)
1140 return str(cursor.selection().toPlainText())
1129 return unicode(cursor.selection().toPlainText())
1141 1130
1142 1131 def _get_cursor(self):
1143 1132 """ Convenience method that returns a cursor for the current position.
@@ -1280,7 +1269,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1280 1269 self._insert_html(cursor, html)
1281 1270 end = cursor.position()
1282 1271 cursor.setPosition(start, QtGui.QTextCursor.KeepAnchor)
1283 text = str(cursor.selection().toPlainText())
1272 text = unicode(cursor.selection().toPlainText())
1284 1273
1285 1274 cursor.setPosition(end)
1286 1275 cursor.endEditBlock()
@@ -1320,7 +1309,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1320 1309 """ Inserts text into the input buffer at the current cursor position,
1321 1310 ensuring that continuation prompts are inserted as necessary.
1322 1311 """
1323 lines = str(text).splitlines(True)
1312 lines = unicode(text).splitlines(True)
1324 1313 if lines:
1325 1314 self._keep_cursor_in_buffer()
1326 1315 cursor = self._control.textCursor()
@@ -1530,7 +1519,7 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
1530 1519 if cursor.position() > 0:
1531 1520 cursor.movePosition(QtGui.QTextCursor.Left,
1532 1521 QtGui.QTextCursor.KeepAnchor)
1533 if str(cursor.selection().toPlainText()) != '\n':
1522 if unicode(cursor.selection().toPlainText()) != '\n':
1534 1523 self._append_plain_text('\n')
1535 1524
1536 1525 # Write the prompt.
@@ -144,7 +144,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
144 144 def copy(self):
145 145 """ Copy the currently selected text to the clipboard, removing prompts.
146 146 """
147 text = str(self._control.textCursor().selection().toPlainText())
147 text = unicode(self._control.textCursor().selection().toPlainText())
148 148 if text:
149 149 lines = map(transform_classic_prompt, text.splitlines())
150 150 text = '\n'.join(lines)
@@ -489,7 +489,7 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
489 489 cursor = self._get_cursor()
490 490 cursor.movePosition(QtGui.QTextCursor.StartOfBlock,
491 491 QtGui.QTextCursor.KeepAnchor)
492 text = str(cursor.selection().toPlainText())
492 text = unicode(cursor.selection().toPlainText())
493 493 return self._completion_lexer.get_context(text)
494 494
495 495 def _process_execute_abort(self, msg):
@@ -206,7 +206,7 b' class IPythonWidget(FrontendWidget):'
206 206 """ Copy the currently selected text to the clipboard, removing prompts
207 207 if possible.
208 208 """
209 text = str(self._control.textCursor().selection().toPlainText())
209 text = unicode(self._control.textCursor().selection().toPlainText())
210 210 if text:
211 211 lines = map(transform_ipy_prompt, text.splitlines())
212 212 text = '\n'.join(lines)
General Comments 0
You need to be logged in to leave comments. Login now