Skip to content

Commit adb2dc0

Browse files
committed
Use .hidden property of TileGrid to handle text 0/1 display control
1 parent 7272941 commit adb2dc0

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

widgets/switch_round.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,16 @@ def __init__(
108108
):
109109

110110
# initialize the Widget superclass (x, y, scale)
111-
super().__init__(**kwargs, max_size=4)
111+
super().__init__(**kwargs, max_size=5)
112112
# Define how many graphical elements will be in this group
113113
# using "max_size=XX"
114114
#
115115
# Group elements for SwitchRoundHorizontal:
116116
# 1. switch_roundrect: The switch background
117117
# 2. switch_circle: The switch button
118118
# 3. Optional - widget label
119-
# 4. Optional - text_0 or text_1: The 0/1 text on the switch button
119+
# 4. Optional: text_0: The "0" circle on the switch button
120+
# 5. Optional: text_1: The "1" rectangle on the switch button
120121

121122
# initialize the Control superclass
122123
super(Control, self).__init__()
@@ -160,8 +161,6 @@ def __init__(
160161

161162
self._value = value
162163

163-
self._text_0_on = not value # controls which text value is displayed (0 or 1)
164-
165164
self._anchor_point = anchor_point
166165
self._anchored_position = anchored_position
167166

@@ -315,10 +314,14 @@ def __init__(
315314

316315
# If display_button_text is True, append the correct text element (0 or 1)
317316
if display_button_text:
318-
if self._text_0_on:
319-
self.append(self._text_0)
317+
self.append(self._text_0)
318+
self.append(self._text_1)
319+
if self._value:
320+
self._text_0.hidden=True
321+
self._text_1.hidden=False
320322
else:
321-
self.append(self._text_1)
323+
self._text_0.hidden=False
324+
self._text_1.hidden=True
322325

323326
# update the position, if required
324327
self._update_position()
@@ -386,15 +389,13 @@ def _draw_position(self, position):
386389
self._text_0.outline = self._switch_circle.outline
387390
self._text_1.outline = self._switch_circle.outline
388391

389-
if self._display_button_text and position > 0.5 and self._text_0_on:
390-
self.pop()
391-
self.append(self._text_1)
392-
self._text_0_on = False
392+
if self._display_button_text and position >= 0.5 :
393+
self._text_0.hidden=True
394+
self._text_1.hidden=False
393395

394-
elif self._display_button_text and position < 0.5 and not self._text_0_on:
395-
self.pop()
396-
self.append(self._text_0)
397-
self._text_0_on = True
396+
elif self._display_button_text and position < 0.5 :
397+
self._text_0.hidden=False
398+
self._text_1.hidden=True
398399

399400
def selected(self, touch_point):
400401
# requires passing display to allow auto_refresh off when redrawing

0 commit comments

Comments
 (0)