2020 https://github.com/adafruit/circuitpython/releases
2121
2222"""
23+
2324from adafruit_display_text .bitmap_label import Label
2425from displayio import Group
2526
2627try :
2728 from typing import Optional , Union
29+
2830 from fontio import FontProtocol
2931except ImportError :
3032 pass
@@ -39,7 +41,6 @@ def _check_color(color):
3941
4042
4143class ButtonBase (Group ):
42- # pylint: disable=too-many-instance-attributes
4344 """Superclass for creating UI buttons for ``displayio``.
4445
4546 :param x: The x position of the button.
@@ -53,7 +54,7 @@ class ButtonBase(Group):
5354 :param selected_label: Text that appears when selected
5455 """
5556
56- def __init__ (
57+ def __init__ ( # noqa: PLR0913 Too many arguments
5758 self ,
5859 * ,
5960 x : int ,
@@ -65,7 +66,7 @@ def __init__(
6566 label_font : Optional [FontProtocol ] = None ,
6667 label_color : Optional [Union [int , tuple [int , int , int ]]] = 0x0 ,
6768 selected_label : Optional [Union [int , tuple [int , int , int ]]] = None ,
68- label_scale : Optional [int ] = None
69+ label_scale : Optional [int ] = None ,
6970 ):
7071 super ().__init__ (x = x , y = y )
7172 self .x = x
@@ -102,20 +103,16 @@ def label(self, newtext: str) -> None:
102103 dims [2 ] *= self ._label .scale
103104 dims [3 ] *= self ._label .scale
104105 if dims [2 ] >= self .width or dims [3 ] >= self .height :
105- while len (self ._label .text ) > 1 and (
106- dims [2 ] >= self .width or dims [3 ] >= self .height
107- ):
108- self ._label .text = "{}." .format (self ._label .text [:- 2 ])
106+ while len (self ._label .text ) > 1 and (dims [2 ] >= self .width or dims [3 ] >= self .height ):
107+ self ._label .text = f"{ self ._label .text [:- 2 ]} ."
109108 dims = list (self ._label .bounding_box )
110109 dims [2 ] *= self ._label .scale
111110 dims [3 ] *= self ._label .scale
112111 if len (self ._label .text ) <= 1 :
113112 raise RuntimeError ("Button not large enough for label" )
114113 self ._label .x = (self .width - dims [2 ]) // 2
115114 self ._label .y = self .height // 2
116- self ._label .color = (
117- self ._label_color if not self .selected else self ._selected_label
118- )
115+ self ._label .color = self ._label_color if not self .selected else self ._selected_label
119116 self .append (self ._label )
120117
121118 if (self .selected_label is None ) and (self ._label_color is not None ):
0 commit comments