@@ -100,14 +100,13 @@ def __init__(
100100 selected_outline = None ,
101101 selected_label = None
102102 ):
103- super ().__init__ ()
103+ super ().__init__ (x = x , y = y )
104104 self .x = x
105105 self .y = y
106106 self .width = width
107107 self .height = height
108108 self ._font = label_font
109109 self ._selected = False
110- self .group = displayio .Group ()
111110 self .name = name
112111 self ._label = label
113112 self .body = self .fill = self .shadow = None
@@ -129,51 +128,49 @@ def __init__(
129128 if (outline_color is not None ) or (fill_color is not None ):
130129 if style == Button .RECT :
131130 self .body = Rect (
132- x ,
133- y ,
131+ 0 ,
132+ 0 ,
134133 width ,
135134 height ,
136135 fill = self .fill_color ,
137136 outline = self .outline_color ,
138137 )
139138 elif style == Button .ROUNDRECT :
140139 self .body = RoundRect (
141- x ,
142- y ,
140+ 0 ,
141+ 0 ,
143142 width ,
144143 height ,
145144 r = 10 ,
146145 fill = self .fill_color ,
147146 outline = self .outline_color ,
148147 )
149148 elif style == Button .SHADOWRECT :
150- self .shadow = Rect (
151- x + 2 , y + 2 , width - 2 , height - 2 , fill = outline_color
152- )
149+ self .shadow = Rect (2 , 2 , width - 2 , height - 2 , fill = outline_color )
153150 self .body = Rect (
154- x ,
155- y ,
151+ 0 ,
152+ 0 ,
156153 width - 2 ,
157154 height - 2 ,
158155 fill = self .fill_color ,
159156 outline = self .outline_color ,
160157 )
161158 elif style == Button .SHADOWROUNDRECT :
162159 self .shadow = RoundRect (
163- x + 2 , y + 2 , width - 2 , height - 2 , r = 10 , fill = self .outline_color
160+ 2 , 2 , width - 2 , height - 2 , r = 10 , fill = self .outline_color
164161 )
165162 self .body = RoundRect (
166- x ,
167- y ,
163+ 0 ,
164+ 0 ,
168165 width - 2 ,
169166 height - 2 ,
170167 r = 10 ,
171168 fill = self .fill_color ,
172169 outline = self .outline_color ,
173170 )
174171 if self .shadow :
175- self .group . append (self .shadow )
176- self .group . append (self .body )
172+ self .append (self .shadow )
173+ self .append (self .body )
177174
178175 self .label = label
179176
@@ -184,8 +181,8 @@ def label(self):
184181
185182 @label .setter
186183 def label (self , newtext ):
187- if self ._label and self . group and (self . group [- 1 ] == self ._label ):
188- self .group . pop ()
184+ if self ._label and self and (self [- 1 ] == self ._label ):
185+ self .pop ()
189186
190187 self ._label = None
191188 if not newtext or (self ._label_color is None ): # no new text
@@ -197,10 +194,10 @@ def label(self, newtext):
197194 dims = self ._label .bounding_box
198195 if dims [2 ] >= self .width or dims [3 ] >= self .height :
199196 raise RuntimeError ("Button not large enough for label" )
200- self ._label .x = self . x + (self .width - dims [2 ]) // 2
201- self ._label .y = self .y + self . height // 2
197+ self ._label .x = (self .width - dims [2 ]) // 2
198+ self ._label .y = self .height // 2
202199 self ._label .color = self ._label_color
203- self .group . append (self ._label )
200+ self .append (self ._label )
204201
205202 if (self .selected_label is None ) and (self ._label_color is not None ):
206203 self .selected_label = (~ self ._label_color ) & 0xFFFFFF
@@ -230,6 +227,16 @@ def selected(self, value):
230227 if self ._label is not None :
231228 self ._label .color = new_label
232229
230+ @property
231+ def group (self ):
232+ """Return self for compatibility with old API."""
233+ print (
234+ "Warning: The group property is being deprecated. "
235+ "User code should be updated to add the Button directly to the "
236+ "Display or other Groups."
237+ )
238+ return self
239+
233240 def contains (self , point ):
234241 """Used to determine if a point is contained within a button. For example,
235242 ``button.contains(touch)`` where ``touch`` is the touch point on the screen will allow for
0 commit comments