eric6/MicroPython/MicroPythonWidget.py

changeset 8051
b78279548993
parent 8038
73ec029d4107
child 8053
5316e335722f
equal deleted inserted replaced
8050:2090a7b8a326 8051:b78279548993
8 """ 8 """
9 9
10 import re 10 import re
11 import time 11 import time
12 import os 12 import os
13 import functools
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,
1161 def __aboutToShowSuperMenu(self): 1162 def __aboutToShowSuperMenu(self):
1162 """ 1163 """
1163 Private slot to populate the Super Menu before showing it. 1164 Private slot to populate the Super Menu before showing it.
1164 """ 1165 """
1165 self.__superMenu.clear() 1166 self.__superMenu.clear()
1167
1168 # prepare the download menu
1169 if self.__device:
1170 menuEntries = self.__device.getDownloadMenuEntries()
1171 if menuEntries:
1172 downloadMenu = QMenu(self.tr("Downloads"), self.__superMenu)
1173 for text, url in menuEntries:
1174 downloadMenu.addAction(
1175 text,
1176 functools.partial(self.__downloadFromUrl, url)
1177 )
1178 else:
1179 downloadMenu = None
1180
1181 # populate the super menu
1166 if self.__device: 1182 if self.__device:
1167 hasTime = self.__device.hasTimeCommands() 1183 hasTime = self.__device.hasTimeCommands()
1168 else: 1184 else:
1169 hasTime = False 1185 hasTime = False
1170 1186
1200 act.setEnabled(available and bool(aw)) 1216 act.setEnabled(available and bool(aw))
1201 self.__superMenu.addSeparator() 1217 self.__superMenu.addSeparator()
1202 if self.__device: 1218 if self.__device:
1203 self.__device.addDeviceMenuEntries(self.__superMenu) 1219 self.__device.addDeviceMenuEntries(self.__superMenu)
1204 self.__superMenu.addSeparator() 1220 self.__superMenu.addSeparator()
1205 act = self.__superMenu.addAction( 1221 if downloadMenu is None:
1206 self.tr("Download Firmware"), self.__downloadFirmware) 1222 # generic download action
1207 act.setEnabled(self.__device.hasFirmwareUrl()) 1223 act = self.__superMenu.addAction(
1224 self.tr("Download Firmware"), self.__downloadFirmware)
1225 act.setEnabled(self.__device.hasFirmwareUrl())
1226 else:
1227 # download sub-menu
1228 self.__superMenu.addMenu(downloadMenu)
1208 self.__superMenu.addSeparator() 1229 self.__superMenu.addSeparator()
1209 act = self.__superMenu.addAction( 1230 act = self.__superMenu.addAction(
1210 self.tr("Show Documentation"), self.__showDocumentation) 1231 self.tr("Show Documentation"), self.__showDocumentation)
1211 act.setEnabled(self.__device.hasDocumentationUrl()) 1232 act.setEnabled(self.__device.hasDocumentationUrl())
1212 self.__superMenu.addSeparator() 1233 self.__superMenu.addSeparator()
1542 # abort silently 1563 # abort silently
1543 return 1564 return
1544 1565
1545 self.__device.downloadFirmware() 1566 self.__device.downloadFirmware()
1546 1567
1568 def __downloadFromUrl(self, url):
1569 """
1570 Private method to open a web browser for the given URL.
1571
1572 @param url URL to be opened
1573 @type str
1574 """
1575 if self.__device is None:
1576 # abort silently
1577 return
1578
1579 if url:
1580 e5App().getObject("UserInterface").launchHelpViewer(url)
1581
1547 @pyqtSlot() 1582 @pyqtSlot()
1548 def __manageIgnored(self): 1583 def __manageIgnored(self):
1549 """ 1584 """
1550 Private slot to manage the list of ignored serial devices. 1585 Private slot to manage the list of ignored serial devices.
1551 """ 1586 """

eric ide

mercurial