Skip to content

Commit c16af0f

Browse files
committed
Updated docs and included figures and licesne files, add simpletest example
1 parent 0bf2830 commit c16af0f

10 files changed

+65
-11
lines changed

adafruit_displayio_layout/widgets/dial.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,50 @@ class Dial(Widget):
9191
anchor point relative to the dial's bounding box
9292
:param (int,int) anchored_position: (x,y) pixel value for the location
9393
of the `anchor_point`
94+
95+
96+
**Simple example of dial and moving needle**
97+
98+
See file: ``examples/displayio_layout_dial_simpletest.py``
99+
100+
101+
102+
.. figure:: dial.gif
103+
:scale: 100 %
104+
:figwidth: 50%
105+
:align: center
106+
:alt: Diagram of the dial widget with needle in motion.
107+
108+
This is a diagram of a dial widget with the needle moving from its
109+
minimum to maximum positions.
110+
111+
.. figure:: dial_variables_angles.png
112+
:scale: 50 %
113+
:figwidth: 70%
114+
:align: center
115+
:alt: Diagram showing the definition of ``start_angle`` and ``sweep_angle``,
116+
both are in units of degrees.
117+
118+
Diagram showing the definition of ``start_angle`` and ``sweep_angle``,
119+
both are in units of degrees.
120+
121+
.. figure:: dial_variables_min_max_values.png
122+
:scale: 50 %
123+
:figwidth: 70%
124+
:align: center
125+
:alt: Diagram showing the defintion of ``min_value`` and ``max_value``.
126+
127+
Diagram showing the defintion of ``min_value`` and ``max_value``.
128+
129+
.. figure:: dial_variables_ticks.png
130+
:scale: 50 %
131+
:figwidth: 70%
132+
:align: center
133+
:alt: Diagram showing the various parameters for setting the dial labels
134+
and major and minor tick marks.
135+
136+
Diagram showing the various parameters for setting the dial labels
137+
and major and minor tick marks.
94138
"""
95139

96140
# The dial is a subclass of Group->Widget.
@@ -243,7 +287,7 @@ def _initialize_dial(self, width, height):
243287
tick_length=self._major_tick_length,
244288
start_angle=self._start_angle,
245289
sweep_angle=self._sweep_angle,
246-
tick_color_index=1,
290+
tick_color_index=2,
247291
)
248292

249293
draw_ticks( # minor ticks
@@ -255,7 +299,7 @@ def _initialize_dial(self, width, height):
255299
tick_length=self._minor_tick_length,
256300
start_angle=self._start_angle,
257301
sweep_angle=self._sweep_angle,
258-
tick_color_index=1,
302+
tick_color_index=2,
259303
)
260304

261305
draw_labels(
@@ -278,8 +322,8 @@ def _initialize_dial(self, width, height):
278322
self.dial_palette[0] = 0x000000
279323
else:
280324
self.dial_palette[0] = self._background_color
281-
self.dial_palette[1] = self._tick_color
282-
self.dial_palette[2] = self._tick_label_color
325+
self.dial_palette[1] = self._tick_label_color
326+
self.dial_palette[2] = self._tick_color
283327

284328
# create the dial tilegrid and append to the self Widget->Group
285329
self.dial_tilegrid = displayio.TileGrid(
@@ -593,7 +637,7 @@ def draw_ticks(
593637
tick_length,
594638
start_angle,
595639
sweep_angle,
596-
tick_color_index=1,
640+
tick_color_index=2,
597641
):
598642
"""Helper function for drawing ticks on the dial widget. Can be used to
599643
customize the dial face.

docs/dial.gif

189 KB
Loading

docs/dial.gif.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2021 Kevin Matocha
2+
3+
SPDX-License-Identifier: MIT

docs/dial_variables_angles.png

70 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2021 Kevin Matocha
2+
3+
SPDX-License-Identifier: MIT
24.4 KB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2021 Kevin Matocha
2+
3+
SPDX-License-Identifier: MIT

docs/dial_variables_ticks.png

59.4 KB
Loading

docs/dial_variables_ticks.png.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: 2021 Kevin Matocha
2+
3+
SPDX-License-Identifier: MIT

examples/displayio_layout_dial_simpletest.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
import time
99
import board
1010
import displayio
11+
import terminalio
1112
from adafruit_displayio_layout.widgets.dial import Dial
1213

1314
from adafruit_bitmap_font import bitmap_font
1415

15-
glyphs = "0123456789"
16-
1716
# Fonts used for the Dial tick labels
18-
tick_font_file = "fonts/BitstreamVeraSans-Bold-16.pcf"
19-
tick_font = bitmap_font.load_font(tick_font_file)
20-
tick_font.load_glyphs(glyphs)
17+
tick_font = terminalio.FONT
2118

2219
display = board.DISPLAY # create the display on the PyPortal or Clue (for example)
2320
# otherwise change this to setup the display
@@ -39,7 +36,8 @@
3936
sweep_angle=240, # total sweep angle of 240 degrees
4037
min_value=minimum_value, # set the minimum value shown on the dial
4138
max_value=maximum_value, # set the maximum value shown on the dial
42-
tick_label_font=tick_font, #
39+
tick_label_font=tick_font, # the font used for the tick labels
40+
tick_label_scale=2.0, # the scale factor for the tick label font
4341
)
4442

4543
my_group = displayio.Group(max_size=1)

0 commit comments

Comments
 (0)