eric6/MicroPython/MicroPythonWidget.py

changeset 8079
331e717c458e
parent 8072
58491f4c99d6
child 8082
2242a6a1d786
diff -r d0e6c9ef0f15 -r 331e717c458e eric6/MicroPython/MicroPythonWidget.py
--- a/eric6/MicroPython/MicroPythonWidget.py	Sat Feb 06 11:45:58 2021 +0100
+++ b/eric6/MicroPython/MicroPythonWidget.py	Sat Feb 06 16:05:27 2021 +0100
@@ -45,6 +45,8 @@
 import Preferences
 import Utilities
 
+from UI.Info import BugAddress
+
 # ANSI Colors (see https://en.wikipedia.org/wiki/ANSI_escape_code)
 AnsiColorSchemes = {
     "Windows 7": {
@@ -349,13 +351,15 @@
                         '<li>{0}</li>'
                         '</ul>'
                         '<p>Please report them together with the board name'
-                        ' and a short description to <a href="mailto:'
-                        'eric-bugs@eric-ide.python-projects.org"> the eric'
-                        ' bug reporting address</a> if it is a MicroPython'
-                        ' board.</p>'
+                        ' and a short description to <a href="mailto:{1}">'
+                        ' the eric bug reporting address</a> if it is a'
+                        ' MicroPython board.</p>'
                     ).format("</li><li>".join([
-                        self.tr("{0} ({1:04x}/{2:04x})").format(desc, vid, pid)
-                        for vid, pid, desc in newUnknownDevices])),
+                        self.tr("{0} (0x{1:04x}/0x{2:04x})",
+                                "description, VId, PId").format(
+                            desc, vid, pid)
+                        for vid, pid, desc in newUnknownDevices]),
+                        BugAddress),
                     E5MessageBox.StandardButtons(
                         E5MessageBox.Ignore |
                         E5MessageBox.Ok
@@ -365,6 +369,15 @@
                     ignoredUnknown = list(ignoredUnknown | newUnknownDevices)
                     Preferences.setMicroPython("IgnoredUnknownDevices",
                                                ignoredUnknown)
+                else:
+                    yes = E5MessageBox.yesNo(
+                        self,
+                        self.tr("Unknown MicroPython Device"),
+                        self.tr("""Would you like to add them to the list of"""
+                                """ manually configured devices?"""),
+                        yesDefault=True)
+                    if yes:
+                        self.__addUnknownDevices(list(newUnknownDevices))
     
     def __handlePreferencesChanged(self):
         """
@@ -1257,6 +1270,8 @@
                 self.tr("Show Documentation"), self.__showDocumentation)
             act.setEnabled(self.__device.hasDocumentationUrl())
         self.__superMenu.addSeparator()
+        self.__superMenu.addAction(self.tr("Manage Unknown Devices"),
+                                   self.__manageUnknownDevices)
         self.__superMenu.addAction(self.tr("Ignored Serial Devices"),
                                    self.__manageIgnored)
         self.__superMenu.addSeparator()
@@ -1634,3 +1649,47 @@
         Private slot to open the MicroPython configuration page.
         """
         e5App().getObject("UserInterface").showPreferences("microPythonPage")
+    
+    @pyqtSlot()
+    def __manageUnknownDevices(self):
+        """
+        Private slot to manage manually added boards (i.e. those not in the
+        list of supported boards).
+        """
+        from .UnknownDevicesDialog import UnknownDevicesDialog
+        dlg = UnknownDevicesDialog()
+        dlg.exec()
+    
+    def __addUnknownDevices(self, devices):
+        """
+        Private method to add devices to the list of manually added boards.
+        
+        @param devices list of not ignored but unknown devices
+        @type list of tuple of (int, int, str)
+        """
+        from .AddEditDevicesDialog import AddEditDevicesDialog
+        
+        if len(devices) > 1:
+            from E5Gui.E5ListSelectionDialog import E5ListSelectionDialog
+            sdlg = E5ListSelectionDialog(
+                [d[2] for d in devices],
+                title=self.tr("Add Unknown Devices"),
+                message=self.tr("Select the devices to be added:"),
+                checkBoxSelection=True
+            )
+            if sdlg.exec() == QDialog.Accepted:
+                selectedDevices = sdlg.getSelection()
+        else:
+            selectedDevices = devices[0][2]
+        
+        if selectedDevices:
+            manualDevices = Preferences.getMicroPython("ManualDevices")
+            for vid, pid, description in devices:
+                if description in selectedDevices:
+                    dlg = AddEditDevicesDialog(vid, pid, description)
+                    if dlg.exec() == QDialog.Accepted:
+                        manualDevices.append(dlg.getDeviceDict())
+            Preferences.setMicroPython("ManualDevices", manualDevices)
+            
+            # rescan the ports
+            self.__populateDeviceTypeComboBox()

eric ide

mercurial