@@ -48,47 +48,56 @@ class Dial(Widget):
48
48
49
49
:param int width: requested width, in pixels
50
50
:param int height: requested height, in pixels
51
- :param int padding: keepout padding amount around the border, in pixels
51
+ :param int padding: keepout padding amount around the border, in pixels,
52
+ default is 12
52
53
53
- :param float sweep_angle: dial rotation, in degrees, maximum value is 360 degrees
54
- :param float start_angle: starting angle, in degrees. Defaults
55
- to `None` for symmetry along vertical axis. Vertical is defined as 0 degrees.
54
+ :param float sweep_angle: dial rotation, in degrees, maximum value is 360 degrees,
55
+ default is 90 degrees
56
+ :param float start_angle: starting angle, in degrees. Set to `None` for symmetry along
57
+ vertical axis. Vertical is defined as 0 degrees.
56
58
Negative values are counter-clockwise degrees; positive values
57
- are clockwise degrees.
59
+ are clockwise degrees. Defaults to `None`.
58
60
59
- :param float min_value: the minimum value displayed on the dial
60
- :param float max_value: the maximum value displayed the dial
61
+ :param float min_value: the minimum value displayed on the dial, default is 0.0
62
+ :param float max_value: the maximum value displayed the dial, default is 100.0
61
63
:param float value: the value to display (if None, defaults to ``min_value``)
62
64
63
65
:param Boolean display_value: set `True` to display a value label on the dial
64
- :param Font value_font: the font for the value label
65
- :param int value_color: the color for the value label
66
+ :param Font value_font: the font for the value label, defaults to
67
+ ``terminalio.FONT``
68
+ :param int value_color: the color for the value label, defaults to 0xFF0000
66
69
:param str value_format_string: the format string for displaying the value label
67
70
(defaults to ':0.0f' to show the value rounded to the nearest whole number)
68
- :param (float,float) value_label_anchor_point: anchor point on the label
69
- :param (float,float) value_label_anchor_point_on_widget: anchor point on the widget where the
70
- label will be placed
71
+ :param (float,float) value_label_anchor_point: anchor point on the label, default
72
+ value is (0.5, -1.0) where the y-value of -1.0 signifies the text baseline
73
+ :param (float,float) value_label_anchor_point_on_widget: anchor point on the
74
+ widget where the label will be placed, default value is (0.5, 0.5)
71
75
72
- :param int needle_width: requested pixel width of the triangular needle
76
+ :param int needle_width: requested pixel width of the triangular needle,
77
+ default = 7
73
78
:param int needle_color: color value for the needle, defaults to red (0xFF0000)
74
-
75
- :param int tick_color: tick line color (24-bit hex value)
76
- :param int major_ticks: number of major ticks
77
- :param int major_tick_stroke: major tick line stroke width, in pixels
78
- :param int major_tick_length: major tick length, in pixels
79
- :param str major_tick_labels: array of strings for the major tick labels
79
+ :param Boolean limit_rotation: Set True to limit needle rotation to between the
80
+ ``min_value`` and ``max_value``, set to False for unlimited rotation, default is True
81
+
82
+ :param int tick_color: tick line color (24-bit hex value), defaults to 0xFFFFFF
83
+ :param int major_ticks: number of major ticks, default = 5
84
+ :param int major_tick_stroke: major tick line stroke width, in pixels, default = 3
85
+ :param int major_tick_length: major tick length, in pixels, default = 10
86
+ :param str major_tick_labels: array of strings for the major tick labels,
87
+ default is ("0", "25", "50", "75", "100")
80
88
:param float tick_label_scale: the scaling of the tick labels, default = 1.0
81
- :param Font tick_label_font: font to be used for major tick labels
82
- :param int tick_label_color: color for the major tick labels
89
+ :param Font tick_label_font: font to be used for major tick labels, default
90
+ is ``terminalio.FONT``
91
+ :param int tick_label_color: color for the major tick labels, default is 0xFFFFFF
83
92
:param Boolean angle_tick_labels: set True to rotate the major tick labels to
84
- match the tick angle
93
+ match the tick angle, default is True
85
94
86
- :param int minor_ticks: number of minor ticks (per major tick)
87
- :param int minor_tick_stroke: minor tick line stroke width, in pixels
88
- :param int minor_tick_length: minor tick length, in pixels
95
+ :param int minor_ticks: number of minor ticks (per major tick), default = 5
96
+ :param int minor_tick_stroke: minor tick line stroke width, in pixels, default = 1
97
+ :param int minor_tick_length: minor tick length, in pixels, default = 5
89
98
90
99
:param int background_color: background color (RGB tuple
91
- or 24-bit hex value), set None for transparent
100
+ or 24-bit hex value), set ` None` for transparent, default is `None`
92
101
93
102
94
103
:param (float,float) anchor_point: (X,Y) values from 0.0 to 1.0 to define the dial's
@@ -169,6 +178,7 @@ def __init__(
169
178
needle_width = 7 ,
170
179
# triangle with this base width, best if this is odd
171
180
needle_color = 0x880000 ,
181
+ limit_rotation = True ,
172
182
value = None ,
173
183
value_font = None ,
174
184
display_value = False ,
@@ -245,6 +255,7 @@ def __init__(
245
255
self ._clip_needle = clip_needle
246
256
self ._needle_width_requested = needle_width
247
257
self ._needle_color = needle_color
258
+ self ._limit_rotation = limit_rotation
248
259
self ._background_color = background_color
249
260
250
261
self ._major_tick_labels = major_tick_labels
@@ -552,6 +563,9 @@ def _get_offset_position(self, position):
552
563
return angle_offset
553
564
554
565
def _update_needle (self , value ):
566
+ if self ._limit_rotation : # constrain between min_value and max_value
567
+ value = max (min (self ._value , self ._max_value ), self ._min_value )
568
+
555
569
self ._draw_position (
556
570
value / (self ._max_value - self ._min_value )
557
571
) # convert to position (0.0 to 1.0)
0 commit comments