##// END OF EJS Templates
Made middle-click paste safe. Fixes bug reported by fperez.
epatters -
Show More
@@ -188,6 +188,15 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
188 elif obj == self._page_control:
188 elif obj == self._page_control:
189 return self._event_filter_page_keypress(event)
189 return self._event_filter_page_keypress(event)
190
190
191 # Make middle-click paste safe.
192 elif etype == QtCore.QEvent.MouseButtonRelease and \
193 event.button() == QtCore.Qt.MidButton and \
194 obj == self._control.viewport():
195 cursor = self._control.cursorForPosition(event.pos());
196 self._control.setTextCursor(cursor)
197 self.paste(QtGui.QClipboard.Selection)
198 return True
199
191 # Override shortucts for all filtered widgets. Note that on Mac OS it is
200 # Override shortucts for all filtered widgets. Note that on Mac OS it is
192 # always unnecessary to override shortcuts, hence the check below (users
201 # always unnecessary to override shortcuts, hence the check below (users
193 # should just use the Control key instead of the Command key).
202 # should just use the Control key instead of the Command key).
@@ -415,12 +424,20 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
415
424
416 font = property(_get_font, _set_font)
425 font = property(_get_font, _set_font)
417
426
418 def paste(self):
427 def paste(self, mode=QtGui.QClipboard.Clipboard):
419 """ Paste the contents of the clipboard into the input region.
428 """ Paste the contents of the clipboard into the input region.
429
430 Parameters:
431 -----------
432 mode : QClipboard::Mode, optional [default QClipboard::Clipboard]
433
434 Controls which part of the system clipboard is used. This can be
435 used to access the selection clipboard in X11 and the Find buffer
436 in Mac OS. By default, the regular clipboard is used.
420 """
437 """
421 if self._control.textInteractionFlags() & QtCore.Qt.TextEditable:
438 if self._control.textInteractionFlags() & QtCore.Qt.TextEditable:
422 try:
439 try:
423 text = str(QtGui.QApplication.clipboard().text())
440 text = str(QtGui.QApplication.clipboard().text(mode))
424 except UnicodeEncodeError:
441 except UnicodeEncodeError:
425 pass
442 pass
426 else:
443 else:
@@ -631,18 +648,27 b' class ConsoleWidget(Configurable, QtGui.QWidget):'
631 def _create_control(self):
648 def _create_control(self):
632 """ Creates and connects the underlying text widget.
649 """ Creates and connects the underlying text widget.
633 """
650 """
651 # Create the underlying control.
634 if self.kind == 'plain':
652 if self.kind == 'plain':
635 control = ConsolePlainTextEdit()
653 control = ConsolePlainTextEdit()
636 elif self.kind == 'rich':
654 elif self.kind == 'rich':
637 control = ConsoleTextEdit()
655 control = ConsoleTextEdit()
638 control.setAcceptRichText(False)
656 control.setAcceptRichText(False)
657
658 # Install event filters. The filter on the viewport is needed for
659 # mouse events.
639 control.installEventFilter(self)
660 control.installEventFilter(self)
640 control.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
661 control.viewport().installEventFilter(self)
662
663 # Connect signals.
641 control.cursorPositionChanged.connect(self._cursor_position_changed)
664 control.cursorPositionChanged.connect(self._cursor_position_changed)
642 control.customContextMenuRequested.connect(self._show_context_menu)
665 control.customContextMenuRequested.connect(self._show_context_menu)
643 control.copyAvailable.connect(self.copy_available)
666 control.copyAvailable.connect(self.copy_available)
644 control.redoAvailable.connect(self.redo_available)
667 control.redoAvailable.connect(self.redo_available)
645 control.undoAvailable.connect(self.undo_available)
668 control.undoAvailable.connect(self.undo_available)
669
670 # Configure the control.
671 control.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
646 control.setReadOnly(True)
672 control.setReadOnly(True)
647 control.setUndoRedoEnabled(False)
673 control.setUndoRedoEnabled(False)
648 control.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
674 control.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
General Comments 0
You need to be logged in to leave comments. Login now