Sun, 14 Feb 2021 18:23:56 +0100
MicroPython
- added code to support 'middle button paste'
--- a/docs/changelog Sat Feb 13 20:07:45 2021 +0100 +++ b/docs/changelog Sun Feb 14 18:23:56 2021 +0100 @@ -15,6 +15,7 @@ -- added capability to manually configure devices not yet known by eric6 -- added a generic dialog for flashing UF2 capable devices (with device detection) + -- added code to support 'middle button paste' - pip Interface -- changed code for the search function to work with the PyPI search page because the XML-RPC search interface of PyPI is still disabled
--- a/eric6/Documentation/Help/source.qhp Sat Feb 13 20:07:45 2021 +0100 +++ b/eric6/Documentation/Help/source.qhp Sun Feb 14 18:23:56 2021 +0100 @@ -9912,6 +9912,7 @@ <keyword name="MicroPythonWidget.__paste" id="MicroPythonWidget.__paste" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__paste" /> <keyword name="MicroPythonWidget.__populateDeviceTypeComboBox" id="MicroPythonWidget.__populateDeviceTypeComboBox" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__populateDeviceTypeComboBox" /> <keyword name="MicroPythonWidget.__processData" id="MicroPythonWidget.__processData" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__processData" /> + <keyword name="MicroPythonWidget.__replEditMouseReleaseEvent" id="MicroPythonWidget.__replEditMouseReleaseEvent" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__replEditMouseReleaseEvent" /> <keyword name="MicroPythonWidget.__setCharFormat" id="MicroPythonWidget.__setCharFormat" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__setCharFormat" /> <keyword name="MicroPythonWidget.__setConnected" id="MicroPythonWidget.__setConnected" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__setConnected" /> <keyword name="MicroPythonWidget.__showContextMenu" id="MicroPythonWidget.__showContextMenu" ref="eric6.MicroPython.MicroPythonWidget.html#MicroPythonWidget.__showContextMenu" />
--- a/eric6/Documentation/Source/eric6.MicroPython.MicroPythonWidget.html Sat Feb 13 20:07:45 2021 +0100 +++ b/eric6/Documentation/Source/eric6.MicroPython.MicroPythonWidget.html Sun Feb 14 18:23:56 2021 +0100 @@ -166,6 +166,10 @@ <td>Private slot to process bytes received from the device.</td> </tr> <tr> +<td><a href="#MicroPythonWidget.__replEditMouseReleaseEvent">__replEditMouseReleaseEvent</a></td> +<td>Private method handling mouse release events for the replEdit widget.</td> +</tr> +<tr> <td><a href="#MicroPythonWidget.__setCharFormat">__setCharFormat</a></td> <td>Private method setting the current text format of the REPL pane based on the passed ANSI codes.</td> </tr> @@ -493,11 +497,18 @@ </dl> <a NAME="MicroPythonWidget.__paste" ID="MicroPythonWidget.__paste"></a> <h4>MicroPythonWidget.__paste</h4> -<b>__paste</b>(<i></i>) +<b>__paste</b>(<i>mode=QClipboard.Mode.Clipboard</i>) <p> Private slot to perform a paste operation. </p> +<dl> + +<dt><i>mode</i> (QClipboard.Mode (optional))</dt> +<dd> +paste mode (defaults to QClipboard.Mode.Clipboard) +</dd> +</dl> <a NAME="MicroPythonWidget.__populateDeviceTypeComboBox" ID="MicroPythonWidget.__populateDeviceTypeComboBox"></a> <h4>MicroPythonWidget.__populateDeviceTypeComboBox</h4> <b>__populateDeviceTypeComboBox</b>(<i></i>) @@ -519,6 +530,26 @@ bytes received from the device </dd> </dl> +<a NAME="MicroPythonWidget.__replEditMouseReleaseEvent" ID="MicroPythonWidget.__replEditMouseReleaseEvent"></a> +<h4>MicroPythonWidget.__replEditMouseReleaseEvent</h4> +<b>__replEditMouseReleaseEvent</b>(<i>evt</i>) + +<p> + Private method handling mouse release events for the replEdit widget. +</p> +<p> + Note: this is a hack because QTextEdit does not allow filtering of + QEvent.MouseButtonRelease. To make middle button paste work, we had + to intercept the protected event method (some kind of reimplementing + it). +</p> +<dl> + +<dt><i>evt</i> (QMouseEvent)</dt> +<dd> +reference to the event object +</dd> +</dl> <a NAME="MicroPythonWidget.__setCharFormat" ID="MicroPythonWidget.__setCharFormat"></a> <h4>MicroPythonWidget.__setCharFormat</h4> <b>__setCharFormat</b>(<i>formatCodes, textCursor</i>)
--- a/eric6/MicroPython/MicroPythonWidget.py Sat Feb 13 20:07:45 2021 +0100 +++ b/eric6/MicroPython/MicroPythonWidget.py Sun Feb 14 18:23:56 2021 +0100 @@ -13,7 +13,7 @@ import functools from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QPoint, QEvent -from PyQt5.QtGui import QColor, QKeySequence, QTextCursor, QBrush +from PyQt5.QtGui import QColor, QKeySequence, QTextCursor, QBrush, QClipboard from PyQt5.QtWidgets import ( QWidget, QMenu, QApplication, QHBoxLayout, QSpacerItem, QSizePolicy, QTextEdit, QToolButton, QDialog @@ -279,6 +279,9 @@ self.__populateDeviceTypeComboBox() self.replEdit.installEventFilter(self) + # Hack to intercept middle button paste + self.__origReplEditMouseReleaseEvent = self.replEdit.mouseReleaseEvent + self.replEdit.mouseReleaseEvent = self.__replEditMouseReleaseEvent self.replEdit.customContextMenuRequested.connect( self.__showContextMenu) @@ -629,14 +632,17 @@ self.__interface.isConnected() and self.__interface.write(b"\r") @pyqtSlot() - def __paste(self): + def __paste(self, mode=QClipboard.Mode.Clipboard): """ Private slot to perform a paste operation. + + @param mode paste mode (defaults to QClipboard.Mode.Clipboard) + @type QClipboard.Mode (optional) """ # add support for paste by mouse middle button clipboard = QApplication.clipboard() if clipboard: - pasteText = clipboard.text() + pasteText = clipboard.text(mode=mode) if pasteText: pasteText = pasteText.replace('\n\r', '\r') pasteText = pasteText.replace('\n', '\r') @@ -681,9 +687,11 @@ if Qt.Key_A <= key <= Qt.Key_Z: # devices treat an input of \x01 as Ctrl+A, etc. msg = bytes([1 + key - Qt.Key_A]) - elif (evt.modifiers() == Qt.ControlModifier | Qt.ShiftModifier or - (Globals.isMacPlatform() and - evt.modifiers() == Qt.ControlModifier)): + elif ( + evt.modifiers() == (Qt.ControlModifier | Qt.ShiftModifier) or + (Globals.isMacPlatform() and + evt.modifiers() == Qt.ControlModifier) + ): if key == Qt.Key_C: self.replEdit.copy() msg = b'' @@ -696,11 +704,31 @@ self.replEdit.setTextCursor(tc) self.__interface.isConnected() and self.__interface.write(msg) return True - else: # standard event processing return super(MicroPythonWidget, self).eventFilter(obj, evt) + def __replEditMouseReleaseEvent(self, evt): + """ + Private method handling mouse release events for the replEdit widget. + + Note: this is a hack because QTextEdit does not allow filtering of + QEvent.MouseButtonRelease. To make middle button paste work, we had + to intercept the protected event method (some kind of reimplementing + it). + + @param evt reference to the event object + @type QMouseEvent + """ + if evt.button() == Qt.MiddleButton: + self.__paste(mode=QClipboard.Mode.Selection) + msg = b'' + if self.__interface.isConnected(): + self.__interface.write(msg) + evt.accept() + else: + self.__origReplEditMouseReleaseEvent(evt) + def __processData(self, data): """ Private slot to process bytes received from the device.