Skip to content

Commit

Permalink
fix: correctly replace dialog 'on_click' handlers
Browse files Browse the repository at this point in the history
Fixes #52
  • Loading branch information
kalekundert committed Sep 8, 2021
1 parent dc14949 commit 7c15377
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion glooey/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_buttons(self):
return self.__buttons

def _replace_button(self, old_button, new_button, on_click):
old_button.remove_handlers(on_click)
old_button.remove_handlers(on_click=on_click)
new_button.push_handlers(on_click=on_click)
self.__buttons.replace(old_button, new_button)

Expand Down
20 changes: 12 additions & 8 deletions tests/dialogs/demo_button_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
class TestButton(glooey.Button):
custom_size_hint = 100, 20

class Label(glooey.Label): #
custom_color = 'black'
class Foreground(glooey.Label): #
custom_color = 'white'
custom_alignment = 'center'

class Base(glooey.Background): #
Expand All @@ -31,8 +31,7 @@ class Decoration(glooey.Background): #
custom_outline = 'green'

class OkButton(TestButton): #
class Label(TestButton.Label):
custom_text = 'Ok'
custom_text = 'Ok'

class TestYesNoDialog(glooey.YesNoDialog):
Content = glooey.Placeholder
Expand All @@ -48,12 +47,10 @@ class Buttons(glooey.YesNoDialog.Buttons): #
custom_cell_padding = 5

class YesButton(TestButton): #
class Label(TestButton.Label):
custom_text = 'Yes'
custom_text = 'Yes'

class NoButton(TestButton): #
class Label(TestButton.Label):
custom_text = 'No'
custom_text = 'No'


window = pyglet.window.Window()
Expand All @@ -67,6 +64,13 @@ def test_dialog():
yield 'Dialog with an "Ok" button.'
ok_dialog.close()

ok_dialog = TestOkDialog()
ok_dialog.open(gui)
ok_dialog.ok_button = TestButton(text='Custom')
ok_dialog.push_handlers(on_close=lambda w: print(f"{w} closed"))
yield 'Dialog with a custom "Ok" button.'
ok_dialog.close()

yes_no_dialog = TestYesNoDialog()
yes_no_dialog.open(gui)
yes_no_dialog.push_handlers(on_close=lambda w: print(f"{w} closed. You clicked '{'yes' if w.response else 'no'}'."))
Expand Down

0 comments on commit 7c15377

Please sign in to comment.