135 17: QBrush(QColor(255, 255, 255)), |
135 17: QBrush(QColor(255, 255, 255)), |
136 }, |
136 }, |
137 } |
137 } |
138 |
138 |
139 |
139 |
140 # TODO: add config option to synchronize the device time upon connect |
|
141 |
|
142 class MicroPythonWidget(QWidget, Ui_MicroPythonWidget): |
140 class MicroPythonWidget(QWidget, Ui_MicroPythonWidget): |
143 """ |
141 """ |
144 Class implementing the MicroPython REPL widget. |
142 Class implementing the MicroPython REPL widget. |
145 |
143 |
146 @signal dataReceived(data) emitted to send data received via the serial |
144 @signal dataReceived(data) emitted to send data received via the serial |
215 self.__fileManagerWidget = None |
213 self.__fileManagerWidget = None |
216 |
214 |
217 self.__interface = MicroPythonCommandsInterface(self) |
215 self.__interface = MicroPythonCommandsInterface(self) |
218 self.__device = None |
216 self.__device = None |
219 self.__connected = False |
217 self.__connected = False |
220 self.setConnected(False) |
218 self.__setConnected(False) |
221 |
219 |
222 if not HAS_QTSERIALPORT: |
220 if not HAS_QTSERIALPORT: |
223 self.replEdit.setHtml(self.tr( |
221 self.replEdit.setHtml(self.tr( |
224 "<h3>The QtSerialPort package is not available.<br/>" |
222 "<h3>The QtSerialPort package is not available.<br/>" |
225 "MicroPython support is deactivated.</h3>")) |
223 "MicroPython support is deactivated.</h3>")) |
389 menu.addAction(self.tr("Copy"), self.replEdit.copy, copyKeys) |
387 menu.addAction(self.tr("Copy"), self.replEdit.copy, copyKeys) |
390 menu.addAction(self.tr("Paste"), self.__paste, pasteKeys) |
388 menu.addAction(self.tr("Paste"), self.__paste, pasteKeys) |
391 menu.addSeparator() |
389 menu.addSeparator() |
392 menu.exec_(self.replEdit.mapToGlobal(pos)) |
390 menu.exec_(self.replEdit.mapToGlobal(pos)) |
393 |
391 |
394 def setConnected(self, connected): |
392 def __setConnected(self, connected): |
395 """ |
393 """ |
396 Public method to set the connection status LED. |
394 Private method to set the connection status LED. |
397 |
395 |
398 @param connected connection state |
396 @param connected connection state |
399 @type bool |
397 @type bool |
400 """ |
398 """ |
401 self.__connected = connected |
399 self.__connected = connected |
839 """ |
837 """ |
840 Private method to connect to the selected device. |
838 Private method to connect to the selected device. |
841 """ |
839 """ |
842 port = self.getCurrentPort() |
840 port = self.getCurrentPort() |
843 if self.__interface.connectToDevice(port): |
841 if self.__interface.connectToDevice(port): |
844 self.setConnected(True) |
842 self.__setConnected(True) |
|
843 |
|
844 if Preferences.getMicroPython("SyncTimeAfterConnect"): |
|
845 self.__synchronizeTime(quiet=True) |
845 else: |
846 else: |
846 E5MessageBox.warning( |
847 E5MessageBox.warning( |
847 self, |
848 self, |
848 self.tr("Serial Device Connect"), |
849 self.tr("Serial Device Connect"), |
849 self.tr("""<p>Cannot connect to device at serial port""" |
850 self.tr("""<p>Cannot connect to device at serial port""" |
852 def __disconnectFromDevice(self): |
853 def __disconnectFromDevice(self): |
853 """ |
854 """ |
854 Private method to disconnect from the device. |
855 Private method to disconnect from the device. |
855 """ |
856 """ |
856 self.__interface.disconnectFromDevice() |
857 self.__interface.disconnectFromDevice() |
857 self.setConnected(False) |
858 self.__setConnected(False) |
858 |
859 |
859 @pyqtSlot() |
860 @pyqtSlot() |
860 def on_runButton_clicked(self): |
861 def on_runButton_clicked(self): |
861 """ |
862 """ |
862 Private slot to execute the script of the active editor on the |
863 Private slot to execute the script of the active editor on the |
1162 ).format(name, version) |
1163 ).format(name, version) |
1163 ) |
1164 ) |
1164 except Exception as exc: |
1165 except Exception as exc: |
1165 self.__showError("getImplementation()", str(exc)) |
1166 self.__showError("getImplementation()", str(exc)) |
1166 |
1167 |
1167 # TODO: show device time after sync |
|
1168 @pyqtSlot() |
1168 @pyqtSlot() |
1169 def __synchronizeTime(self): |
1169 def __synchronizeTime(self, quiet=False): |
1170 """ |
1170 """ |
1171 Private slot to set the time of the connected device to the local |
1171 Private slot to set the time of the connected device to the local |
1172 computer's time. |
1172 computer's time. |
|
1173 |
|
1174 @param quiet flag indicating to not show a message |
|
1175 @type bool |
1173 """ |
1176 """ |
1174 try: |
1177 try: |
1175 self.__interface.syncTime() |
1178 self.__interface.syncTime() |
1176 |
1179 |
1177 E5MessageBox.information( |
1180 if not quiet: |
1178 self, |
1181 E5MessageBox.information( |
1179 self.tr("Synchronize Time"), |
1182 self, |
1180 self.tr("The time of the connected device was synchronized" |
1183 self.tr("Synchronize Time"), |
1181 " with the local time.")) |
1184 self.tr("<p>The time of the connected device was" |
|
1185 " synchronized with the local time.</p>") |
|
1186 + self.__getDeviceTime() |
|
1187 ) |
1182 except Exception as exc: |
1188 except Exception as exc: |
1183 self.__showError("syncTime()", str(exc)) |
1189 self.__showError("syncTime()", str(exc)) |
1184 |
1190 |
1185 @pyqtSlot() |
1191 def __getDeviceTime(self): |
1186 def __showDeviceTime(self): |
1192 """ |
1187 """ |
1193 Private method to get a string containing the date and time of the |
1188 Private slot to show the date and time of the connected device. |
1194 connected device. |
|
1195 |
|
1196 @return date and time of the connected device |
|
1197 @rtype str |
1189 """ |
1198 """ |
1190 try: |
1199 try: |
1191 dateTimeString = self.__interface.getTime() |
1200 dateTimeString = self.__interface.getTime() |
1192 try: |
1201 try: |
1193 date, time = dateTimeString.strip().split(None, 1) |
1202 date, time = dateTimeString.strip().split(None, 1) |
1201 except ValueError: |
1210 except ValueError: |
1202 msg = self.tr( |
1211 msg = self.tr( |
1203 "<h3>Device Date and Time</h3>" |
1212 "<h3>Device Date and Time</h3>" |
1204 "<p>{0}</p>" |
1213 "<p>{0}</p>" |
1205 ).format(dateTimeString.strip()) |
1214 ).format(dateTimeString.strip()) |
1206 |
1215 return msg |
1207 E5MessageBox.information( |
|
1208 self, |
|
1209 self.tr("Device Date and Time"), |
|
1210 msg) |
|
1211 except Exception as exc: |
1216 except Exception as exc: |
1212 self.__showError("getTime()", str(exc)) |
1217 self.__showError("getTime()", str(exc)) |
|
1218 return "" |
|
1219 |
|
1220 @pyqtSlot() |
|
1221 def __showDeviceTime(self): |
|
1222 """ |
|
1223 Private slot to show the date and time of the connected device. |
|
1224 """ |
|
1225 msg = self.__getDeviceTime() |
|
1226 E5MessageBox.information( |
|
1227 self, |
|
1228 self.tr("Device Date and Time"), |
|
1229 msg) |
1213 |
1230 |
1214 @pyqtSlot() |
1231 @pyqtSlot() |
1215 def __showLocalTime(self): |
1232 def __showLocalTime(self): |
1216 """ |
1233 """ |
1217 Private slot to show the local date and time. |
1234 Private slot to show the local date and time. |