--- a/eric6/MicroPython/MicroPythonWidget.py Mon Mar 01 17:48:43 2021 +0100 +++ b/eric6/MicroPython/MicroPythonWidget.py Tue Mar 02 17:17:09 2021 +0100 @@ -189,11 +189,11 @@ ZoomMin = -10 ZoomMax = 20 - DeviceTypeRole = Qt.UserRole - DeviceBoardRole = Qt.UserRole + 1 - DevicePortRole = Qt.UserRole + 2 - DeviceVidRole = Qt.UserRole + 3 - DevicePidRole = Qt.UserRole + 4 + DeviceTypeRole = Qt.ItemDataRole.UserRole + DeviceBoardRole = Qt.ItemDataRole.UserRole + 1 + DevicePortRole = Qt.ItemDataRole.UserRole + 2 + DeviceVidRole = Qt.ItemDataRole.UserRole + 3 + DevicePidRole = Qt.ItemDataRole.UserRole + 4 dataReceived = pyqtSignal(bytes) @@ -218,9 +218,11 @@ "micropython_supermenu_button") self.menuButton.setIcon(UI.PixmapCache.getIcon("superMenu")) self.menuButton.setToolTip(self.tr("MicroPython Menu")) - self.menuButton.setPopupMode(QToolButton.InstantPopup) - self.menuButton.setToolButtonStyle(Qt.ToolButtonIconOnly) - self.menuButton.setFocusPolicy(Qt.NoFocus) + self.menuButton.setPopupMode( + QToolButton.ToolButtonPopupMode.InstantPopup) + self.menuButton.setToolButtonStyle( + Qt.ToolButtonStyle.ToolButtonIconOnly) + self.menuButton.setFocusPolicy(Qt.FocusPolicy.NoFocus) self.menuButton.setAutoRaise(True) self.menuButton.setShowMenuInside(True) self.menuButton.setMenu(self.__superMenu) @@ -239,8 +241,8 @@ self.connectButton.setIcon(UI.PixmapCache.getIcon("linkConnect")) self.__zoomLayout = QHBoxLayout() - spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, - QSizePolicy.Minimum) + spacerItem = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, + QSizePolicy.Policy.Minimum) self.__zoomLayout.addSpacerItem(spacerItem) self.__zoom0 = self.replEdit.fontPointSize() @@ -357,7 +359,7 @@ self.deviceInfoLabel.setText(supportedMessage + unknownMessage) index = self.deviceTypeComboBox.findText(currentDevice, - Qt.MatchExactly) + Qt.MatchFlag.MatchExactly) if index == -1: # entry is no longer present index = 0 @@ -427,9 +429,9 @@ self.replEdit.setFontPointSize(self.__font.pointSize()) if Preferences.getMicroPython("ReplLineWrap"): - self.replEdit.setLineWrapMode(QTextEdit.WidgetWidth) + self.replEdit.setLineWrapMode(QTextEdit.LineWrapMode.WidgetWidth) else: - self.replEdit.setLineWrapMode(QTextEdit.NoWrap) + self.replEdit.setLineWrapMode(QTextEdit.LineWrapMode.NoWrap) if self.__chartWidget is not None: self.__chartWidget.preferencesChanged() @@ -523,11 +525,13 @@ @type QPoint """ if Globals.isMacPlatform(): - copyKeys = QKeySequence(Qt.CTRL + Qt.Key_C) - pasteKeys = QKeySequence(Qt.CTRL + Qt.Key_V) + copyKeys = QKeySequence(Qt.Modifier.CTRL + Qt.Key.Key_C) + pasteKeys = QKeySequence(Qt.Modifier.CTRL + Qt.Key.Key_V) else: - copyKeys = QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_C) - pasteKeys = QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_V) + copyKeys = QKeySequence( + Qt.Modifier.CTRL + Qt.Modifier.SHIFT + Qt.Key.Key_C) + pasteKeys = QKeySequence( + Qt.Modifier.CTRL + Qt.Modifier.SHIFT + Qt.Key.Key_V) menu = QMenu(self) menu.addAction(self.tr("Clear"), self.__clear) menu.addSeparator() @@ -621,7 +625,7 @@ self.__interface.write(b'\x03') self.__device.setRepl(True) - self.replEdit.setFocus(Qt.OtherFocusReason) + self.replEdit.setFocus(Qt.FocusReason.OtherFocusReason) else: self.__interface.dataReceived.disconnect(self.__processData) if (not self.chartButton.isChecked() and @@ -687,47 +691,49 @@ @return flag to indicate that the event was handled @rtype bool """ - if obj is self.replEdit and evt.type() == QEvent.KeyPress: + if obj is self.replEdit and evt.type() == QEvent.Type.KeyPress: # handle the key press event on behalve of the REPL pane key = evt.key() msg = bytes(evt.text(), 'utf8') - if key == Qt.Key_Backspace: + if key == Qt.Key.Key_Backspace: msg = b'\b' - elif key == Qt.Key_Delete: + elif key == Qt.Key.Key_Delete: msg = b'\x1B[\x33\x7E' - elif key == Qt.Key_Up: + elif key == Qt.Key.Key_Up: msg = b'\x1B[A' - elif key == Qt.Key_Down: + elif key == Qt.Key.Key_Down: msg = b'\x1B[B' - elif key == Qt.Key_Right: + elif key == Qt.Key.Key_Right: msg = b'\x1B[C' - elif key == Qt.Key_Left: + elif key == Qt.Key.Key_Left: msg = b'\x1B[D' - elif key == Qt.Key_Home: + elif key == Qt.Key.Key_Home: msg = b'\x1B[H' - elif key == Qt.Key_End: + elif key == Qt.Key.Key_End: msg = b'\x1B[F' elif ((Globals.isMacPlatform() and - evt.modifiers() == Qt.MetaModifier) or + evt.modifiers() == Qt.KeyboardModifier.MetaModifier) or (not Globals.isMacPlatform() and - evt.modifiers() == Qt.ControlModifier)): - if Qt.Key_A <= key <= Qt.Key_Z: + evt.modifiers() == Qt.KeyboardModifier.ControlModifier)): + if Qt.Key.Key_A <= key <= Qt.Key.Key_Z: # devices treat an input of \x01 as Ctrl+A, etc. - msg = bytes([1 + key - Qt.Key_A]) + msg = bytes([1 + key - Qt.Key.Key_A]) elif ( - evt.modifiers() == (Qt.ControlModifier | Qt.ShiftModifier) or + evt.modifiers() == ( + Qt.KeyboardModifier.ControlModifier | + Qt.KeyboardModifier.ShiftModifier) or (Globals.isMacPlatform() and - evt.modifiers() == Qt.ControlModifier) + evt.modifiers() == Qt.KeyboardModifier.ControlModifier) ): - if key == Qt.Key_C: + if key == Qt.Key.Key_C: self.replEdit.copy() msg = b'' - elif key == Qt.Key_V: + elif key == Qt.Key.Key_V: self.__paste() msg = b'' - elif key in (Qt.Key_Return, Qt.Key_Enter): + elif key in (Qt.Key.Key_Return, Qt.Key.Key_Enter): tc = self.replEdit.textCursor() - tc.movePosition(QTextCursor.EndOfLine) + tc.movePosition(QTextCursor.MoveOperation.EndOfLine) self.replEdit.setTextCursor(tc) self.__interface.isConnected() and self.__interface.write(msg) return True @@ -740,14 +746,14 @@ 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). + QEvent.Type.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: + if evt.button() == Qt.MouseButton.MiddleButton: self.__paste(mode=QClipboard.Mode.Selection) msg = b'' if self.__interface.isConnected(): @@ -765,7 +771,7 @@ """ tc = self.replEdit.textCursor() # the text cursor must be on the last line - while tc.movePosition(QTextCursor.Down): + while tc.movePosition(QTextCursor.MoveOperation.Down): pass # set the font @@ -777,7 +783,7 @@ index = 0 while index < len(data): if data[index] == 8: # \b - tc.movePosition(QTextCursor.Left) + tc.movePosition(QTextCursor.MoveOperation.Left) self.replEdit.setTextCursor(tc) elif data[index] in (4, 13): # EOT, \r pass @@ -800,35 +806,43 @@ count = int(match.group("count")) if action == "A": # up - tc.movePosition(QTextCursor.Up, n=count) + tc.movePosition(QTextCursor.MoveOperation.Up, + n=count) self.replEdit.setTextCursor(tc) elif action == "B": # down - tc.movePosition(QTextCursor.Down, n=count) + tc.movePosition(QTextCursor.MoveOperation.Down, + n=count) self.replEdit.setTextCursor(tc) elif action == "C": # right - tc.movePosition(QTextCursor.Right, n=count) + tc.movePosition(QTextCursor.MoveOperation.Right, + n=count) self.replEdit.setTextCursor(tc) elif action == "D": # left - tc.movePosition(QTextCursor.Left, n=count) + tc.movePosition(QTextCursor.MoveOperation.Left, + n=count) self.replEdit.setTextCursor(tc) elif action == "K": # delete things if match.group("count") in ("", "0"): # delete to end of line - tc.movePosition(QTextCursor.EndOfLine, - mode=QTextCursor.KeepAnchor) + tc.movePosition( + QTextCursor.MoveOperation.EndOfLine, + mode=QTextCursor.MoveMode.KeepAnchor) tc.removeSelectedText() self.replEdit.setTextCursor(tc) elif match.group("count") == "1": # delete to beinning of line - tc.movePosition(QTextCursor.StartOfLine, - mode=QTextCursor.KeepAnchor) + tc.movePosition( + QTextCursor.MoveOperation.StartOfLine, + mode=QTextCursor.MoveMode.KeepAnchor) tc.removeSelectedText() self.replEdit.setTextCursor(tc) elif match.group("count") == "2": # delete whole line - tc.movePosition(QTextCursor.EndOfLine) - tc.movePosition(QTextCursor.StartOfLine, - mode=QTextCursor.KeepAnchor) + tc.movePosition( + QTextCursor.MoveOperation.EndOfLine) + tc.movePosition( + QTextCursor.MoveOperation.StartOfLine, + mode=QTextCursor.MoveMode.KeepAnchor) tc.removeSelectedText() self.replEdit.setTextCursor(tc) elif action == "m": @@ -1029,7 +1043,7 @@ dlg = ConnectionSelectionDialog( self.__unknownPorts, self.__lastPort, self.__lastDeviceType ) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: vid, pid, port, deviceType = dlg.getData() self.deviceIconLabel.setPixmap( @@ -1742,7 +1756,7 @@ dlg = IgnoredDevicesDialog( Preferences.getMicroPython("IgnoredUnknownDevices"), self) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: ignoredDevices = dlg.getDevices() Preferences.setMicroPython("IgnoredUnknownDevices", ignoredDevices) @@ -1781,7 +1795,7 @@ message=self.tr("Select the devices to be added:"), checkBoxSelection=True ) - if sdlg.exec() == QDialog.Accepted: + if sdlg.exec() == QDialog.DialogCode.Accepted: selectedDevices = sdlg.getSelection() else: selectedDevices = devices[0][2] @@ -1791,7 +1805,7 @@ for vid, pid, description in devices: if description in selectedDevices: dlg = AddEditDevicesDialog(vid, pid, description) - if dlg.exec() == QDialog.Accepted: + if dlg.exec() == QDialog.DialogCode.Accepted: manualDevices.append(dlg.getDeviceDict()) Preferences.setMicroPython("ManualDevices", manualDevices)