Since we need a single button to toggle between pause and unpause, we will again use the cycle() method from the itertools module. Define an attribute, as follows (see code 5.04—view.py):
toggle_pause_unpause = itertools.cycle(["pause","unpause"])
Then, modify the command callback attached to the button, as follows:
def on_pause_unpause_button_clicked(self):
action = next(self.toggle_pause_unpause)
if action == 'pause':
self.player.pause()
elif action == 'unpause':
self.player.unpause()
This takes care of the pause and unpause features of the program.