Skip to content

Commit

Permalink
fix: set button foreground widget
Browse files Browse the repository at this point in the history
The old code mixed up a variable such that set_foreground() would set
the foreground to the same widget it used to be, instead of using the
new widget provided by the caller.  This made it impossible to
dynamically change the foreground.
  • Loading branch information
kalekundert committed Oct 5, 2020
1 parent e593747 commit 8cc807f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion glooey/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def set_foreground(self, widget):
if self._foreground is not None:
self._detach_child(self._foreground)

self._attach_child(self._foreground)
self._attach_child(widget)
self._foreground = widget
self._repack_and_regroup_children()

Expand Down
11 changes: 7 additions & 4 deletions tests/buttons/demo_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def test_button():
yield "Grey inactive button (no rollover)."
button.enable()

button.foreground = TestLabel("Different foreground widget")
yield "Replace the foreground widget."

button.set_background(
base_top = pyglet.image.load('assets/64x4/green.png'),
base_bottom = pyglet.image.load('assets/64x4/green.png'),
Expand All @@ -82,22 +85,22 @@ def test_button():
button = TestButton('Constructor text')
button.push_handlers(on_click, on_double_click)
gui.clear(); gui.add(button)
yield "Different button text."
yield "Set text via constructor."

button = TestButtonNoForeground()
button.push_handlers(on_click, on_double_click)
gui.clear(); gui.add(button)
yield "No button text."
yield "No foreground."

button = TestButtonCustomAttrIntrospection("Custom attribute introspection")
button.push_handlers(on_click, on_double_click)
gui.clear(); gui.add(button)
yield "Custom attribute introspection (same appearance as before)"
yield "Custom attribute introspection (same appearance as first test)"

button = TestButtonSuperclassIntrospection("Superclass introspection")
button.push_handlers(on_click, on_double_click)
gui.clear(); gui.add(button)
yield "Superclass introspection (same appearance as before)"
yield "Superclass introspection (same appearance as first test)"


pyglet.app.run()
Expand Down

0 comments on commit 8cc807f

Please sign in to comment.