MicroPython: implemented fixes for a few issues.

Wed, 03 Feb 2021 19:14:35 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 03 Feb 2021 19:14:35 +0100
changeset 8061
979562f350bf
parent 8060
78aea20be1ec
child 8062
8dc5acb30a8b

MicroPython: implemented fixes for a few issues.

eric6/MicroPython/MicroPythonCommandsInterface.py file | annotate | diff | comparison | revisions
eric6/MicroPython/MicroPythonWidget.py file | annotate | diff | comparison | revisions
--- a/eric6/MicroPython/MicroPythonCommandsInterface.py	Wed Feb 03 16:42:04 2021 +0100
+++ b/eric6/MicroPython/MicroPythonCommandsInterface.py	Wed Feb 03 19:14:35 2021 +0100
@@ -143,11 +143,17 @@
         rawReplMessage = b"raw REPL; CTRL-B to exit\r\n>"
         
         self.__serial.write(b"\x02")        # end raw mode if required
-        self.__serial.waitForBytesWritten()
+        written = self.__serial.waitForBytesWritten(500)
+        # time out after 500ms if device is not responding
+        if not written:
+            return False
         for _i in range(3):
             # CTRL-C three times to break out of loops
             self.__serial.write(b"\r\x03")
-            self.__serial.waitForBytesWritten()
+            written = self.__serial.waitForBytesWritten(500)
+            # time out after 500ms if device is not responding
+            if not written:
+                return False
             QThread.msleep(10)
         self.__serial.readAll()             # read all data and discard it
         self.__serial.write(b"\r\x01")      # send CTRL-A to enter raw mode
@@ -806,21 +812,30 @@
         @exception OSError raised to indicate an issue with the device
         """
         commands = [
-            "import time as __time_",
             "\n".join([
                 "try:",
-                "    print(__time_.strftime('%Y-%m-%d %H:%M:%S',"
+                "    import rtc as __rtc_",
+                "    print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'"
+                ".format(*__rtc_.RTC().datetime[:6]))",
+                "    del __rtc_",
+                "except:",
+                "    import time as __time_",
+                "    try:",
+                "        print(__time_.strftime('%Y-%m-%d %H:%M:%S',"
                 # __IGNORE_WARNING_M601__
                 " __time_.localtime()))",
-                "except AttributeError:",
-                "    tm = __time_.localtime()",
-                "    print('{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'"
+                "    except AttributeError:",
+                "        tm = __time_.localtime()",
+                "        print('{0:04d}-{1:02d}-{2:02d}"
+                " {3:02d}:{4:02d}:{5:02d}'"
                 ".format(tm[0], tm[1], tm[2], tm[3], tm[4], tm[5]))",
-                "    del tm",
+                "        del tm",
+                "    del __time_"
             ]),
-            "del __time_"
         ]
         out, err = self.execute(commands)
         if err:
+            if b"NotImplementedError" in err:
+                return "&lt;unsupported&gt; &lt;unsupported&gt;"
             raise OSError(self.__shortError(err))
         return out.decode("utf-8").strip()
--- a/eric6/MicroPython/MicroPythonWidget.py	Wed Feb 03 16:42:04 2021 +0100
+++ b/eric6/MicroPython/MicroPythonWidget.py	Wed Feb 03 19:14:35 2021 +0100
@@ -23,6 +23,7 @@
 from E5Gui import E5MessageBox, E5FileDialog
 from E5Gui.E5Application import e5App
 from E5Gui.E5ProcessDialog import E5ProcessDialog
+from E5Gui.E5OverrideCursor import E5OverrideCursor, E5OverridenCursor
 
 from .Ui_MicroPythonWidget import Ui_MicroPythonWidget
 
@@ -573,7 +574,8 @@
         currently connected device.
         """
         if self.__connected:
-            self.__disconnectFromDevice()
+            with E5OverrideCursor():
+                self.__disconnectFromDevice()
             
             if self.replButton.isChecked():
                 self.on_replButton_clicked(False)
@@ -582,7 +584,8 @@
             if self.chartButton.isChecked():
                 self.on_chartButton_clicked(False)
         else:
-            self.__connectToDevice()
+            with E5OverrideCursor():
+                self.__connectToDevice()
     
     @pyqtSlot()
     def __clear(self):
@@ -597,6 +600,7 @@
         """
         Private slot to perform a paste operation.
         """
+        # add support for paste by mouse middle button
         clipboard = QApplication.clipboard()
         if clipboard:
             pasteText = clipboard.text()
@@ -687,7 +691,7 @@
             if data[index] == 8:        # \b
                 tc.movePosition(QTextCursor.Left)
                 self.replEdit.setTextCursor(tc)
-            elif data[index] == 13:     # \r
+            elif data[index] in (4, 13):     # EOT, \r
                 pass
             elif (len(data) > index + 1 and
                   data[index] == 27 and
@@ -928,11 +932,12 @@
                     self.__device.hasTimeCommands()):
                 self.__synchronizeTime(quiet=True)
         else:
-            E5MessageBox.warning(
-                self,
-                self.tr("Serial Device Connect"),
-                self.tr("""<p>Cannot connect to device at serial port"""
-                        """ <b>{0}</b>.</p>""").format(port))
+            with E5OverridenCursor():
+                E5MessageBox.warning(
+                    self,
+                    self.tr("Serial Device Connect"),
+                    self.tr("""<p>Cannot connect to device at serial port"""
+                            """ <b>{0}</b>.</p>""").format(port))
     
     def __disconnectFromDevice(self):
         """
@@ -1308,13 +1313,14 @@
             self.__interface.syncTime()
             
             if not quiet:
-                E5MessageBox.information(
-                    self,
-                    self.tr("Synchronize Time"),
-                    self.tr("<p>The time of the connected device was"
-                            " synchronized with the local time.</p>") +
-                    self.__getDeviceTime()
-                )
+                with E5OverridenCursor():
+                    E5MessageBox.information(
+                        self,
+                        self.tr("Synchronize Time"),
+                        self.tr("<p>The time of the connected device was"
+                                " synchronized with the local time.</p>") +
+                        self.__getDeviceTime()
+                    )
         except Exception as exc:
             self.__showError("syncTime()", str(exc))
     
@@ -1352,10 +1358,11 @@
         Private slot to show the date and time of the connected device.
         """
         msg = self.__getDeviceTime()
-        E5MessageBox.information(
-            self,
-            self.tr("Device Date and Time"),
-            msg)
+        if msg:
+            E5MessageBox.information(
+                self,
+                self.tr("Device Date and Time"),
+                msg)
     
     @pyqtSlot()
     def __showLocalTime(self):
@@ -1432,12 +1439,14 @@
         @param error error message
         @type str
         """
-        E5MessageBox.warning(
-            self,
-            self.tr("Error handling device"),
-            self.tr("<p>There was an error communicating with the connected"
-                    " device.</p><p>Method: {0}</p><p>Message: {1}</p>")
-            .format(method, error))
+        with E5OverridenCursor():
+            E5MessageBox.warning(
+                self,
+                self.tr("Error handling device"),
+                self.tr("<p>There was an error communicating with the"
+                        " connected device.</p><p>Method: {0}</p>"
+                        "<p>Message: {1}</p>")
+                .format(method, error))
     
     def __mpyCrossAvailable(self):
         """

eric ide

mercurial