self.machine.mode_controller

class mpf.core.mode_controller.ModeController(machine)

Bases: mpf.core.mpf_controller.MpfController

Parent class for the Mode Controller.

There is one instance of this in MPF and it's responsible for loading, unloading, and managing all modes.

Parameters:machine -- The main MachineController instance.

Accessing the mode_controller in code

There is only one instance of the mode_controller in MPF, and it's accessible via self.machine.mode_controller.

Methods & Attributes

The mode_controller has the following methods & attributes available. Note that methods & attributes inherited from base classes are not included here.

dump()

Dump the current status of the running modes to the log file.

is_active(mode_name)

Return true if the mode is active.

Parameters:mode_name -- String name of the mode to check.
Returns:True if the mode is active, False if it is not.
register_load_method(load_method, config_section_name=None, priority=0, **kwargs)

Register a method which is called when the mode is loaded.

Used by core components, plugins, etc. to register themselves with the Mode Controller for anything they need a mode to do when it's registered.

Parameters:
  • load_method -- The method that will be called when this mode code loads.
  • config_section_name -- An optional string for the section of the configuration file that will be passed to the load_method when it's called.
  • priority -- Int of the relative priority which allows remote methods to be called in a specific order. Default is 0. Higher values will be called first.
  • **kwargs -- Any additional keyword arguments specified will be passed to the load_method.

Note that these methods will be called once, when the mode code is first initialized during the MPF boot process.

register_start_method(start_method, config_section_name=None, priority=0, **kwargs)

Register a method which is called when the mode is started.

Used by core components, plugins, etc. to register themselves with the Mode Controller for anything that they a mode to do when it starts.

Parameters:
  • start_method -- The method that will be called when this mode code loads.
  • config_section_name -- An optional string for the section of the configuration file that will be passed to the start_method when it's called.
  • priority -- Int of the relative priority which allows remote methods to be called in a specific order. Default is 0. Higher values will be called first.
  • **kwargs -- Any additional keyword arguments specified will be passed to the start_method.

Note that these methods will be called every single time this mode is started.

register_stop_method(callback, priority=0)

Register a method which is called when the mode is stopped.

These are universal, in that they're called every time a mode stops priority is the priority they're called. Has nothing to do with mode priority.

remove_start_method(start_method, config_section_name=None, priority=0, **kwargs)

Remove an existing start method.

remove_stop_method(callback, priority=0)

Remove an existing stop method.

set_mode_state(mode, active)

Called when a mode goes active or inactive.