Skip to content

led_icon

frog.gui.led_icon ¤

Class for LED Icons.

Classes¤

LEDIcon(on_img, off_img, is_on=False) ¤

Bases: QLabel

QLabel object to represent an LED with on/off status.

Creates the LED icon, sets its status and stores corresponding image data.

Parameters:

Name Type Description Default
on_img QImage

QImage for LED on state.

required
off_img QImage

QImage for LED off state.

required
is_on bool

On/off status of LED.

False
Source code in frog/gui/led_icon.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
def __init__(self, on_img: QImage, off_img: QImage, is_on: bool = False) -> None:
    """Creates the LED icon, sets its status and stores corresponding image data.

    Args:
        on_img (QImage): QImage for LED on state.
        off_img (QImage): QImage for LED off state.
        is_on (bool): On/off status of LED.
    """
    super().__init__()
    self._on_img = on_img
    self._off_img = off_img
    if is_on:
        self.turn_on()
    else:
        self.turn_off()
    self.timer = QTimer()
    self.timer.timeout.connect(self.turn_off)
Functions¤
create_green_icon() classmethod ¤

Creates a green LED icon.

Source code in frog/gui/led_icon.py
44
45
46
47
@classmethod
def create_green_icon(cls) -> LEDIcon:
    """Creates a green LED icon."""
    return cls(on_img=_green_on_img, off_img=_green_off_img)
create_red_icon() classmethod ¤

Creates a red LED icon.

Source code in frog/gui/led_icon.py
49
50
51
52
@classmethod
def create_red_icon(cls) -> LEDIcon:
    """Creates a red LED icon."""
    return cls(on_img=_red_on_img, off_img=_red_off_img)
flash(duration=250) ¤

Turns the LED on for a specified duration.

Parameters:

Name Type Description Default
duration int

Number of milliseconds to keep LED lit for

250
Source code in frog/gui/led_icon.py
64
65
66
67
68
69
70
71
def flash(self, duration: int = 250) -> None:
    """Turns the LED on for a specified duration.

    Args:
        duration (int): Number of milliseconds to keep LED lit for
    """
    self.turn_on()
    self.timer.singleShot(duration, self.turn_off)
turn_off() ¤

Turns the LED off.

Source code in frog/gui/led_icon.py
59
60
61
62
def turn_off(self) -> None:
    """Turns the LED off."""
    self._is_on = False
    self.setPixmap(QPixmap(self._off_img))
turn_on() ¤

Turns the LED on.

Source code in frog/gui/led_icon.py
54
55
56
57
def turn_on(self) -> None:
    """Turns the LED on."""
    self._is_on = True
    self.setPixmap(QPixmap(self._on_img))