498 ) |
506 ) |
499 |
507 |
500 boardName = self.deviceTypeComboBox.itemData(index, self.DeviceBoardRole) |
508 boardName = self.deviceTypeComboBox.itemData(index, self.DeviceBoardRole) |
501 vid = self.deviceTypeComboBox.itemData(index, self.DeviceVidRole) |
509 vid = self.deviceTypeComboBox.itemData(index, self.DeviceVidRole) |
502 pid = self.deviceTypeComboBox.itemData(index, self.DevicePidRole) |
510 pid = self.deviceTypeComboBox.itemData(index, self.DevicePidRole) |
|
511 serNo = self.deviceTypeComboBox.itemData(index, self.DeviceSerNoRole) |
503 |
512 |
504 if deviceType or (pid is not None and pid is not None): |
513 if deviceType or (pid is not None and pid is not None): |
505 self.__device = MicroPythonDevices.getDevice( |
514 self.__device = MicroPythonDevices.getDevice( |
506 deviceType, self, vid, pid, boardName |
515 deviceType, self, vid, pid, boardName=boardName, serialNumber=serNo |
507 ) |
516 ) |
508 self.__device.setButtons() |
517 self.__device.setButtons() |
509 |
518 |
510 self.connectButton.setEnabled(bool(deviceType)) |
519 self.connectButton.setEnabled(bool(deviceType)) |
|
520 else: |
|
521 self.__device = None |
511 |
522 |
512 @pyqtSlot() |
523 @pyqtSlot() |
513 def on_checkButton_clicked(self): |
524 def on_checkButton_clicked(self): |
514 """ |
525 """ |
515 Private slot to check for connected devices. |
526 Private slot to check for connected devices. |
907 ) |
921 ) |
908 tc.removeSelectedText() |
922 tc.removeSelectedText() |
909 self.replEdit.setTextCursor(tc) |
923 self.replEdit.setTextCursor(tc) |
910 elif action == "m": |
924 elif action == "m": |
911 self.__setCharFormat(match.group(0)[:-1].split(";"), tc) |
925 self.__setCharFormat(match.group(0)[:-1].split(";"), tc) |
|
926 elif ( |
|
927 len(data) > index + 1 |
|
928 and data[index] == 27 |
|
929 and data[index + 1 : index + 4] == b"]0;" |
|
930 ): |
|
931 if b"\x1b\\" in data[index + 4 :]: |
|
932 # 'set window title' command detected: <Esc>]0;...<Esc>\ |
|
933 # __IGNORE_WARNING_M891__ |
|
934 titleData = data[index + 4 :].split(b"\x1b\\")[0] |
|
935 title = titleData.decode() |
|
936 index += len(titleData) + 5 # one more is done at the end |
|
937 tc.deleteChar() |
|
938 self.replEdit.setTextCursor(tc) |
|
939 self.replEdit.insertPlainText(title) |
|
940 else: |
|
941 # data is incomplete; buffer and stop processing |
|
942 self.__replBuffer = data[index:] |
|
943 return |
912 else: |
944 else: |
913 tc.deleteChar() |
945 tc.deleteChar() |
914 self.replEdit.setTextCursor(tc) |
946 self.replEdit.setTextCursor(tc) |
915 self.replEdit.insertPlainText(chr(data[index])) |
947 self.replEdit.insertPlainText(chr(data[index])) |
916 |
948 |
917 index += 1 |
949 index += 1 |
918 |
950 |
919 self.replEdit.ensureCursorVisible() |
951 self.replEdit.ensureCursorVisible() |
|
952 self.__replBuffer = b"" |
920 |
953 |
921 def __setCharFormat(self, formatCodes, textCursor): |
954 def __setCharFormat(self, formatCodes, textCursor): |
922 """ |
955 """ |
923 Private method setting the current text format of the REPL pane based |
956 Private method setting the current text format of the REPL pane based |
924 on the passed ANSI codes. |
957 on the passed ANSI codes. |
1421 downloadMenu = None |
1456 downloadMenu = None |
1422 |
1457 |
1423 # populate the super menu |
1458 # populate the super menu |
1424 hasTime = self.__device.hasTimeCommands() if self.__device else False |
1459 hasTime = self.__device.hasTimeCommands() if self.__device else False |
1425 |
1460 |
1426 act = self.__superMenu.addAction( |
1461 self.__superMenu.addAction( |
1427 self.tr("Show Version"), self.__showDeviceVersion |
1462 self.tr("Show Version"), self.__showDeviceVersion |
1428 ) |
1463 ).setEnabled(self.__connected) |
1429 act.setEnabled(self.__connected) |
1464 self.__superMenu.addAction( |
1430 act = self.__superMenu.addAction( |
|
1431 self.tr("Show Implementation"), self.__showImplementation |
1465 self.tr("Show Implementation"), self.__showImplementation |
1432 ) |
1466 ).setEnabled(self.__connected) |
1433 act.setEnabled(self.__connected) |
1467 self.__superMenu.addAction( |
1434 act = self.__superMenu.addAction( |
|
1435 self.tr("Show Board Data"), self.__showBoardInformation |
1468 self.tr("Show Board Data"), self.__showBoardInformation |
1436 ) |
1469 ).setEnabled(self.__connected) |
1437 act.setEnabled(self.__connected) |
|
1438 self.__superMenu.addSeparator() |
1470 self.__superMenu.addSeparator() |
1439 if hasTime: |
1471 if hasTime: |
1440 act = self.__superMenu.addAction( |
1472 self.__superMenu.addAction( |
1441 self.tr("Synchronize Time"), self.__synchronizeTime |
1473 self.tr("Synchronize Time"), self.__synchronizeTime |
1442 ) |
1474 ).setEnabled(self.__connected) |
1443 act.setEnabled(self.__connected) |
1475 self.__superMenu.addAction( |
1444 act = self.__superMenu.addAction( |
|
1445 self.tr("Show Device Time"), self.__showDeviceTime |
1476 self.tr("Show Device Time"), self.__showDeviceTime |
1446 ) |
1477 ).setEnabled(self.__connected) |
1447 act.setEnabled(self.__connected) |
|
1448 self.__superMenu.addAction(self.tr("Show Local Time"), self.__showLocalTime) |
1478 self.__superMenu.addAction(self.tr("Show Local Time"), self.__showLocalTime) |
1449 if hasTime: |
1479 if hasTime: |
1450 act = self.__superMenu.addAction( |
1480 self.__superMenu.addAction( |
1451 self.tr("Show Time"), self.__showLocalAndDeviceTime |
1481 self.tr("Show Time"), self.__showLocalAndDeviceTime |
1452 ) |
1482 ).setEnabled(self.__connected) |
1453 act.setEnabled(self.__connected) |
|
1454 self.__superMenu.addSeparator() |
1483 self.__superMenu.addSeparator() |
1455 self.__superMenu.addAction( |
1484 self.__superMenu.addAction( |
1456 self.tr("Show Builtin Modules"), self.__showBuiltinModules |
1485 self.tr("Show Builtin Modules"), self.__showBuiltinModules |
1457 ).setEnabled(self.__connected) |
1486 ).setEnabled(self.__connected) |
1458 self.__superMenu.addSeparator() |
1487 self.__superMenu.addSeparator() |
1459 if not OSUtilities.isWindowsPlatform(): |
1488 if not OSUtilities.isWindowsPlatform(): |
1460 available = self.__mpyCrossAvailable() |
1489 available = self.__mpyCrossAvailable() |
1461 act = self.__superMenu.addAction( |
1490 self.__superMenu.addAction( |
1462 self.tr("Compile Python File"), self.__compileFile2Mpy |
1491 self.tr("Compile Python File"), self.__compileFile2Mpy |
1463 ) |
1492 ).setEnabled(available) |
1464 act.setEnabled(available) |
1493 aw = ericApp().getObject("ViewManager").activeWindow() |
1465 act = self.__superMenu.addAction( |
1494 self.__superMenu.addAction( |
1466 self.tr("Compile Current Editor"), self.__compileEditor2Mpy |
1495 self.tr("Compile Current Editor"), self.__compileEditor2Mpy |
1467 ) |
1496 ).setEnabled(available and bool(aw)) |
1468 aw = ericApp().getObject("ViewManager").activeWindow() |
|
1469 act.setEnabled(available and bool(aw)) |
|
1470 self.__superMenu.addSeparator() |
1497 self.__superMenu.addSeparator() |
1471 if self.__device: |
1498 if self.__device: |
1472 self.__device.addDeviceMenuEntries(self.__superMenu) |
1499 self.__device.addDeviceMenuEntries(self.__superMenu) |
1473 self.__superMenu.addSeparator() |
1500 self.__superMenu.addSeparator() |
1474 if downloadMenu is None: |
1501 if downloadMenu is None: |
1475 # generic download action |
1502 # generic download action |
1476 act = self.__superMenu.addAction( |
1503 self.__superMenu.addAction( |
1477 self.tr("Download Firmware"), self.__downloadFirmware |
1504 self.tr("Download Firmware"), self.__downloadFirmware |
1478 ) |
1505 ).setEnabled(self.__device.hasFirmwareUrl()) |
1479 act.setEnabled(self.__device.hasFirmwareUrl()) |
|
1480 else: |
1506 else: |
1481 # download sub-menu |
1507 # download sub-menu |
1482 self.__superMenu.addMenu(downloadMenu) |
1508 self.__superMenu.addMenu(downloadMenu) |
1483 self.__superMenu.addSeparator() |
1509 self.__superMenu.addSeparator() |
1484 act = self.__superMenu.addAction( |
1510 self.__superMenu.addAction( |
1485 self.tr("Show Documentation"), self.__showDocumentation |
1511 self.tr("Show Documentation"), self.__showDocumentation |
1486 ) |
1512 ).setEnabled(self.__device.hasDocumentationUrl()) |
1487 act.setEnabled(self.__device.hasDocumentationUrl()) |
|
1488 self.__superMenu.addSeparator() |
1513 self.__superMenu.addSeparator() |
1489 if self.__device is not None and not self.__device.hasFlashMenuEntry(): |
1514 ##if self.__device is not None and not self.__device.hasFlashMenuEntry(): |
|
1515 if bool(UF2FlashDialog.getFoundDevices()): |
1490 self.__superMenu.addAction(self.tr("Flash UF2 Device"), self.__flashUF2) |
1516 self.__superMenu.addAction(self.tr("Flash UF2 Device"), self.__flashUF2) |
1491 self.__superMenu.addSeparator() |
1517 self.__superMenu.addSeparator() |
1492 self.__superMenu.addAction( |
1518 self.__superMenu.addAction( |
1493 self.tr("Manage Unknown Devices"), self.__manageUnknownDevices |
1519 self.tr("Manage Unknown Devices"), self.__manageUnknownDevices |
1494 ) |
1520 ) |
1501 @pyqtSlot() |
1527 @pyqtSlot() |
1502 def __showDeviceVersion(self): |
1528 def __showDeviceVersion(self): |
1503 """ |
1529 """ |
1504 Private slot to show some version info about MicroPython of the device. |
1530 Private slot to show some version info about MicroPython of the device. |
1505 """ |
1531 """ |
1506 try: |
1532 data = self.__device.getDeviceData() |
1507 versionInfo = self.__interface.version() |
1533 if data: |
1508 if versionInfo: |
1534 msg = self.tr("<h3>Device Version Information</h3>") |
1509 msg = self.tr("<h3>Device Version Information</h3>") |
1535 msg += "<table>" |
1510 msg += "<table>" |
1536 for key in ("sysname", "nodename", "release", "version", "machine"): |
1511 for key, value in versionInfo.items(): |
1537 msg += "<tr><td><b>{0}</b></td><td>{1}</td></tr>".format( |
1512 msg += "<tr><td><b>{0}</b></td><td>{1}</td></tr>".format( |
1538 key.capitalize(), data[key] |
1513 key.capitalize(), value |
1539 ) |
1514 ) |
1540 msg += "</table>" |
1515 msg += "</table>" |
|
1516 else: |
|
1517 msg = self.tr("No version information available.") |
|
1518 |
|
1519 EricMessageBox.information(self, self.tr("Device Version Information"), msg) |
1541 EricMessageBox.information(self, self.tr("Device Version Information"), msg) |
1520 except Exception as exc: |
1542 else: |
1521 self.__showError("version()", str(exc)) |
1543 EricMessageBox.critical( |
|
1544 self, |
|
1545 self.tr("Device Version Information"), |
|
1546 self.tr("No version information available."), |
|
1547 ) |
1522 |
1548 |
1523 @pyqtSlot() |
1549 @pyqtSlot() |
1524 def __showImplementation(self): |
1550 def __showImplementation(self): |
1525 """ |
1551 """ |
1526 Private slot to show some implementation related information. |
1552 Private slot to show some implementation related information. |
1527 """ |
1553 """ |
1528 try: |
1554 data = self.__device.getDeviceData() |
1529 impInfo = self.__interface.getImplementation() |
1555 if data: |
1530 if impInfo["name"] == "micropython": |
1556 if data["mpy_name"] == "micropython": |
1531 name = "MicroPython" |
1557 name = "MicroPython" |
1532 elif impInfo["name"] == "circuitpython": |
1558 elif data["mpy_name"] == "circuitpython": |
1533 name = "CircuitPython" |
1559 name = "CircuitPython" |
1534 elif impInfo["name"] == "unknown": |
1560 elif data["mpy_name"] == "unknown": |
1535 name = self.tr("unknown") |
1561 name = self.tr("unknown") |
1536 else: |
1562 else: |
1537 name = impInfo["name"] |
1563 name = data["mpy_name"] |
1538 version = ( |
1564 version = ( |
1539 self.tr("unknown") |
1565 self.tr("unknown") |
1540 if impInfo["version"] == "unknown" |
1566 if data["mpy_version"] == "unknown" |
1541 else impInfo["version"] |
1567 else data["mpy_version"] |
1542 ) |
1568 ) |
1543 variant = ( |
1569 variant = ( |
1544 self.tr(" ({0})").format(impInfo["variant"]) |
1570 self.tr(" ({0})").format(data["mpy_variant"]) |
1545 if impInfo["variant"] |
1571 if data["mpy_variant"] |
1546 else "" |
1572 else "" |
1547 ) |
1573 ) |
1548 |
1574 |
1549 EricMessageBox.information( |
1575 EricMessageBox.information( |
1550 self, |
1576 self, |