src/eric7/MicroPython/EspDevices.py

branch
eric7
changeset 9751
606ac0e26533
parent 9749
5d409223cf3f
child 9752
2b9546c0cbd9
equal deleted inserted replaced
9750:4958dd72c937 9751:606ac0e26533
366 """ 366 """
367 Private slot to show the firmware version of the connected device and the 367 Private slot to show the firmware version of the connected device and the
368 available firmware version. 368 available firmware version.
369 """ 369 """
370 if self.microPython.isConnected(): 370 if self.microPython.isConnected():
371 interface = self.microPython.commandsInterface() 371 if self._deviceData["mpy_name"] == "micropython":
372 if interface is not None: 372 url = QUrl(FirmwareGithubUrls["micropython"])
373 impInfo = interface.getImplementation() 373 elif self._deviceData["mpy_name"] == "circuitpython":
374 if impInfo["name"] != "micropython": 374 url = QUrl(FirmwareGithubUrls["circuitpython"])
375 EricMessageBox.critical( 375 else:
376 None, 376 EricMessageBox.critical(
377 self.tr("Show MicroPython Versions"), 377 None,
378 self.tr( 378 self.tr("Show MicroPython Versions"),
379 """The firmware of the connected device cannot be""" 379 self.tr(
380 """ determined or the board does not run MicroPython.""" 380 """The firmware of the connected device cannot be"""
381 """ Aborting...""" 381 """ determined or the board does not run MicroPython"""
382 ), 382 """ or CircuitPython. Aborting..."""
383 ) 383 ),
384 else: 384 )
385 ui = ericApp().getObject("UserInterface") 385 return
386 request = QNetworkRequest(QUrl(FirmwareGithubUrls["micropython"])) 386
387 reply = ui.networkAccessManager().head(request) 387 ui = ericApp().getObject("UserInterface")
388 reply.finished.connect( 388 request = QNetworkRequest(url)
389 lambda: self.__firmwareVersionResponse(reply, impInfo) 389 reply = ui.networkAccessManager().head(request)
390 ) 390 reply.finished.connect(lambda: self.__firmwareVersionResponse(reply))
391 391
392 def __firmwareVersionResponse(self, reply, implementation): 392 def __firmwareVersionResponse(self, reply):
393 """ 393 """
394 Private method handling the response of the latest version request. 394 Private method handling the response of the latest version request.
395 395
396 @param reply reference to the reply object 396 @param reply reference to the reply object
397 @type QNetworkReply 397 @type QNetworkReply
398 @param implementation dictionary containing the implementation data of the
399 connected device
400 @type dict
401 """ 398 """
402 latestUrl = reply.url().toString() 399 latestUrl = reply.url().toString()
403 tag = latestUrl.rsplit("/", 1)[-1] 400 tag = latestUrl.rsplit("/", 1)[-1]
404 while tag and not tag[0].isdecimal(): 401 while tag and not tag[0].isdecimal():
405 # get rid of leading non-decimal characters 402 # get rid of leading non-decimal characters
406 tag = tag[1:] 403 tag = tag[1:]
407 latestVersion = Globals.versionToTuple(tag) 404 latestVersion = Globals.versionToTuple(tag)
408 405
409 if implementation["version"] == "unknown": 406 if self._deviceData["mpy_version"] == "unknown":
410 currentVersionStr = self.tr("unknown") 407 currentVersionStr = self.tr("unknown")
411 currentVersion = (0, 0, 0) 408 currentVersion = (0, 0, 0)
412 else: 409 else:
413 currentVersionStr = implementation["version"] 410 currentVersionStr = self._deviceData["mpy_version"]
414 currentVersion = Globals.versionToTuple(currentVersionStr) 411 currentVersion = Globals.versionToTuple(currentVersionStr)
415 412
413 if self._deviceData["mpy_name"] == "circuitpython":
414 kind = "CircuitPython"
415 elif self._deviceData["mpy_name"] == "micropython":
416 kind = "MicroPython"
417
416 msg = self.tr( 418 msg = self.tr(
417 "<h4>MicroPython Version Information</h4>" 419 "<h4>{0} Version Information</h4>"
418 "<table>" 420 "<table>"
419 "<tr><td>Installed:</td><td>{0}</td></tr>" 421 "<tr><td>Installed:</td><td>{1}</td></tr>"
420 "<tr><td>Available:</td><td>{1}</td></tr>" 422 "<tr><td>Available:</td><td>{2}</td></tr>"
421 "</table>" 423 "</table>"
422 ).format(currentVersionStr, tag) 424 ).format(kind, currentVersionStr, tag)
423 if currentVersion < latestVersion: 425 if currentVersion < latestVersion:
424 msg += self.tr("<p><b>Update available!</b></p>") 426 msg += self.tr("<p><b>Update available!</b></p>")
425 427
426 EricMessageBox.information( 428 EricMessageBox.information(
427 None, 429 None,
428 self.tr("MicroPython Version"), 430 self.tr("{0} Version").format(kind),
429 msg, 431 msg,
430 ) 432 )
431 433
432 @pyqtSlot() 434 @pyqtSlot()
433 def __showChipID(self): 435 def __showChipID(self):
545 @rtype str 547 @rtype str
546 """ 548 """
547 return Preferences.getMicroPython("MicroPythonFirmwareUrl") 549 return Preferences.getMicroPython("MicroPythonFirmwareUrl")
548 550
549 551
550 def createDevice(microPythonWidget, deviceType, vid, pid, boardName): 552 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber):
551 """ 553 """
552 Function to instantiate a MicroPython device object. 554 Function to instantiate a MicroPython device object.
553 555
554 @param microPythonWidget reference to the main MicroPython widget 556 @param microPythonWidget reference to the main MicroPython widget
555 @type MicroPythonWidget 557 @type MicroPythonWidget
559 @type int 561 @type int
560 @param pid product ID 562 @param pid product ID
561 @type int 563 @type int
562 @param boardName name of the board 564 @param boardName name of the board
563 @type str 565 @type str
566 @param serialNumber serial number of the board
567 @type str
564 @return reference to the instantiated device object 568 @return reference to the instantiated device object
565 @rtype EspDevice 569 @rtype EspDevice
566 """ 570 """
567 return EspDevice(microPythonWidget, deviceType) 571 return EspDevice(microPythonWidget, deviceType)

eric ide

mercurial