# eric7.MicroPython.MicroPythonWidget

Module implementing the MicroPython REPL widget.

### Global Attributes

AnsiColorSchemes

### Classes

MicroPythonWidget | Class implementing the MicroPython REPL widget.

### Functions

None

## MicroPythonWidget

Class implementing the MicroPython REPL widget.

### Signals

dataReceived(data)
  emitted to send data received via the serial connection for further processing

### Derived from

QWidget, Ui_MicroPythonWidget

### Class Attributes

DeviceBoardRole
DevicePidRole
DevicePortRole
DeviceTypeRole
DeviceVidRole
ManualMarker
ZoomMax
ZoomMin

### Class Methods

None

### Methods

MicroPythonWidget | Constructor
__aboutToShowSuperMenu | Private slot to populate the Super Menu before showing it.
__addUnknownDevices | Private method to add devices to the list of manually added boards.
__clear | Private slot to clear the REPL pane.
__compileEditor2Mpy | Private slot to cross compile the current editor to a .mpy file.
__compileFile2Mpy | Private slot to cross compile a Python file (*.py) to a .mpy file.
__configure | Private slot to open the MicroPython configuration page.
__connectToDevice | Private method to connect to the selected device.
__crossCompile | Private method to cross compile a Python file to a .mpy file.
__disconnectFromDevice | Private method to disconnect from the device.
__doZoom | Private slot to zoom the REPL pane.
__downloadFirmware | Private slot to open the firmware download page.
__downloadFromUrl | Private method to open a web browser for the given URL.
__flashUF2 | Private slot to flash MicroPython/CircuitPython to a device support the UF2 bootloader.
__getDeviceTime | Private method to get a string containing the date and time of the connected device.
__handlePreferencesChanged | Private slot to handle a change in preferences.
__manageIgnored | Private slot to manage the list of ignored serial devices.
__manageUnknownDevices | Private slot to manage manually added boards (i.e.
__mpyCrossAvailable | Private method to check the availability of mpy-cross.
__paste | Private slot to perform a paste operation.
__populateDeviceTypeComboBox | Private method to populate the device type selector.
__processData | Private slot to process bytes received from the device.
__replEditMouseReleaseEvent | Private method handling mouse release events for the replEdit widget.
__setCharFormat | Private method setting the current text format of the REPL pane based on the passed ANSI codes.
__setConnected | Private method to set the connection status LED.
__showBoardInformation | Private slot to show all available information about a board.
__showContextMenu | Private slot to show the REPL context menu.
__showDeviceTime | Private slot to show the date and time of the connected device.
__showDeviceVersion | Private slot to show some version info about MicroPython of the device.
__showDocumentation | Private slot to open the documentation URL for the selected device.
__showError | Private method to show some error message.
__showImplementation | Private slot to show some implementation related information.
__showLocalAndDeviceTime | Private slot to show the local and device time side-by-side.
__showLocalTime | Private slot to show the local date and time.
__showNoDeviceMessage | Private method to show a message dialog indicating a missing device.
__synchronizeTime | Private slot to set the time of the connected device to the local computer's time.
commandsInterface | Public method to get a reference to the commands interface object.
eventFilter | Public method to process events for the REPL pane.
getCurrentBoard | Public method to get the board name of the selected device.
getCurrentPort | Public method to determine the port path of the selected device.
getDeviceWorkspace | Public method to get the workspace directory of the device.
handleDataFlood | Public slot handling a data flood from the device.
isConnected | Public method to get the connection state.
isMicrobit | Public method to check, if the connected/selected device is a BBC micro:bit or Calliope mini.
on_chartButton_clicked | Private slot to open a chart view to plot data received from the connected device.
on_checkButton_clicked | Private slot to check for connected devices.
on_connectButton_clicked | Private slot to connect to the selected device or disconnect from the currently connected device.
on_deviceTypeComboBox_activated | Private slot handling the selection of a device type.
on_filesButton_clicked | Private slot to open a file manager window to the connected device.
on_openButton_clicked | Private slot to open a file of the connected device.
on_replButton_clicked | Private slot to connect to enable or disable the REPL widget.
on_runButton_clicked | Private slot to execute the script of the active editor on the selected device.
on_saveButton_clicked | Private slot to save the current editor to the connected device.
setActionButtons | Public method to set the enabled state of the various action buttons.

### Static Methods

None

#### MicroPythonWidget (Constructor)

MicroPythonWidget(parent=None)

Constructor

parent (QWidget)
  reference to the parent widget

#### MicroPythonWidget.__aboutToShowSuperMenu

__aboutToShowSuperMenu()

Private slot to populate the Super Menu before showing it.

#### MicroPythonWidget.__addUnknownDevices

__addUnknownDevices(devices)

Private method to add devices to the list of manually added boards.

devices (list of tuple of (int, int, str))
  list of not ignored but unknown devices

#### MicroPythonWidget.__clear

__clear()

Private slot to clear the REPL pane.

#### MicroPythonWidget.__compileEditor2Mpy

__compileEditor2Mpy()

Private slot to cross compile the current editor to a .mpy file.

#### MicroPythonWidget.__compileFile2Mpy

__compileFile2Mpy()

Private slot to cross compile a Python file (*.py) to a .mpy file.

#### MicroPythonWidget.__configure

__configure()

Private slot to open the MicroPython configuration page.

#### MicroPythonWidget.__connectToDevice

__connectToDevice()

Private method to connect to the selected device.

#### MicroPythonWidget.__crossCompile

__crossCompile(pythonFile="", title="")

Private method to cross compile a Python file to a .mpy file.

pythonFile (str)
  name of the Python file to be compiled
title (str)
  title for the various dialogs

#### MicroPythonWidget.__disconnectFromDevice

__disconnectFromDevice()

Private method to disconnect from the device.

#### MicroPythonWidget.__doZoom

__doZoom(value)

Private slot to zoom the REPL pane.

value (int)
  zoom value

#### MicroPythonWidget.__downloadFirmware

__downloadFirmware()

Private slot to open the firmware download page.

#### MicroPythonWidget.__downloadFromUrl

__downloadFromUrl(url)

Private method to open a web browser for the given URL.

url (str)
  URL to be opened

#### MicroPythonWidget.__flashUF2

__flashUF2()

Private slot to flash MicroPython/CircuitPython to a device support the UF2 bootloader.

#### MicroPythonWidget.__getDeviceTime

__getDeviceTime()

Private method to get a string containing the date and time of the connected device.

Return:
  date and time of the connected device

Return Type:
  str

#### MicroPythonWidget.__handlePreferencesChanged

__handlePreferencesChanged()

Private slot to handle a change in preferences.

#### MicroPythonWidget.__manageIgnored

__manageIgnored()

Private slot to manage the list of ignored serial devices.

#### MicroPythonWidget.__manageUnknownDevices

__manageUnknownDevices()

Private slot to manage manually added boards (i.e. those not in the list of supported boards).

#### MicroPythonWidget.__mpyCrossAvailable

__mpyCrossAvailable()

Private method to check the availability of mpy-cross.

Return:
  flag indicating the availability of mpy-cross

Return Type:
  bool

#### MicroPythonWidget.__paste

__paste(mode=QClipboard.Mode.Clipboard)

Private slot to perform a paste operation.

mode (QClipboard.Mode (optional))
  paste mode (defaults to QClipboard.Mode.Clipboard)

#### MicroPythonWidget.__populateDeviceTypeComboBox

__populateDeviceTypeComboBox()

Private method to populate the device type selector.

#### MicroPythonWidget.__processData

__processData(data)

Private slot to process bytes received from the device.

data (bytes)
  bytes received from the device

#### MicroPythonWidget.__replEditMouseReleaseEvent

__replEditMouseReleaseEvent(evt)

Private method handling mouse release events for the replEdit widget.

Note: this is a hack because QTextEdit does not allow filtering of QEvent.Type.MouseButtonRelease. To make middle button paste work, we had to intercept the protected event method (some kind of reimplementing it).

evt (QMouseEvent)
  reference to the event object

#### MicroPythonWidget.__setCharFormat

__setCharFormat(formatCodes, textCursor)

Private method setting the current text format of the REPL pane based on the passed ANSI codes.

Following codes are used:

- 0: Reset
- 1: Bold font (weight 75)
- 2: Light font (weight 25)
- 3: Italic font
- 4: Underlined font
- 9: Strikeout font
- 21: Bold off (weight 50)
- 22: Light off (weight 50)
- 23: Italic off
- 24: Underline off
- 29: Strikeout off
- 30: foreground Black
- 31: foreground Dark Red
- 32: foreground Dark Green
- 33: foreground Dark Yellow
- 34: foreground Dark Blue
- 35: foreground Dark Magenta
- 36: foreground Dark Cyan
- 37: foreground Light Gray
- 39: reset foreground to default
- 40: background Black
- 41: background Dark Red
- 42: background Dark Green
- 43: background Dark Yellow
- 44: background Dark Blue
- 45: background Dark Magenta
- 46: background Dark Cyan
- 47: background Light Gray
- 49: reset background to default
- 53: Overlined font
- 55: Overline off
- 90: bright foreground Dark Gray
- 91: bright foreground Red
- 92: bright foreground Green
- 93: bright foreground Yellow
- 94: bright foreground Blue
- 95: bright foreground Magenta
- 96: bright foreground Cyan
- 97: bright foreground White
- 100: bright background Dark Gray
- 101: bright background Red
- 102: bright background Green
- 103: bright background Yellow
- 104: bright background Blue
- 105: bright background Magenta
- 106: bright background Cyan
- 107: bright background White

formatCodes (list of str)
  list of format codes
textCursor (QTextCursor)
  reference to the text cursor

#### MicroPythonWidget.__setConnected

__setConnected(connected)

Private method to set the connection status LED.

connected (bool)
  connection state

#### MicroPythonWidget.__showBoardInformation

__showBoardInformation()

Private slot to show all available information about a board.

#### MicroPythonWidget.__showContextMenu

__showContextMenu(pos)

Private slot to show the REPL context menu.

pos (QPoint)
  position to show the menu at

#### MicroPythonWidget.__showDeviceTime

__showDeviceTime()

Private slot to show the date and time of the connected device.

#### MicroPythonWidget.__showDeviceVersion

__showDeviceVersion()

Private slot to show some version info about MicroPython of the device.

#### MicroPythonWidget.__showDocumentation

__showDocumentation()

Private slot to open the documentation URL for the selected device.

#### MicroPythonWidget.__showError

__showError(method, error)

Private method to show some error message.

method (str)
  name of the method the error occured in
error (str)
  error message

#### MicroPythonWidget.__showImplementation

__showImplementation()

Private slot to show some implementation related information.

#### MicroPythonWidget.__showLocalAndDeviceTime

__showLocalAndDeviceTime()

Private slot to show the local and device time side-by-side.

#### MicroPythonWidget.__showLocalTime

__showLocalTime()

Private slot to show the local date and time.

#### MicroPythonWidget.__showNoDeviceMessage

__showNoDeviceMessage()

Private method to show a message dialog indicating a missing device.

#### MicroPythonWidget.__synchronizeTime

__synchronizeTime(quiet=False)

Private slot to set the time of the connected device to the local computer's time.

quiet (bool)
  flag indicating to not show a message

#### MicroPythonWidget.commandsInterface

commandsInterface()

Public method to get a reference to the commands interface object.

Return:
  reference to the commands interface object

Return Type:
  MicroPythonCommandsInterface

#### MicroPythonWidget.eventFilter

eventFilter(obj, evt)

Public method to process events for the REPL pane.

obj (QObject)
  reference to the object the event was meant for
evt (QEvent)
  reference to the event object

Return:
  flag to indicate that the event was handled

Return Type:
  bool

#### MicroPythonWidget.getCurrentBoard

getCurrentBoard()

Public method to get the board name of the selected device.

Return:
  board name of the selected device

Return Type:
  str

#### MicroPythonWidget.getCurrentPort

getCurrentPort()

Public method to determine the port path of the selected device.

Return:
  path of the port of the selected device

Return Type:
  str

#### MicroPythonWidget.getDeviceWorkspace

getDeviceWorkspace()

Public method to get the workspace directory of the device.

Return:
  workspace directory of the device

Return Type:
  str

#### MicroPythonWidget.handleDataFlood

handleDataFlood()

Public slot handling a data flood from the device.

#### MicroPythonWidget.isConnected

isConnected()

Public method to get the connection state.

Return:
  connection state

Return Type:
  bool

#### MicroPythonWidget.isMicrobit

isMicrobit()

Public method to check, if the connected/selected device is a BBC micro:bit or Calliope mini.

Return:
  flag indicating a micro:bit device rtype bool

#### MicroPythonWidget.on_chartButton_clicked

on_chartButton_clicked(checked)

Private slot to open a chart view to plot data received from the connected device.

If the selected device is not connected yet, this will be done now.

checked (bool)
  state of the button

#### MicroPythonWidget.on_checkButton_clicked

on_checkButton_clicked()

Private slot to check for connected devices.

#### MicroPythonWidget.on_connectButton_clicked

on_connectButton_clicked()

Private slot to connect to the selected device or disconnect from the currently connected device.

#### MicroPythonWidget.on_deviceTypeComboBox_activated

on_deviceTypeComboBox_activated(index)

Private slot handling the selection of a device type.

index (int)
  index of the selected device

#### MicroPythonWidget.on_filesButton_clicked

on_filesButton_clicked(checked)

Private slot to open a file manager window to the connected device.

If the selected device is not connected yet, this will be done now.

checked (bool)
  state of the button

#### MicroPythonWidget.on_openButton_clicked

on_openButton_clicked()

Private slot to open a file of the connected device.

#### MicroPythonWidget.on_replButton_clicked

on_replButton_clicked(checked)

Private slot to connect to enable or disable the REPL widget.

If the selected device is not connected yet, this will be done now.

checked (bool)
  state of the button

#### MicroPythonWidget.on_runButton_clicked

on_runButton_clicked()

Private slot to execute the script of the active editor on the selected device.

If the REPL is not active yet, it will be activated, which might cause an unconnected device to be connected.

#### MicroPythonWidget.on_saveButton_clicked

on_saveButton_clicked()

Private slot to save the current editor to the connected device.

#### MicroPythonWidget.setActionButtons

setActionButtons(**kwargs)

Public method to set the enabled state of the various action buttons.

kwargs= (dict)
  keyword arguments containg the enabled states (keys are 'run', 'repl', 'files', 'chart', 'open', 'save'

Up