eric6/MicroPython/MicroPythonWidget.py

branch
micropython
changeset 7135
44fcfc99b864
parent 7134
21d23ca51680
child 7139
9bb36ec2d1b5
--- a/eric6/MicroPython/MicroPythonWidget.py	Tue Aug 13 15:51:35 2019 +0200
+++ b/eric6/MicroPython/MicroPythonWidget.py	Tue Aug 13 16:28:43 2019 +0200
@@ -137,8 +137,6 @@
 }
 
 
-# TODO: add config option to synchronize the device time upon connect
-
 class MicroPythonWidget(QWidget, Ui_MicroPythonWidget):
     """
     Class implementing the MicroPython REPL widget.
@@ -217,7 +215,7 @@
         self.__interface = MicroPythonCommandsInterface(self)
         self.__device = None
         self.__connected = False
-        self.setConnected(False)
+        self.__setConnected(False)
         
         if not HAS_QTSERIALPORT:
             self.replEdit.setHtml(self.tr(
@@ -391,9 +389,9 @@
         menu.addSeparator()
         menu.exec_(self.replEdit.mapToGlobal(pos))
     
-    def setConnected(self, connected):
+    def __setConnected(self, connected):
         """
-        Public method to set the connection status LED.
+        Private method to set the connection status LED.
         
         @param connected connection state
         @type bool
@@ -841,7 +839,10 @@
         """
         port = self.getCurrentPort()
         if self.__interface.connectToDevice(port):
-            self.setConnected(True)
+            self.__setConnected(True)
+            
+            if Preferences.getMicroPython("SyncTimeAfterConnect"):
+                self.__synchronizeTime(quiet=True)
         else:
             E5MessageBox.warning(
                 self,
@@ -854,7 +855,7 @@
         Private method to disconnect from the device.
         """
         self.__interface.disconnectFromDevice()
-        self.setConnected(False)
+        self.__setConnected(False)
     
     @pyqtSlot()
     def on_runButton_clicked(self):
@@ -1164,28 +1165,36 @@
         except Exception as exc:
             self.__showError("getImplementation()", str(exc))
     
-    # TODO: show device time after sync
     @pyqtSlot()
-    def __synchronizeTime(self):
+    def __synchronizeTime(self, quiet=False):
         """
         Private slot to set the time of the connected device to the local
         computer's time.
+        
+        @param quiet flag indicating to not show a message
+        @type bool
         """
         try:
             self.__interface.syncTime()
             
-            E5MessageBox.information(
-                self,
-                self.tr("Synchronize Time"),
-                self.tr("The time of the connected device was synchronized"
-                        " with the local time."))
+            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()
+                )
         except Exception as exc:
             self.__showError("syncTime()", str(exc))
     
-    @pyqtSlot()
-    def __showDeviceTime(self):
+    def __getDeviceTime(self):
         """
-        Private slot to show the date and time of the connected device.
+        Private method to get a string containing the date and time of the
+        connected device.
+        
+        @return date and time of the connected device
+        @rtype str
         """
         try:
             dateTimeString = self.__interface.getTime()
@@ -1203,13 +1212,21 @@
                     "<h3>Device Date and Time</h3>"
                     "<p>{0}</p>"
                 ).format(dateTimeString.strip())
-            
-            E5MessageBox.information(
-                self,
-                self.tr("Device Date and Time"),
-                msg)
+            return msg
         except Exception as exc:
             self.__showError("getTime()", str(exc))
+            return ""
+    
+    @pyqtSlot()
+    def __showDeviceTime(self):
+        """
+        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)
     
     @pyqtSlot()
     def __showLocalTime(self):

eric ide

mercurial