277 self.__interface = MicroPythonCommandsInterface(self) |
277 self.__interface = MicroPythonCommandsInterface(self) |
278 else: |
278 else: |
279 self.__interface = None |
279 self.__interface = None |
280 self.__device = None |
280 self.__device = None |
281 self.__connected = False |
281 self.__connected = False |
|
282 self.__linkConnected = False |
282 self.__setConnected(False) |
283 self.__setConnected(False) |
283 |
284 |
284 if not HAS_QTSERIALPORT: |
285 if not HAS_QTSERIALPORT: |
285 self.replEdit.setHtml( |
286 self.replEdit.setHtml( |
286 self.tr( |
287 self.tr( |
380 currentDevice, Qt.MatchFlag.MatchExactly |
381 currentDevice, Qt.MatchFlag.MatchExactly |
381 ) |
382 ) |
382 if index == -1: |
383 if index == -1: |
383 # entry is no longer present |
384 # entry is no longer present |
384 index = 0 |
385 index = 0 |
385 if self.__connected: |
386 if self.__linkConnected: |
386 # we are still connected, so disconnect |
387 # we are still connected, so disconnect |
387 self.on_connectButton_clicked() |
388 self.on_connectButton_clicked() |
388 |
389 |
389 self.on_deviceTypeComboBox_activated(index) |
390 self.on_deviceTypeComboBox_activated(index) |
390 self.deviceTypeComboBox.setCurrentIndex(index) |
391 self.deviceTypeComboBox.setCurrentIndex(index) |
522 @keyparam kwargs keyword arguments containg the enabled states (keys |
523 @keyparam kwargs keyword arguments containg the enabled states (keys |
523 are 'run', 'repl', 'files', 'chart', 'open', 'save' |
524 are 'run', 'repl', 'files', 'chart', 'open', 'save' |
524 @type dict |
525 @type dict |
525 """ |
526 """ |
526 if "open" in kwargs: |
527 if "open" in kwargs: |
527 self.openButton.setEnabled(kwargs["open"]) |
528 self.openButton.setEnabled(kwargs["open"] and self.__connected) |
528 if "save" in kwargs: |
529 if "save" in kwargs: |
529 self.saveButton.setEnabled(kwargs["save"]) |
530 self.saveButton.setEnabled(kwargs["save"] and self.__connected) |
530 if "run" in kwargs: |
531 if "run" in kwargs: |
531 self.runButton.setEnabled(kwargs["run"]) |
532 self.runButton.setEnabled(kwargs["run"] and self.__connected) |
532 if "repl" in kwargs: |
533 if "repl" in kwargs: |
533 self.replButton.setEnabled(kwargs["repl"]) |
534 self.replButton.setEnabled(kwargs["repl"] and self.__linkConnected) |
534 if "files" in kwargs: |
535 if "files" in kwargs: |
535 self.filesButton.setEnabled(kwargs["files"]) |
536 self.filesButton.setEnabled(kwargs["files"] and self.__connected) |
536 if "chart" in kwargs: |
537 if "chart" in kwargs: |
537 self.chartButton.setEnabled(kwargs["chart"] and HAS_QTCHART) |
538 self.chartButton.setEnabled( |
|
539 kwargs["chart"] and HAS_QTCHART and self.__connected |
|
540 ) |
538 |
541 |
539 @pyqtSlot(QPoint) |
542 @pyqtSlot(QPoint) |
540 def __showContextMenu(self, pos): |
543 def __showContextMenu(self, pos): |
541 """ |
544 """ |
542 Private slot to show the REPL context menu. |
545 Private slot to show the REPL context menu. |
552 copyKeys = QKeySequence("Ctrl+Shift+C") |
555 copyKeys = QKeySequence("Ctrl+Shift+C") |
553 pasteKeys = QKeySequence("Ctrl+Shift+V") |
556 pasteKeys = QKeySequence("Ctrl+Shift+V") |
554 selectAllKeys = QKeySequence("Ctrl+Shift+A") |
557 selectAllKeys = QKeySequence("Ctrl+Shift+A") |
555 |
558 |
556 menu = QMenu(self) |
559 menu = QMenu(self) |
557 act = menu.addAction( |
560 menu.addAction( |
558 EricPixmapCache.getIcon("editDelete"), self.tr("Clear"), self.__clear |
561 EricPixmapCache.getIcon("editDelete"), self.tr("Clear"), self.__clear |
559 ) |
562 ).setEnabled(bool(self.replEdit.toPlainText())) |
560 act.setEnabled(bool(self.replEdit.toPlainText())) |
|
561 menu.addSeparator() |
563 menu.addSeparator() |
562 act = menu.addAction( |
564 menu.addAction( |
563 EricPixmapCache.getIcon("editCopy"), |
565 EricPixmapCache.getIcon("editCopy"), |
564 self.tr("Copy"), |
566 self.tr("Copy"), |
565 copyKeys, |
567 copyKeys, |
566 self.replEdit.copy, |
568 self.replEdit.copy, |
567 ) |
569 ).setEnabled(self.replEdit.textCursor().hasSelection()) |
568 act.setEnabled(self.replEdit.textCursor().hasSelection()) |
570 menu.addAction( |
569 act = menu.addAction( |
|
570 EricPixmapCache.getIcon("editPaste"), |
571 EricPixmapCache.getIcon("editPaste"), |
571 self.tr("Paste"), |
572 self.tr("Paste"), |
572 pasteKeys, |
573 pasteKeys, |
573 self.__paste, |
574 self.__paste, |
574 ) |
575 ).setEnabled(self.replEdit.canPaste() and self.__connected) |
575 act.setEnabled(self.replEdit.canPaste() and self.__interface.isConnected()) |
|
576 menu.addSeparator() |
576 menu.addSeparator() |
577 act = menu.addAction( |
577 menu.addAction( |
578 EricPixmapCache.getIcon("editSelectAll"), |
578 EricPixmapCache.getIcon("editSelectAll"), |
579 self.tr("Select All"), |
579 self.tr("Select All"), |
580 selectAllKeys, |
580 selectAllKeys, |
581 self.replEdit.selectAll, |
581 self.replEdit.selectAll, |
582 ) |
582 ).setEnabled(bool(self.replEdit.toPlainText())) |
583 act.setEnabled(bool(self.replEdit.toPlainText())) |
|
584 |
583 |
585 menu.exec(self.replEdit.mapToGlobal(pos)) |
584 menu.exec(self.replEdit.mapToGlobal(pos)) |
586 |
585 |
587 def __setConnected(self, connected): |
586 def __setConnected(self, connected): |
588 """ |
587 """ |
590 |
589 |
591 @param connected connection state |
590 @param connected connection state |
592 @type bool |
591 @type bool |
593 """ |
592 """ |
594 self.__connected = connected |
593 self.__connected = connected |
595 |
594 self.__linkConnected = self.__interface.isConnected() |
596 self.deviceConnectedLed.setOn(connected) |
595 |
|
596 self.deviceConnectedLed.setOn(self.__linkConnected) |
597 if self.__fileManagerWidget: |
597 if self.__fileManagerWidget: |
598 self.__fileManagerWidget.deviceConnectedLed.setOn(connected) |
598 self.__fileManagerWidget.deviceConnectedLed.setOn(connected) |
599 |
599 |
600 self.deviceTypeComboBox.setEnabled(not connected) |
600 self.deviceTypeComboBox.setEnabled(not self.__linkConnected) |
601 |
601 |
602 if connected: |
602 if self.__linkConnected: |
603 self.connectButton.setIcon(EricPixmapCache.getIcon("linkDisconnect")) |
603 self.connectButton.setIcon(EricPixmapCache.getIcon("linkDisconnect")) |
604 self.connectButton.setToolTip( |
604 self.connectButton.setToolTip( |
605 self.tr("Press to disconnect the current device") |
605 self.tr("Press to disconnect the current device") |
606 ) |
606 ) |
607 else: |
607 else: |
610 self.tr("Press to connect the selected device") |
610 self.tr("Press to connect the selected device") |
611 ) |
611 ) |
612 |
612 |
613 def isConnected(self): |
613 def isConnected(self): |
614 """ |
614 """ |
615 Public method to get the connection state. |
615 Public method to get the MicroPython device connection state. |
616 |
616 |
617 @return connection state |
617 @return connection state |
618 @rtype bool |
618 @rtype bool |
619 """ |
619 """ |
620 return self.__connected |
620 return self.__connected |
|
621 |
|
622 def isLinkConnected(self): |
|
623 """ |
|
624 Public method to get the link connection state. |
|
625 |
|
626 @return connection state |
|
627 @rtype bool |
|
628 """ |
|
629 return self.__linkConnected |
621 |
630 |
622 def __showNoDeviceMessage(self): |
631 def __showNoDeviceMessage(self): |
623 """ |
632 """ |
624 Private method to show a message dialog indicating a missing device. |
633 Private method to show a message dialog indicating a missing device. |
625 """ |
634 """ |
687 def on_connectButton_clicked(self): |
696 def on_connectButton_clicked(self): |
688 """ |
697 """ |
689 Private slot to connect to the selected device or disconnect from the |
698 Private slot to connect to the selected device or disconnect from the |
690 currently connected device. |
699 currently connected device. |
691 """ |
700 """ |
692 if self.__connected: |
701 if self.__linkConnected: |
693 with EricOverrideCursor(): |
702 with EricOverrideCursor(): |
694 self.__disconnectFromDevice() |
703 self.__disconnectFromDevice() |
695 |
704 |
696 if self.replButton.isChecked(): |
705 if self.replButton.isChecked(): |
697 self.on_replButton_clicked(False) |
706 self.on_replButton_clicked(False) |
1107 MicroPythonDevices.getDeviceIcon(deviceType, False) |
1116 MicroPythonDevices.getDeviceIcon(deviceType, False) |
1108 ) |
1117 ) |
1109 self.__device = MicroPythonDevices.getDevice( |
1118 self.__device = MicroPythonDevices.getDevice( |
1110 deviceType, self, vid, pid |
1119 deviceType, self, vid, pid |
1111 ) |
1120 ) |
1112 self.__device.setButtons() |
|
1113 |
1121 |
1114 self.__lastPort = port |
1122 self.__lastPort = port |
1115 self.__lastDeviceType = deviceType |
1123 self.__lastDeviceType = deviceType |
1116 else: |
1124 else: |
1117 return |
1125 return |
1118 |
1126 |
1119 if self.__interface.connectToDevice(port): |
1127 if self.__interface.connectToDevice(port): |
1120 self.__setConnected(True) |
1128 deviceResponding = self.__interface.probeDevice() |
1121 |
1129 self.__setConnected(deviceResponding) |
1122 if ( |
1130 if deviceResponding: |
1123 Preferences.getMicroPython("SyncTimeAfterConnect") |
1131 if ( |
1124 and self.__device.hasTimeCommands() |
1132 Preferences.getMicroPython("SyncTimeAfterConnect") |
1125 ): |
1133 and self.__device.hasTimeCommands() |
1126 self.__synchronizeTime(quiet=True) |
1134 ): |
|
1135 self.__synchronizeTime(quiet=True) |
|
1136 else: |
|
1137 with EricOverridenCursor(): |
|
1138 EricMessageBox.warning( |
|
1139 self, |
|
1140 self.tr("Serial Device Connect"), |
|
1141 self.tr( |
|
1142 """<p>The device at serial port <b>{0}</b> does not""" |
|
1143 """ respond. It may not have a MicroPython firmware""" |
|
1144 """ flashed.</p>""" |
|
1145 ).format(port), |
|
1146 ) |
1127 else: |
1147 else: |
1128 with EricOverridenCursor(): |
1148 with EricOverridenCursor(): |
1129 EricMessageBox.warning( |
1149 EricMessageBox.warning( |
1130 self, |
1150 self, |
1131 self.tr("Serial Device Connect"), |
1151 self.tr("Serial Device Connect"), |
1132 self.tr( |
1152 self.tr( |
1133 """<p>Cannot connect to device at serial""" |
1153 """<p>Cannot connect to device at serial""" |
1134 """ port <b>{0}</b>.</p>""" |
1154 """ port <b>{0}</b>.</p>""" |
1135 ).format(port), |
1155 ).format(port), |
1136 ) |
1156 ) |
|
1157 |
|
1158 self.__device.setButtons() |
1137 |
1159 |
1138 def __disconnectFromDevice(self): |
1160 def __disconnectFromDevice(self): |
1139 """ |
1161 """ |
1140 Private method to disconnect from the device. |
1162 Private method to disconnect from the device. |
1141 """ |
1163 """ |
1935 Private slot to show a list of builtin modules. |
1957 Private slot to show a list of builtin modules. |
1936 """ |
1958 """ |
1937 from .ShowModulesDialog import ShowModulesDialog |
1959 from .ShowModulesDialog import ShowModulesDialog |
1938 |
1960 |
1939 if self.__connected: |
1961 if self.__connected: |
1940 moduleNames = self.__interface.getModules() |
1962 try: |
1941 dlg = ShowModulesDialog( |
1963 moduleNames = self.__interface.getModules() |
1942 moduleNames, |
1964 dlg = ShowModulesDialog( |
1943 info=self.tr("Plus any modules on the filesystem."), |
1965 moduleNames, |
1944 parent=self, |
1966 info=self.tr("Plus any modules on the filesystem."), |
1945 ) |
1967 parent=self, |
1946 dlg.show() |
1968 ) |
|
1969 dlg.show() |
|
1970 except Exception as exc: |
|
1971 self.__showError("getModules()", str(exc)) |