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