eric6/MicroPython/MicroPythonWidget.py

changeset 8133
4d1d1c248f79
parent 8121
9a2aa5353a32
child 8134
a5c4ac339f2a
--- a/eric6/MicroPython/MicroPythonWidget.py	Wed Feb 24 16:46:38 2021 +0100
+++ b/eric6/MicroPython/MicroPythonWidget.py	Wed Feb 24 17:55:10 2021 +0100
@@ -258,6 +258,10 @@
         self.__fileManagerWidget = None
         self.__chartWidget = None
         
+        self.__unknownPorts = []
+        self.__lastPort = None
+        self.__lastDeviceType = None
+        
         if HAS_QTSERIALPORT:
             self.__interface = MicroPythonCommandsInterface(self)
         else:
@@ -305,7 +309,9 @@
         self.deviceInfoLabel.clear()
         
         self.deviceTypeComboBox.addItem("", "")
-        devices, unknownDevices = MicroPythonDevices.getFoundDevices()
+        devices, unknownDevices, unknownPorts = (
+            MicroPythonDevices.getFoundDevices()
+        )
         if devices:
             self.deviceInfoLabel.setText(
                 self.tr("%n supported device(s) detected.", "", len(devices)))
@@ -391,6 +397,10 @@
                         yesDefault=True)
                     if yes:
                         self.__addUnknownDevices(list(newUnknownDevices))
+        
+        self.__unknownPorts = unknownPorts
+        if self.__unknownPorts:
+            self.connectButton.setEnabled(True)
     
     def __handlePreferencesChanged(self):
         """
@@ -457,7 +467,8 @@
                                                      vid, pid)
         self.__device.setButtons()
         
-        self.connectButton.setEnabled(bool(deviceType))
+        self.connectButton.setEnabled(bool(deviceType) or
+                                      bool(self.__unknownPorts))
     
     @pyqtSlot()
     def on_checkButton_clicked(self):
@@ -959,13 +970,15 @@
         @rtype str
         """
         portName = self.deviceTypeComboBox.currentData(self.DevicePortRole)
-        
-        if Globals.isWindowsPlatform():
-            # return it unchanged
-            return portName
+        if portName:
+            if Globals.isWindowsPlatform():
+                # return it unchanged
+                return portName
+            else:
+                # return with device path prepended
+                return "/dev/{0}".format(portName)
         else:
-            # return with device path prepended
-            return "/dev/{0}".format(portName)
+            return ""
     
     def getCurrentBoard(self):
         """
@@ -994,6 +1007,19 @@
         Private method to connect to the selected device.
         """
         port = self.getCurrentPort()
+        if not port:
+            # TODO: implement port and device selection dialog
+            deviceType = "circuitpython"
+            port = "ttyACM0"
+            vid = 0
+            pid = 0
+            
+            self.deviceIconLabel.setPixmap(MicroPythonDevices.getDeviceIcon(
+                deviceType, False))
+            self.__device = MicroPythonDevices.getDevice(deviceType, self,
+                                                         vid, pid)
+            self.__device.setButtons()
+        
         if self.__interface.connectToDevice(port):
             self.__setConnected(True)
             
@@ -1005,8 +1031,8 @@
                 E5MessageBox.warning(
                     self,
                     self.tr("Serial Device Connect"),
-                    self.tr("""<p>Cannot connect to device at serial port"""
-                            """ <b>{0}</b>.</p>""").format(port))
+                    self.tr("""<p>Cannot connect to device at serial"""
+                            """ port <b>{0}</b>.</p>""").format(port))
     
     def __disconnectFromDevice(self):
         """

eric ide

mercurial