eric6/MicroPython/MicroPythonReplWidget.py

branch
micropython
changeset 7133
7aa4832b3730
parent 7130
6014d37d9683
equal deleted inserted replaced
7132:c4682cfcd160 7133:7aa4832b3730
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import re 12 import re
13 import time
13 14
14 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QPoint, QEvent 15 from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QPoint, QEvent
15 from PyQt5.QtGui import QColor, QKeySequence, QTextCursor, QBrush 16 from PyQt5.QtGui import QColor, QKeySequence, QTextCursor, QBrush
16 from PyQt5.QtWidgets import ( 17 from PyQt5.QtWidgets import (
17 QWidget, QMenu, QApplication, QHBoxLayout, QSpacerItem, QSizePolicy, 18 QWidget, QMenu, QApplication, QHBoxLayout, QSpacerItem, QSizePolicy,
134 17: QBrush(QColor(255, 255, 255)), 135 17: QBrush(QColor(255, 255, 255)),
135 }, 136 },
136 } 137 }
137 138
138 139
140 # TODO: add config option to synchronize the device time upon connect
139 class MicroPythonReplWidget(QWidget, Ui_MicroPythonReplWidget): 141 class MicroPythonReplWidget(QWidget, Ui_MicroPythonReplWidget):
140 """ 142 """
141 Class implementing the MicroPython REPL widget. 143 Class implementing the MicroPython REPL widget.
142 144
143 @signal dataReceived(data) emitted to send data received via the serial 145 @signal dataReceived(data) emitted to send data received via the serial
1040 return 1042 return
1041 1043
1042 if not self.__interface.isConnected(): 1044 if not self.__interface.isConnected():
1043 self.__connectToDevice() 1045 self.__connectToDevice()
1044 self.__fileManagerWidget = MicroPythonFileManagerWidget( 1046 self.__fileManagerWidget = MicroPythonFileManagerWidget(
1045 self.__interface, self.__device.supportsLocalFileAccess, 1047 self.__interface, self.__device.supportsLocalFileAccess(),
1046 self) 1048 self)
1047 1049
1048 self.__ui.addSideWidget(self.__ui.BottomSide, 1050 self.__ui.addSideWidget(self.__ui.BottomSide,
1049 self.__fileManagerWidget, 1051 self.__fileManagerWidget,
1050 UI.PixmapCache.getIcon("filemanager"), 1052 UI.PixmapCache.getIcon("filemanager"),
1081 if self.__device: 1083 if self.__device:
1082 hasTime = self.__device.hasTimeCommands() 1084 hasTime = self.__device.hasTimeCommands()
1083 else: 1085 else:
1084 hasTime = False 1086 hasTime = False
1085 1087
1088 # TODO: add menu entry to cross-compile a .py file (using mpy-cross)
1086 act = self.__superMenu.addAction( 1089 act = self.__superMenu.addAction(
1087 self.tr("Show Version"), self.__showDeviceVersion) 1090 self.tr("Show Version"), self.__showDeviceVersion)
1088 act.setEnabled(self.__connected) 1091 act.setEnabled(self.__connected)
1089 act = self.__superMenu.addAction( 1092 act = self.__superMenu.addAction(
1090 self.tr("Show Implementation"), self.__showImplementation) 1093 self.tr("Show Implementation"), self.__showImplementation)
1093 if hasTime: 1096 if hasTime:
1094 act = self.__superMenu.addAction( 1097 act = self.__superMenu.addAction(
1095 self.tr("Synchronize Time"), self.__synchronizeTime) 1098 self.tr("Synchronize Time"), self.__synchronizeTime)
1096 act.setEnabled(self.__connected) 1099 act.setEnabled(self.__connected)
1097 act = self.__superMenu.addAction( 1100 act = self.__superMenu.addAction(
1098 self.tr("Show Time"), self.__showDeviceTime) 1101 self.tr("Show Device Time"), self.__showDeviceTime)
1099 act.setEnabled(self.__connected) 1102 act.setEnabled(self.__connected)
1103 self.__superMenu.addAction(
1104 self.tr("Show Local Time"), self.__showLocalTime)
1100 self.__superMenu.addSeparator() 1105 self.__superMenu.addSeparator()
1101 if self.__device: 1106 if self.__device:
1102 self.__device.addDeviceMenuEntries(self.__superMenu) 1107 self.__device.addDeviceMenuEntries(self.__superMenu)
1103 1108
1104 @pyqtSlot() 1109 @pyqtSlot()
1156 ).format(name, version) 1161 ).format(name, version)
1157 ) 1162 )
1158 except Exception as exc: 1163 except Exception as exc:
1159 self.__showError("getImplementation()", str(exc)) 1164 self.__showError("getImplementation()", str(exc))
1160 1165
1166 # TODO: show device time after sync
1161 @pyqtSlot() 1167 @pyqtSlot()
1162 def __synchronizeTime(self): 1168 def __synchronizeTime(self):
1163 """ 1169 """
1164 Private slot to set the time of the connected device to the local 1170 Private slot to set the time of the connected device to the local
1165 computer's time. 1171 computer's time.
1202 self.tr("Device Date and Time"), 1208 self.tr("Device Date and Time"),
1203 msg) 1209 msg)
1204 except Exception as exc: 1210 except Exception as exc:
1205 self.__showError("getTime()", str(exc)) 1211 self.__showError("getTime()", str(exc))
1206 1212
1213 @pyqtSlot()
1214 def __showLocalTime(self):
1215 """
1216 Private slot to show the local date and time.
1217 """
1218 localdatetime = time.localtime()
1219 loacldate = time.strftime('%Y-%m-%d', localdatetime)
1220 localtime = time.strftime('%H:%M:%S', localdatetime)
1221 E5MessageBox.information(
1222 self,
1223 self.tr("Local Date and Time"),
1224 self.tr("<h3>Local Date and Time</h3>"
1225 "<table>"
1226 "<tr><td><b>Date</b></td><td>{0}</td></tr>"
1227 "<tr><td><b>Time</b></td><td>{1}</td></tr>"
1228 "</table>"
1229 ).format(loacldate, localtime)
1230 )
1231
1207 def __showError(self, method, error): 1232 def __showError(self, method, error):
1208 """ 1233 """
1209 Private method to show some error message. 1234 Private method to show some error message.
1210 1235
1211 @param method name of the method the error occured in 1236 @param method name of the method the error occured in

eric ide

mercurial