Fri, 01 Nov 2019 18:58:46 +0100
MicroPythonWidget
- added a menu entry to show the local and device time side-by-side
docs/changelog | file | annotate | diff | comparison | revisions | |
eric6/MicroPython/MicroPythonWidget.py | file | annotate | diff | comparison | revisions |
diff -r 8610ae96ad7b -r f05a814aeddc docs/changelog --- a/docs/changelog Fri Nov 01 16:55:20 2019 +0100 +++ b/docs/changelog Fri Nov 01 18:58:46 2019 +0100 @@ -2,6 +2,8 @@ ---------- Version 19.12: - bug fixes +- MicroPython + -- added a menu entry to show the local and device time side-by-side Version 19.11: - bug fixes @@ -10,7 +12,7 @@ -- added a context menu to select spell check language -- made the preview refresh timeout configurable (see Editor -> File Handling config page) -- Error Message Dialog: +- Error Message Dialog -- added a configurable minimum severity for messages being shown in a dialog (see Application config page) - MicroPython
diff -r 8610ae96ad7b -r f05a814aeddc eric6/MicroPython/MicroPythonWidget.py --- a/eric6/MicroPython/MicroPythonWidget.py Fri Nov 01 16:55:20 2019 +0100 +++ b/eric6/MicroPython/MicroPythonWidget.py Fri Nov 01 18:58:46 2019 +0100 @@ -1109,7 +1109,10 @@ act.setEnabled(self.__connected) self.__superMenu.addAction( self.tr("Show Local Time"), self.__showLocalTime) - # TODO: add entry to show local and device time side-by-side + if hasTime: + act = self.__superMenu.addAction( + self.tr("Show Time"), self.__showLocalAndDeviceTime) + act.setEnabled(self.__connected) self.__superMenu.addSeparator() if not Globals.isWindowsPlatform(): available = self.__mpyCrossAvailable() @@ -1255,7 +1258,7 @@ Private slot to show the local date and time. """ localdatetime = time.localtime() - loacldate = time.strftime('%Y-%m-%d', localdatetime) + localdate = time.strftime('%Y-%m-%d', localdatetime) localtime = time.strftime('%H:%M:%S', localdatetime) E5MessageBox.information( self, @@ -1265,9 +1268,56 @@ "<tr><td><b>Date</b></td><td>{0}</td></tr>" "<tr><td><b>Time</b></td><td>{1}</td></tr>" "</table>" - ).format(loacldate, localtime) + ).format(localdate, localtime) ) + @pyqtSlot() + def __showLocalAndDeviceTime(self): + """ + Private slot to show the local and device time side-by-side. + """ + localdatetime = time.localtime() + localdate = time.strftime('%Y-%m-%d', localdatetime) + localtime = time.strftime('%H:%M:%S', localdatetime) + + try: + deviceDateTimeString = self.__interface.getTime() + try: + devicedate, devicetime = ( + deviceDateTimeString.strip().split(None, 1) + ) + E5MessageBox.information( + self, + self.tr("Date and Time"), + self.tr("<table>" + "<tr><th></th><th>Local Date and Time</th>" + "<th>Device Date and Time</th></tr>" + "<tr><td><b>Date</b></td>" + "<td align='center'>{0}</td>" + "<td align='center'>{2}</td></tr>" + "<tr><td><b>Time</b></td>" + "<td align='center'>{1}</td>" + "<td align='center'>{3}</td></tr>" + "</table>" + ).format(localdate, localtime, + devicedate, devicetime) + ) + except ValueError: + E5MessageBox.information( + self, + self.tr("Date and Time"), + self.tr("<table>" + "<tr><th>Local Date and Time</th>" + "<th>Device Date and Time</th></tr>" + "<tr><td align='center'>{0} {1}</td>" + "<td align='center'>{2}</td></tr>" + "</table>" + ).format(localdate, localtime, + deviceDateTimeString.strip()) + ) + except Exception as exc: + self.__showError("getTime()", str(exc)) + def __showError(self, method, error): """ Private method to show some error message.