Show More
@@ -268,7 +268,6 class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): | |||
|
268 | 268 | self._continuation_prompt = '> ' |
|
269 | 269 | self._continuation_prompt_html = None |
|
270 | 270 | self._executing = False |
|
271 | self._filter_drag = False | |
|
272 | 271 | self._filter_resize = False |
|
273 | 272 | self._html_exporter = HtmlExporter(self._control) |
|
274 | 273 | self._input_buffer_executing = '' |
@@ -343,7 +342,37 class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): | |||
|
343 | 342 | triggered=self.reset_font) |
|
344 | 343 | self.addAction(self.reset_font_size) |
|
345 | 344 | |
|
345 | # Accept drag and drop events here. Drops were already turned off | |
|
346 | # in self._control when that widget was created. | |
|
347 | self.setAcceptDrops(True) | |
|
346 | 348 | |
|
349 | #--------------------------------------------------------------------------- | |
|
350 | # Drag and drop support | |
|
351 | #--------------------------------------------------------------------------- | |
|
352 | ||
|
353 | def dragEnterEvent(self, e): | |
|
354 | if e.mimeData().hasText(): | |
|
355 | # By changing the action to copy we don't need to worry about | |
|
356 | # the user accidentally moving text around in the widget. | |
|
357 | e.setDropAction(QtCore.Qt.CopyAction) | |
|
358 | e.accept() | |
|
359 | ||
|
360 | def dragMoveEvent(self, e): | |
|
361 | if e.mimeData().hasText(): | |
|
362 | cursor = self._control.cursorForPosition(e.pos()) | |
|
363 | if self._in_buffer(cursor.position()): | |
|
364 | e.setDropAction(QtCore.Qt.CopyAction) | |
|
365 | self._control.setTextCursor(cursor) | |
|
366 | else: | |
|
367 | e.setDropAction(QtCore.Qt.IgnoreAction) | |
|
368 | e.accept() | |
|
369 | ||
|
370 | def dropEvent(self, e): | |
|
371 | if e.mimeData().hasText(): | |
|
372 | cursor = self._control.cursorForPosition(e.pos()) | |
|
373 | if self._in_buffer(cursor.position()): | |
|
374 | text = e.mimeData().text() | |
|
375 | self._insert_plain_text_into_buffer(cursor, text) | |
|
347 | 376 | |
|
348 | 377 | def eventFilter(self, obj, event): |
|
349 | 378 | """ Reimplemented to ensure a console-like behavior in the underlying |
@@ -392,39 +421,6 class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): | |||
|
392 | 421 | event.key() in self._shortcuts: |
|
393 | 422 | event.accept() |
|
394 | 423 | |
|
395 | # Ensure that drags are safe. The problem is that the drag starting | |
|
396 | # logic, which determines whether the drag is a Copy or Move, is locked | |
|
397 | # down in QTextControl. If the widget is editable, which it must be if | |
|
398 | # we're not executing, the drag will be a Move. The following hack | |
|
399 | # prevents QTextControl from deleting the text by clearing the selection | |
|
400 | # when a drag leave event originating from this widget is dispatched. | |
|
401 | # The fact that we have to clear the user's selection is unfortunate, | |
|
402 | # but the alternative--trying to prevent Qt from using its hardwired | |
|
403 | # drag logic and writing our own--is worse. | |
|
404 | elif etype == QtCore.QEvent.DragEnter and \ | |
|
405 | obj == self._control.viewport() and \ | |
|
406 | event.source() == self._control.viewport(): | |
|
407 | self._filter_drag = True | |
|
408 | elif etype == QtCore.QEvent.DragLeave and \ | |
|
409 | obj == self._control.viewport() and \ | |
|
410 | self._filter_drag: | |
|
411 | cursor = self._control.textCursor() | |
|
412 | cursor.clearSelection() | |
|
413 | self._control.setTextCursor(cursor) | |
|
414 | self._filter_drag = False | |
|
415 | ||
|
416 | # Ensure that drops are safe. | |
|
417 | elif etype == QtCore.QEvent.Drop and obj == self._control.viewport(): | |
|
418 | cursor = self._control.cursorForPosition(event.pos()) | |
|
419 | if self._in_buffer(cursor.position()): | |
|
420 | text = event.mimeData().text() | |
|
421 | self._insert_plain_text_into_buffer(cursor, text) | |
|
422 | ||
|
423 | # Qt is expecting to get something here--drag and drop occurs in its | |
|
424 | # own event loop. Send a DragLeave event to end it. | |
|
425 | QtGui.qApp.sendEvent(obj, QtGui.QDragLeaveEvent()) | |
|
426 | return True | |
|
427 | ||
|
428 | 424 | # Handle scrolling of the vsplit pager. This hack attempts to solve |
|
429 | 425 | # problems with tearing of the help text inside the pager window. This |
|
430 | 426 | # happens only on Mac OS X with both PySide and PyQt. This fix isn't |
@@ -1035,8 +1031,12 class ConsoleWidget(LoggingConfigurable, QtGui.QWidget): | |||
|
1035 | 1031 | control.setAcceptRichText(False) |
|
1036 | 1032 | control.setMouseTracking(True) |
|
1037 | 1033 | |
|
1034 | # Prevent the widget from handling drops, as we already provide | |
|
1035 | # the logic in this class. | |
|
1036 | control.setAcceptDrops(False) | |
|
1037 | ||
|
1038 | 1038 | # Install event filters. The filter on the viewport is needed for |
|
1039 |
# mouse events |
|
|
1039 | # mouse events. | |
|
1040 | 1040 | control.installEventFilter(self) |
|
1041 | 1041 | control.viewport().installEventFilter(self) |
|
1042 | 1042 |
General Comments 0
You need to be logged in to leave comments.
Login now