msl.qt.widgets.led module

An LED widget.

class msl.qt.widgets.led.Shapes(value)[source]

Bases: IntEnum

Shapes that are available to draw the LED.

Circle = 0
Rounded = 1
Square = 2
Triangle = 3
class msl.qt.widgets.led.LED(*, parent=None, shape=Shapes.Circle, on_color='#0F6900', off_color='grey', clickable=False, tooltip=None)[source]

Bases: QWidget

An LED widget, led_widget

This class is based off of the QLed project.

Parameters
  • parent (QtWidgets.QWidget) – The parent widget.

  • shape (int, str or Shapes) – The shape to draw the LED. If a str then the name of one of the Shapes, e.g. 0, 'circle' and Shapes.Circle are equivalent.

  • on_color – The color when the LED is on. See to_qcolor() for details about the different data types that are supported.

  • off_color – The color when the LED is off. See to_qcolor() for details about the different data types that are supported.

  • clickable (bool) – Whether the state of the LED can be changed by clicking on it.

  • tooltip (str, optional) – The tooltip to use for the LED.

Example

To view an example with the LED run:

>>> from msl.examples.qt import led
>>> led.show()  
Circle = 0
Rounded = 1
Square = 2
Triangle = 3
clicked

Emitted when the LED is clicked (even if it is not clickable).

toggled

Emitted when the LED turns on \(\rightarrow\) off or off \(\rightarrow\) on.

property is_on

Whether the LED is on or off.

Type

bool

clickable()[source]

Get if the on/off state of the LED can be changed by clicking on it.

Returns

bool – Whether the state of the LED can be changed by clicking on it.

set_clickable(clickable)[source]

Set if the on/off state of the LED can be changed by clicking on it.

Parameters

clickable (bool) – Whether the state of the LED can be changed by clicking on it.

off_color()[source]

Get the color of the LED when it is off.

Returns

QtGui.QColor – The off color.

set_off_color(color)[source]

Set the color of the LED when it is off.

Parameters

color – The color when the LED is off. See to_qcolor() for details about the different data types that are supported.

on_color()[source]

Get the color of the LED when it is on.

Returns

QtGui.QColor – The on color.

set_on_color(color)[source]

Set the color of the LED when it is on.

Parameters

color – The color when the LED is on. See to_qcolor() for details about the different data types that are supported.

shape()[source]

Get the shape of the LED.

Returns

Shapes – The shape of the LED.

set_shape(shape)[source]

Set the shape of the LED.

Parameters

shape (int, str or Shapes) – The shape to draw the LED. If a str then the name of one of the Shapes, e.g. 0, 'circle' and Shapes.Circle are equivalent.

toggle()[source]

Toggle the on/off state of the LED.

turn_off()[source]

Turn the LED off.

turn_on()[source]

Turn the LED on.