Calling Show Player in Python

Skip to first unread message


Aug 26, 2023, 12:52:52 PM8/26/23
to MPF Users
Hi All,

I'm running into an issue and I don't seem to be able to fix it. My Pinn game is very procedural and because of this I do most of the coding in Python itself.

In this particular case I'm trying to get the show player to play a light show. but pending on a selection in the game it is using a different light or color. I want to do it in python because otherwise I need to add hundreds of events, which I wonder what that will do to the performance.

Most of the objects I have been able to trace back and I'm able to launch my lightshows via python. However I'm not able to stop them. and I do get this warning
2023-08-26 18:25:16,465 : WARNING : show_player : Config player show_player is missing context effect_controlled_friend

In the attachment I added a video, the purple blinking light should be turned off when moving to the next light. but that doesn't happen.

The problem is that I can't trace back the issue, I gave it a key, and gave it context, but for some reason it still doesn't have context when I try.

Code looks like this:
def light_play_show(self, light: str, color_id: str, action="play", **kwargs):
        led = NativeTypeTemplate(value=light, machine=self.machine)
        color = NativeTypeTemplate(value=color_id, machine=self.machine)
        self.settings = self.get_show_settings(led, color, action), context="effect_controlled_friend", calling_context=None)

def get_show_settings(self, led, color, action="play", **kwargs):
        settings = {
            self.condition: {
                "action": action,
                "key": "effect_controlled_friend",
                "priority": 5000,
                "block_queue": False,
                "start_step": self.start_step,
                "speed": "1.0",
                "loops": "-1",
                "start_running": self.start_step,
                "sync_ms": None,
                "manual_advance": False,
                "events_when_played": [],
                "events_when_stopped": [],
                "events_when_looped": [],
                "events_when_paused": [],
                "events_when_resumed": [],
                "events_when_advanced": [],
                "events_when_stepped_back": [],
                "events_when_updated": [],
                "events_when_completed": [],
                "show_tokens": {
                    "led": led,
                    "color1": color

        return settings

I made a version (not procedural) in YAML to check if there is a difference between the context and key. compared to calling it manually via python. but everything that I print looks exactly the same.

      action: play
      key: effect_controlled_friend
      priority: 5000
        color1: purple
        led: l_objective_hide_target_h

      action: stop
      key: effect_controlled_friend

If any of the developers has any idea where I'm going wrong I would gladly hear it.
I have done similar things with widgets and that works perfectly, especially since that works with the given key. Which doesn't seem to be the case with shows...

Best regards,
Jordy de Lat
2023-08-26 18-45-37.mp4

Anthony van Winkle

Aug 26, 2023, 1:47:04 PM8/26/23
to MPF Users
Hello Jordy!

When discussing shows, the context refers to the instigator of the show, like the "parent" that starts the show. Most often this will be the name of the mode that the show is in, which is how MPF is able to track all the shows started by a mode and (more importantly) stop all those shows when the mode stops. 

So in your case, it looks like you're using an arbitrary value "effect_controlled_friend" as the context, which is giving the error because that's not a context MPF is tracking. I would suggest using the name of the parent mode as the context and see if that gets you in the right direction.


Aug 27, 2023, 11:58:34 AM8/27/23
to MPF Users
Hey Anthony!

Thank you for getting back to me!
So I have been trying to dig deeper into this based on your advise, and yeah its exactly as you say when I print the context in the I indeed get the when launching the show from the YAML file.
"effect_controlled_friend" was in this case is my mode name. I changed this to for the future.

That said, It's still doesn't seem to make a difference. However it did get me a little further.
The calls a function called _get_instance_dict. And this seems where there problem is happening. (also where the missing context error message comes from)

So I added some print code t0 the existing fucntion. (forgive me, its a bit messy)
def _get_instance_dict(self, context):
        if context == "effect_controlled_friend":
            return self.instances[context][self.config_file_section]
        except KeyError:
            self.warning_log("Config player {} is missing context {}".format(self.config_file_section, context))
            return {}

So when I launch the YAML version of the show it returns the following:
self.instances.keys() -> dict_keys(['_global', 'effect_controlled_friend', 'lanes'])
self.instances[context]  -> {'show_player': {'effect_controlled_friend': Running Show Instance: "ls_controlled_friend" {'color1': 'purple', 'led': 'l_objective_hide_target_h'} 1}}
self.instances[context][self.config_file_section] -> {'effect_controlled_friend': Running Show Instance: "ls_controlled_friend" {'color1': 'purple', 'led': 'l_objective_hide_target_h'} 1}
Which is completely right offcourse.
Running the python variant it shows that the self.intstances from the doesn't have the key effect_controlled_friend.
(and offcourse crashes afterwards because of a KeyError)

dict_keys(['_global', 'lanes'])

So I guess I need to find a way to add and update the self.instances to fix this particular problem. If I can add the same data as the YAML file I think it should work.

Any tips on how to approach this are welcome offcourse!

Best Regards,
Jordy de Lat

Sector 8 Music

Aug 27, 2023, 3:14:17 PM8/27/23
I found a way to fix it, its probably not the way it was intended though... but it happend by accident while I was figuring out how everything was connected to each other. 
adding this line makes sure that the context exists, and now it is stopping the shows as intended!
self.machine.show_player.process_mode_config(config=dict(), root_config_dict=dict(), mode=self)

You received this message because you are subscribed to the Google Groups "MPF Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
0 new messages