32 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor |
34 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor, EricOverridenCursor |
33 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
35 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
34 from eric7.EricWidgets.EricApplication import ericApp |
36 from eric7.EricWidgets.EricApplication import ericApp |
35 from eric7.EricWidgets.EricListSelectionDialog import EricListSelectionDialog |
37 from eric7.EricWidgets.EricListSelectionDialog import EricListSelectionDialog |
36 from eric7.EricWidgets.EricProcessDialog import EricProcessDialog |
38 from eric7.EricWidgets.EricProcessDialog import EricProcessDialog |
|
39 from eric7.EricWidgets.EricPlainTextDialog import EricPlainTextDialog |
37 from eric7.EricWidgets.EricZoomWidget import EricZoomWidget |
40 from eric7.EricWidgets.EricZoomWidget import EricZoomWidget |
38 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities |
41 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities |
39 from eric7.UI.Info import BugAddress |
42 from eric7.UI.Info import BugAddress |
40 |
43 |
41 from . import Devices, UF2FlashDialog |
44 from . import Devices, UF2FlashDialog |
1444 """ |
1447 """ |
1445 Private slot to populate the Super Menu before showing it. |
1448 Private slot to populate the Super Menu before showing it. |
1446 """ |
1449 """ |
1447 self.__superMenu.clear() |
1450 self.__superMenu.clear() |
1448 |
1451 |
|
1452 if self.__device: |
|
1453 hasMip = self.__device.getDeviceData("mip") |
|
1454 hasUPip = self.__device.getDeviceData("upip") |
|
1455 else: |
|
1456 hasMip = False |
|
1457 hasUPip = False |
|
1458 |
1449 # prepare the download menu |
1459 # prepare the download menu |
1450 if self.__device: |
1460 if self.__device: |
1451 menuEntries = self.__device.getDownloadMenuEntries() |
1461 menuEntries = self.__device.getDownloadMenuEntries() |
1452 if menuEntries: |
1462 if menuEntries: |
1453 downloadMenu = QMenu(self.tr("Downloads"), self.__superMenu) |
1463 downloadMenu = QMenu(self.tr("Downloads"), self.__superMenu) |
1496 ).setEnabled(self.__connected) |
1506 ).setEnabled(self.__connected) |
1497 self.__superMenu.addSeparator() |
1507 self.__superMenu.addSeparator() |
1498 self.__superMenu.addAction( |
1508 self.__superMenu.addAction( |
1499 self.tr("Show Builtin Modules"), self.__showBuiltinModules |
1509 self.tr("Show Builtin Modules"), self.__showBuiltinModules |
1500 ).setEnabled(self.__connected) |
1510 ).setEnabled(self.__connected) |
|
1511 if hasMip: |
|
1512 self.__superMenu.addAction( |
|
1513 self.tr("Install Package"), lambda: self.__installPackage("mip") |
|
1514 ).setEnabled(self.__connected) |
|
1515 elif hasUPip: |
|
1516 self.__superMenu.addAction( |
|
1517 self.tr("Install Packages"), lambda: self.__installPackage("upip") |
|
1518 ).setEnabled(self.__connected) |
1501 self.__superMenu.addSeparator() |
1519 self.__superMenu.addSeparator() |
1502 if not OSUtilities.isWindowsPlatform(): |
1520 if not OSUtilities.isWindowsPlatform(): |
1503 available = self.__mpyCrossAvailable() |
1521 available = self.__mpyCrossAvailable() |
1504 self.__superMenu.addAction( |
1522 self.__superMenu.addAction( |
1505 self.tr("Compile Python File"), self.__compileFile2Mpy |
1523 self.tr("Compile Python File"), self.__compileFile2Mpy |
2021 parent=self, |
2039 parent=self, |
2022 ) |
2040 ) |
2023 dlg.show() |
2041 dlg.show() |
2024 except Exception as exc: |
2042 except Exception as exc: |
2025 self.showError("getModules()", str(exc)) |
2043 self.showError("getModules()", str(exc)) |
|
2044 |
|
2045 @pyqtSlot() |
|
2046 def __installPackage(self, method): |
|
2047 """ |
|
2048 Private slot to install packages using the given method. |
|
2049 |
|
2050 @param method package management method to be used (one of 'upip' or 'mip') |
|
2051 @type str |
|
2052 """ |
|
2053 from .MipPackageDialog import MipPackageDialog |
|
2054 |
|
2055 if method not in ("mip", "upip"): |
|
2056 raise ValueError( |
|
2057 "Unsupported method given. Expected 'mip' or 'upip' but got {0}." |
|
2058 ).format(method) |
|
2059 |
|
2060 if method == "mip": |
|
2061 title = self.tr("Install Package") |
|
2062 dlg = MipPackageDialog(self) |
|
2063 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
2064 package, version, mpy = dlg.getData() |
|
2065 with EricOverrideCursor(): |
|
2066 out, err = self.__device.mipInstall(package, version, mpy) |
|
2067 elif method == "upip": |
|
2068 title = self.tr("Install Packages") |
|
2069 packagesStr, ok = QInputDialog.getText( |
|
2070 self, |
|
2071 self.tr("Install Packages"), |
|
2072 self.tr("Enter the packages to be installed separated by whitespace:"), |
|
2073 QLineEdit.EchoMode.Normal, |
|
2074 ) |
|
2075 if ok and packagesStr: |
|
2076 packages = packagesStr.split() |
|
2077 with EricOverrideCursor(): |
|
2078 out, err = self.__device.upipInstall(packages) |
|
2079 else: |
|
2080 return |
|
2081 else: |
|
2082 return |
|
2083 |
|
2084 if err: |
|
2085 self.showError(title, err.decode("utf-8")) |
|
2086 if out: |
|
2087 dlg = EricPlainTextDialog( |
|
2088 title=title, text=out.decode("utf-8"), parent=self |
|
2089 ) |
|
2090 dlg.exec() |