eric6/MicroPython/MicroPythonWidget.py

changeset 7325
f05a814aeddc
parent 7321
3642cc5df144
child 7328
e2d85ef3fadb
equal deleted inserted replaced
7324:8610ae96ad7b 7325:f05a814aeddc
1107 act = self.__superMenu.addAction( 1107 act = self.__superMenu.addAction(
1108 self.tr("Show Device Time"), self.__showDeviceTime) 1108 self.tr("Show Device Time"), self.__showDeviceTime)
1109 act.setEnabled(self.__connected) 1109 act.setEnabled(self.__connected)
1110 self.__superMenu.addAction( 1110 self.__superMenu.addAction(
1111 self.tr("Show Local Time"), self.__showLocalTime) 1111 self.tr("Show Local Time"), self.__showLocalTime)
1112 # TODO: add entry to show local and device time side-by-side 1112 if hasTime:
1113 act = self.__superMenu.addAction(
1114 self.tr("Show Time"), self.__showLocalAndDeviceTime)
1115 act.setEnabled(self.__connected)
1113 self.__superMenu.addSeparator() 1116 self.__superMenu.addSeparator()
1114 if not Globals.isWindowsPlatform(): 1117 if not Globals.isWindowsPlatform():
1115 available = self.__mpyCrossAvailable() 1118 available = self.__mpyCrossAvailable()
1116 act = self.__superMenu.addAction( 1119 act = self.__superMenu.addAction(
1117 self.tr("Compile Python File"), self.__compileFile2Mpy) 1120 self.tr("Compile Python File"), self.__compileFile2Mpy)
1253 def __showLocalTime(self): 1256 def __showLocalTime(self):
1254 """ 1257 """
1255 Private slot to show the local date and time. 1258 Private slot to show the local date and time.
1256 """ 1259 """
1257 localdatetime = time.localtime() 1260 localdatetime = time.localtime()
1258 loacldate = time.strftime('%Y-%m-%d', localdatetime) 1261 localdate = time.strftime('%Y-%m-%d', localdatetime)
1259 localtime = time.strftime('%H:%M:%S', localdatetime) 1262 localtime = time.strftime('%H:%M:%S', localdatetime)
1260 E5MessageBox.information( 1263 E5MessageBox.information(
1261 self, 1264 self,
1262 self.tr("Local Date and Time"), 1265 self.tr("Local Date and Time"),
1263 self.tr("<h3>Local Date and Time</h3>" 1266 self.tr("<h3>Local Date and Time</h3>"
1264 "<table>" 1267 "<table>"
1265 "<tr><td><b>Date</b></td><td>{0}</td></tr>" 1268 "<tr><td><b>Date</b></td><td>{0}</td></tr>"
1266 "<tr><td><b>Time</b></td><td>{1}</td></tr>" 1269 "<tr><td><b>Time</b></td><td>{1}</td></tr>"
1267 "</table>" 1270 "</table>"
1268 ).format(loacldate, localtime) 1271 ).format(localdate, localtime)
1269 ) 1272 )
1273
1274 @pyqtSlot()
1275 def __showLocalAndDeviceTime(self):
1276 """
1277 Private slot to show the local and device time side-by-side.
1278 """
1279 localdatetime = time.localtime()
1280 localdate = time.strftime('%Y-%m-%d', localdatetime)
1281 localtime = time.strftime('%H:%M:%S', localdatetime)
1282
1283 try:
1284 deviceDateTimeString = self.__interface.getTime()
1285 try:
1286 devicedate, devicetime = (
1287 deviceDateTimeString.strip().split(None, 1)
1288 )
1289 E5MessageBox.information(
1290 self,
1291 self.tr("Date and Time"),
1292 self.tr("<table>"
1293 "<tr><th></th><th>Local Date and Time</th>"
1294 "<th>Device Date and Time</th></tr>"
1295 "<tr><td><b>Date</b></td>"
1296 "<td align='center'>{0}</td>"
1297 "<td align='center'>{2}</td></tr>"
1298 "<tr><td><b>Time</b></td>"
1299 "<td align='center'>{1}</td>"
1300 "<td align='center'>{3}</td></tr>"
1301 "</table>"
1302 ).format(localdate, localtime,
1303 devicedate, devicetime)
1304 )
1305 except ValueError:
1306 E5MessageBox.information(
1307 self,
1308 self.tr("Date and Time"),
1309 self.tr("<table>"
1310 "<tr><th>Local Date and Time</th>"
1311 "<th>Device Date and Time</th></tr>"
1312 "<tr><td align='center'>{0} {1}</td>"
1313 "<td align='center'>{2}</td></tr>"
1314 "</table>"
1315 ).format(localdate, localtime,
1316 deviceDateTimeString.strip())
1317 )
1318 except Exception as exc:
1319 self.__showError("getTime()", str(exc))
1270 1320
1271 def __showError(self, method, error): 1321 def __showError(self, method, error):
1272 """ 1322 """
1273 Private method to show some error message. 1323 Private method to show some error message.
1274 1324

eric ide

mercurial