eric6/MicroPython/MicroPythonWidget.py

changeset 8079
331e717c458e
parent 8072
58491f4c99d6
child 8082
2242a6a1d786
equal deleted inserted replaced
8078:d0e6c9ef0f15 8079:331e717c458e
42 42
43 import Globals 43 import Globals
44 import UI.PixmapCache 44 import UI.PixmapCache
45 import Preferences 45 import Preferences
46 import Utilities 46 import Utilities
47
48 from UI.Info import BugAddress
47 49
48 # ANSI Colors (see https://en.wikipedia.org/wiki/ANSI_escape_code) 50 # ANSI Colors (see https://en.wikipedia.org/wiki/ANSI_escape_code)
49 AnsiColorSchemes = { 51 AnsiColorSchemes = {
50 "Windows 7": { 52 "Windows 7": {
51 0: QBrush(QColor(0, 0, 0)), 53 0: QBrush(QColor(0, 0, 0)),
347 '<p>Detected these unknown serial devices</p>' 349 '<p>Detected these unknown serial devices</p>'
348 '<ul>' 350 '<ul>'
349 '<li>{0}</li>' 351 '<li>{0}</li>'
350 '</ul>' 352 '</ul>'
351 '<p>Please report them together with the board name' 353 '<p>Please report them together with the board name'
352 ' and a short description to <a href="mailto:' 354 ' and a short description to <a href="mailto:{1}">'
353 'eric-bugs@eric-ide.python-projects.org"> the eric' 355 ' the eric bug reporting address</a> if it is a'
354 ' bug reporting address</a> if it is a MicroPython' 356 ' MicroPython board.</p>'
355 ' board.</p>'
356 ).format("</li><li>".join([ 357 ).format("</li><li>".join([
357 self.tr("{0} ({1:04x}/{2:04x})").format(desc, vid, pid) 358 self.tr("{0} (0x{1:04x}/0x{2:04x})",
358 for vid, pid, desc in newUnknownDevices])), 359 "description, VId, PId").format(
360 desc, vid, pid)
361 for vid, pid, desc in newUnknownDevices]),
362 BugAddress),
359 E5MessageBox.StandardButtons( 363 E5MessageBox.StandardButtons(
360 E5MessageBox.Ignore | 364 E5MessageBox.Ignore |
361 E5MessageBox.Ok 365 E5MessageBox.Ok
362 ) 366 )
363 ) 367 )
364 if button == E5MessageBox.Ignore: 368 if button == E5MessageBox.Ignore:
365 ignoredUnknown = list(ignoredUnknown | newUnknownDevices) 369 ignoredUnknown = list(ignoredUnknown | newUnknownDevices)
366 Preferences.setMicroPython("IgnoredUnknownDevices", 370 Preferences.setMicroPython("IgnoredUnknownDevices",
367 ignoredUnknown) 371 ignoredUnknown)
372 else:
373 yes = E5MessageBox.yesNo(
374 self,
375 self.tr("Unknown MicroPython Device"),
376 self.tr("""Would you like to add them to the list of"""
377 """ manually configured devices?"""),
378 yesDefault=True)
379 if yes:
380 self.__addUnknownDevices(list(newUnknownDevices))
368 381
369 def __handlePreferencesChanged(self): 382 def __handlePreferencesChanged(self):
370 """ 383 """
371 Private slot to handle a change in preferences. 384 Private slot to handle a change in preferences.
372 """ 385 """
1255 self.__superMenu.addSeparator() 1268 self.__superMenu.addSeparator()
1256 act = self.__superMenu.addAction( 1269 act = self.__superMenu.addAction(
1257 self.tr("Show Documentation"), self.__showDocumentation) 1270 self.tr("Show Documentation"), self.__showDocumentation)
1258 act.setEnabled(self.__device.hasDocumentationUrl()) 1271 act.setEnabled(self.__device.hasDocumentationUrl())
1259 self.__superMenu.addSeparator() 1272 self.__superMenu.addSeparator()
1273 self.__superMenu.addAction(self.tr("Manage Unknown Devices"),
1274 self.__manageUnknownDevices)
1260 self.__superMenu.addAction(self.tr("Ignored Serial Devices"), 1275 self.__superMenu.addAction(self.tr("Ignored Serial Devices"),
1261 self.__manageIgnored) 1276 self.__manageIgnored)
1262 self.__superMenu.addSeparator() 1277 self.__superMenu.addSeparator()
1263 self.__superMenu.addAction(self.tr("Configure"), self.__configure) 1278 self.__superMenu.addAction(self.tr("Configure"), self.__configure)
1264 1279
1632 def __configure(self): 1647 def __configure(self):
1633 """ 1648 """
1634 Private slot to open the MicroPython configuration page. 1649 Private slot to open the MicroPython configuration page.
1635 """ 1650 """
1636 e5App().getObject("UserInterface").showPreferences("microPythonPage") 1651 e5App().getObject("UserInterface").showPreferences("microPythonPage")
1652
1653 @pyqtSlot()
1654 def __manageUnknownDevices(self):
1655 """
1656 Private slot to manage manually added boards (i.e. those not in the
1657 list of supported boards).
1658 """
1659 from .UnknownDevicesDialog import UnknownDevicesDialog
1660 dlg = UnknownDevicesDialog()
1661 dlg.exec()
1662
1663 def __addUnknownDevices(self, devices):
1664 """
1665 Private method to add devices to the list of manually added boards.
1666
1667 @param devices list of not ignored but unknown devices
1668 @type list of tuple of (int, int, str)
1669 """
1670 from .AddEditDevicesDialog import AddEditDevicesDialog
1671
1672 if len(devices) > 1:
1673 from E5Gui.E5ListSelectionDialog import E5ListSelectionDialog
1674 sdlg = E5ListSelectionDialog(
1675 [d[2] for d in devices],
1676 title=self.tr("Add Unknown Devices"),
1677 message=self.tr("Select the devices to be added:"),
1678 checkBoxSelection=True
1679 )
1680 if sdlg.exec() == QDialog.Accepted:
1681 selectedDevices = sdlg.getSelection()
1682 else:
1683 selectedDevices = devices[0][2]
1684
1685 if selectedDevices:
1686 manualDevices = Preferences.getMicroPython("ManualDevices")
1687 for vid, pid, description in devices:
1688 if description in selectedDevices:
1689 dlg = AddEditDevicesDialog(vid, pid, description)
1690 if dlg.exec() == QDialog.Accepted:
1691 manualDevices.append(dlg.getDeviceDict())
1692 Preferences.setMicroPython("ManualDevices", manualDevices)
1693
1694 # rescan the ports
1695 self.__populateDeviceTypeComboBox()

eric ide

mercurial