|
| 1 | +# SPDX-FileCopyrightText: 2020 Brent Rubell for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +""" |
| 6 | +`adafruit_progressbar` |
| 7 | +================================================================================ |
| 8 | +
|
| 9 | +Dynamic progress bar widget for CircuitPython displays |
| 10 | +
|
| 11 | +
|
| 12 | +* Author(s): Brent Rubell and Hugo Dahl |
| 13 | +
|
| 14 | +Implementation Notes |
| 15 | +-------------------- |
| 16 | +
|
| 17 | +**Software and Dependencies:** |
| 18 | +
|
| 19 | +* Adafruit CircuitPython firmware for the supported boards: |
| 20 | + https://github.com/adafruit/circuitpython/releases |
| 21 | +
|
| 22 | +""" |
| 23 | + |
| 24 | +# imports |
| 25 | +import displayio |
| 26 | + |
| 27 | +__version__ = "0.0.0-auto.0" |
| 28 | +__repo__ = "https://github.com/brentru/Adafruit_CircuitPython_ProgressBar.git" |
| 29 | + |
| 30 | + |
| 31 | +class ProgressBarBase(displayio.TileGrid): |
| 32 | + def __init__( |
| 33 | + self, |
| 34 | + position: (int, int), |
| 35 | + size: (int, int), |
| 36 | + start_value: float = 0.0, |
| 37 | + bar_color=0x00FF00, |
| 38 | + outline_color=0xFFFFFF, |
| 39 | + fill_color=0x000000, |
| 40 | + ): |
| 41 | + |
| 42 | + self._size = size |
| 43 | + self._position = position |
| 44 | + self._progress = start_value |
| 45 | + self._bitmap = displayio.Bitmap(self.width, self.height, 3) |
| 46 | + self._palette = displayio.Palette(3) |
| 47 | + self._palette[0] = fill_color |
| 48 | + self._palette[1] = outline_color |
| 49 | + self._palette[2] = bar_color |
| 50 | + |
| 51 | + super(ProgressBarBase, self).__init__( |
| 52 | + self._bitmap, |
| 53 | + pixel_shader=self._palette, |
| 54 | + x=self._position[0], |
| 55 | + y=self._position[1], |
| 56 | + ) |
| 57 | + |
| 58 | + _bitmap: displayio.Bitmap # The bitmap used for the bar/value |
| 59 | + _position: (int, int) # The (x,y) coordinates of the top-left corner |
| 60 | + _size: (int, int) # The dimensions of the progress bar |
| 61 | + _palette: displayio.Palette(3) # The palette to be used |
| 62 | + _progress: float # The value to represent, between 0.0 and 100.0 |
| 63 | + |
| 64 | + @property.getter |
| 65 | + def width(self): |
| 66 | + return self._size[0] |
| 67 | + |
| 68 | + @property.getter |
| 69 | + def height(self): |
| 70 | + return self._size[1] |
| 71 | + |
| 72 | + @property.getter |
| 73 | + def x(self): |
| 74 | + return self._position[0] |
| 75 | + |
| 76 | + @property.getter |
| 77 | + def y(self): |
| 78 | + return self._position[1] |
| 79 | + |
| 80 | + @property |
| 81 | + def progress(self): |
| 82 | + return self._progress |
| 83 | + |
| 84 | + @property.setter |
| 85 | + def progress(self, value): |
| 86 | + self._progress = value |
| 87 | + self.render() |
| 88 | + |
| 89 | + def render(self): |
| 90 | + pass |
0 commit comments