Exemple #1
0
    def __init__(self, machine):
        self.machine = machine
        self.log = logging.getLogger("DisplayController")
        self.log.debug("Loading the DisplayController")

        self.delay = DelayManager()

        self.hw_module = None
        self.fonts = None

        self.machine.request_pygame()

        # todo move this? Should be in the DMD module?
        self.dmd_palette = [(0, 0, 0),
                            (1, 0, 0),
                            (2, 0, 0),
                            (3, 0, 0),
                            (4, 0, 0),
                            (5, 0, 0),
                            (6, 0, 0),
                            (7, 0, 0),
                            (8, 0, 0),
                            (9, 0, 0),
                            (10, 0, 0),
                            (11, 0, 0),
                            (12, 0, 0),
                            (13, 0, 0),
                            (14, 0, 0),
                            (15, 0, 0)] * 16

        self.transitions = dict()
        self.decorators = dict()
        self.display_elements = dict()

        self.displays = dict()
        self.default_display = None
        self.slidebuilder = SlideBuilder(self.machine)

        # Register for events
        if 'window' in self.machine.config:
            self.machine.events.add_handler('init_phase_2',
                                            self.machine.get_window,
                                            priority=1000)

        self.machine.events.add_handler('init_phase_1',
                                        self._load_display_modules)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_display_element_modules)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_fonts)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_transitions)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_decorators)
        self.machine.events.add_handler('action_show_slide', self.show_slide)

        if 'slide_player' in self.machine.config:
            self.machine.events.add_handler('pygame_initialized',
                self._load_slidebuilder_config)
Exemple #2
0
    def __init__(self, machine):
        self.machine = machine
        self.log = logging.getLogger("DisplayController")
        self.log.debug("Loading the DisplayController")

        self.delay = DelayManager()

        self.hw_module = None
        self.fonts = None

        self.machine.request_pygame()

        # todo move this? Should be in the DMD module?
        self.dmd_palette = [(0, 0, 0), (1, 0, 0), (2, 0, 0), (3, 0, 0),
                            (4, 0, 0), (5, 0, 0), (6, 0, 0), (7, 0, 0),
                            (8, 0, 0), (9, 0, 0), (10, 0, 0), (11, 0, 0),
                            (12, 0, 0), (13, 0, 0), (14, 0, 0),
                            (15, 0, 0)] * 16

        self.transitions = dict()
        self.decorators = dict()
        self.display_elements = dict()

        self.displays = dict()
        self.default_display = None
        self.slidebuilder = SlideBuilder(self.machine)

        # Register for events
        if 'window' in self.machine.config:
            self.machine.events.add_handler('init_phase_2',
                                            self.machine.get_window,
                                            priority=1000)

        self.machine.events.add_handler('init_phase_1',
                                        self._load_display_modules)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_display_element_modules)
        self.machine.events.add_handler('init_phase_1', self._load_fonts)
        self.machine.events.add_handler('init_phase_1', self._load_transitions)
        self.machine.events.add_handler('init_phase_1', self._load_decorators)
        self.machine.events.add_handler('action_show_slide', self.show_slide)

        if 'slideplayer' in self.machine.config:
            self.machine.events.add_handler('pygame_initialized',
                                            self._load_slidebuilder_config)
Exemple #3
0
class DisplayController(object):
    """Parent class for the Display Controller in MPF. There is only one of
    these per machine. It's responsible for interacting with the display,
    regardless of what type it is (DMD, LCD, alphanumeric, etc.).

    Args:
        machine: The main MachineController object.
    """

    def __init__(self, machine):
        self.machine = machine
        self.log = logging.getLogger("DisplayController")
        self.log.debug("Loading the DisplayController")

        self.delay = DelayManager()

        self.hw_module = None
        self.fonts = None

        self.machine.request_pygame()

        # todo move this? Should be in the DMD module?
        self.dmd_palette = [
            (0, 0, 0),
            (1, 0, 0),
            (2, 0, 0),
            (3, 0, 0),
            (4, 0, 0),
            (5, 0, 0),
            (6, 0, 0),
            (7, 0, 0),
            (8, 0, 0),
            (9, 0, 0),
            (10, 0, 0),
            (11, 0, 0),
            (12, 0, 0),
            (13, 0, 0),
            (14, 0, 0),
            (15, 0, 0),
        ] * 16

        self.transitions = dict()
        self.decorators = dict()
        self.display_elements = dict()

        self.displays = dict()
        self.default_display = None
        self.slidebuilder = SlideBuilder(self.machine)

        # Register for events
        if "window" in self.machine.config:
            self.machine.events.add_handler("init_phase_2", self.machine.get_window, priority=1000)

        self.machine.events.add_handler("init_phase_1", self._load_display_modules)
        self.machine.events.add_handler("init_phase_1", self._load_display_element_modules)
        self.machine.events.add_handler("init_phase_1", self._load_fonts)
        self.machine.events.add_handler("init_phase_1", self._load_transitions)
        self.machine.events.add_handler("init_phase_1", self._load_decorators)
        self.machine.events.add_handler("action_show_slide", self.show_slide)

        if "slideplayer" in self.machine.config:
            self.machine.events.add_handler("pygame_initialized", self._load_slidebuilder_config)

    def _load_slidebuilder_config(self):
        # This has to be a separate method since slidebuilder.process config
        # returns an unloader method so we can't use it as an event handler
        self.slidebuilder.process_config(self.machine.config["slideplayer"], priority=0)

    def _load_display_modules(self):
        # Load the display modules as specified in the config files

        # todo this could be cleaned up a bit

        self.machine.config["mediacontroller"]["display_modules"]["modules"] = self.machine.config["mediacontroller"][
            "display_modules"
        ]["modules"].split(" ")

        for module in self.machine.config["mediacontroller"]["display_modules"]["modules"]:
            i = __import__("mpf.media_controller.display_modules." + module.split(".")[0], fromlist=[""])

            if i.is_used(self.machine.config):
                self.hw_module = getattr(i, module.split(".")[1])(self.machine)
                return  # we only support one type of hw_module at a time

    def _load_display_element_modules(self):

        # adds the available display elements to the list
        # creates asset managers for display assets that need them

        for module in self.machine.config["mediacontroller"]["display_modules"]["elements"]:

            display_element_module = __import__("mpf.media_controller.elements." + module, fromlist=[""])
            self.display_elements[module] = display_element_module

            if display_element_module.create_asset_manager:
                AssetManager(
                    machine=self.machine,
                    config_section=display_element_module.config_section,
                    path_string=(self.machine.config["mediacontroller"]["paths"][display_element_module.path_string]),
                    asset_class=display_element_module.asset_class,
                    asset_attribute=display_element_module.asset_attribute,
                    file_extensions=display_element_module.file_extensions,
                )

    def _load_fonts(self):
        if "fonts" not in self.machine.config:
            self.machine.config["fonts"] = dict()

        self.fonts = FontManager(self.machine, self.machine.config["fonts"])

    def _load_transitions(self):
        # This is tricky because we don't want to import them, rather, we just
        # want to create a list of them.

        # todo this could be cleaned up by adding module attributes which point
        # to the classes in the module

        for k, v in self.machine.config["mediacontroller"]["display_modules"]["transitions"].iteritems():
            __import__("mpf.media_controller.transitions." + v.split(".")[0])
            module = eval("mpf.media_controller.transitions." + v.split(".")[0])
            cls = v.split(".")[1]
            self.transitions[k] = (module, cls)

    def _load_decorators(self):
        # This is tricky because we don't want to import them, rather, we just
        # want to list them.

        # todo this could be cleaned up by adding module attributes which point
        # to the classes in the module

        for k, v in self.machine.config["mediacontroller"]["display_modules"]["decorators"].iteritems():
            __import__("mpf.media_controller.decorators." + v.split(".")[0])
            module = eval("mpf.media_controller.decorators." + v.split(".")[0])
            cls = v.split(".")[1]
            self.decorators[k] = (module, cls)

    def set_default_display(self, display_name):
        """Sets the default display.

        Args:
            display_name: String name of the display you'd like to set to be
                the default.

        Returns: None on success, False on failure.

        """

        if display_name in self.displays:
            self.default_display = self.displays[display_name]

        else:
            return False

    def show_slide(self, slide, display=None, **kwargs):
        """ Shows a slide. This method assumes the slide exists for this display
        already.

        Args:
            slide: The Slide object you want to show.
            display: The name of the display you'd like to show this slide on.
            **kwargs: Optional dictionary of settings which could add a
                transition. See the documentation on the SlideBuilder for all
                the options.
        """

        # figure out which display we're dealing with
        if not display:
            display = self.default_display
        else:
            display = self.displays[display]

        if "transition" in kwargs:
            transition_settings = kwargs["transition"]
            transition_type = kwargs["transition"].pop("type")

            display.transition(new_slide=display.slides[slide], transition=transition_type, **transition_settings)

    def remove_slides(self, removal_key):

        for display_obj in self.displays.values():
            display_obj.remove_slides_by_key(removal_key)
Exemple #4
0
class DisplayController(object):
    """Parent class for the Display Controller in MPF. There is only one of
    these per machine. It's responsible for interacting with the display,
    regardless of what type it is (DMD, LCD, alphanumeric, etc.).

    Args:
        machine: The main MachineController object.
    """

    def __init__(self, machine):
        self.machine = machine
        self.log = logging.getLogger("DisplayController")
        self.log.debug("Loading the DisplayController")

        self.delay = DelayManager()

        self.hw_module = None
        self.fonts = None

        self.machine.request_pygame()

        # todo move this? Should be in the DMD module?
        self.dmd_palette = [(0, 0, 0),
                            (1, 0, 0),
                            (2, 0, 0),
                            (3, 0, 0),
                            (4, 0, 0),
                            (5, 0, 0),
                            (6, 0, 0),
                            (7, 0, 0),
                            (8, 0, 0),
                            (9, 0, 0),
                            (10, 0, 0),
                            (11, 0, 0),
                            (12, 0, 0),
                            (13, 0, 0),
                            (14, 0, 0),
                            (15, 0, 0)] * 16

        self.transitions = dict()
        self.decorators = dict()
        self.display_elements = dict()

        self.displays = dict()
        self.default_display = None
        self.slide_builder = SlideBuilder(self.machine)

        # Register for events
        if 'window' in self.machine.config:
            self.machine.events.add_handler('init_phase_2',
                                            self.machine.get_window,
                                            priority=1000)

        self.machine.events.add_handler('init_phase_1',
                                        self._load_display_modules)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_display_element_modules)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_fonts)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_transitions)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_decorators)

        if 'slide_player' in self.machine.config:
            self.machine.events.add_handler('pygame_initialized',
                self._load_slide_builder_config)

    def _load_slide_builder_config(self):
        # This has to be a separate method since slide_builder.process config
        # returns an unloader method so we can't use it as an event handler
        self.slide_builder.process_config(
            self.machine.config['slide_player'], priority=0)

    def _load_display_modules(self):
        # Load the display modules as specified in the config files

        # todo this could be cleaned up a bit

        self.machine.config['media_controller']['display_modules']['modules'] = (
            self.machine.config['media_controller']['display_modules']
            ['modules'].split(' '))

        for module in (self.machine.config['media_controller']['display_modules']
                       ['modules']):
            i = __import__('mpf.media_controller.display_modules.' +
                           module.split('.')[0], fromlist=[''])

            if i.is_used(self.machine.config):
                self.hw_module = getattr(i, module.split('.')[1])(self.machine)
                return  # we only support one type of hw_module at a time

    def _load_display_element_modules(self):

        # adds the available display elements to the list
        # creates asset managers for display assets that need them

        for module in (self.machine.config['media_controller']['display_modules']
                       ['elements']):

            display_element_module = __import__('mpf.media_controller.elements.'
                                                + module, fromlist=[''])
            self.display_elements[module] = display_element_module

            if display_element_module.create_asset_manager:
                AssetManager(
                    machine=self.machine,
                    config_section=display_element_module.config_section,
                    path_string=(self.machine.config['media_controller']['paths']
                                  [display_element_module.path_string]),
                    asset_class=display_element_module.asset_class,
                    asset_attribute=display_element_module.asset_attribute,
                    file_extensions=display_element_module.file_extensions)

    def _load_fonts(self):
        if 'fonts' not in self.machine.config:
            self.machine.config['fonts'] = dict()

        self.fonts = FontManager(self.machine, self.machine.config['fonts'])

    def _load_transitions(self):
        # This is tricky because we don't want to import them, rather, we just
        # want to create a list of them.

        # todo this could be cleaned up by adding module attributes which point
        # to the classes in the module

        for k, v in (self.machine.config['media_controller']['display_modules']
                     ['transitions'].iteritems()):
            __import__('mpf.media_controller.transitions.' + v.split('.')[0])
            module = eval('mpf.media_controller.transitions.' + v.split('.')[0])
            cls = v.split('.')[1]
            self.transitions[k] = (module, cls)

    def _load_decorators(self):
        # This is tricky because we don't want to import them, rather, we just
        # want to list them.

        # todo this could be cleaned up by adding module attributes which point
        # to the classes in the module

        for k, v in (self.machine.config['media_controller']['display_modules']
                     ['decorators'].iteritems()):
            __import__('mpf.media_controller.decorators.' + v.split('.')[0])
            module = eval('mpf.media_controller.decorators.' + v.split('.')[0])
            cls = v.split('.')[1]
            self.decorators[k] = (module, cls)

    def set_default_display(self, display_name):
        """Sets the default display.

        Args:
            display_name: String name of the display you'd like to set to be
                the default.

        Returns: None on success, False on failure.

        """

        if display_name in self.displays:
            self.default_display = self.displays[display_name]

        else:
            return False
Exemple #5
0
class DisplayController(object):
    """Parent class for the Display Controller in MPF. There is only one of
    these per machine. It's responsible for interacting with the display,
    regardless of what type it is (DMD, LCD, alphanumeric, etc.).

    Args:
        machine: The main MachineController object.
    """
    def __init__(self, machine):
        self.machine = machine
        self.log = logging.getLogger("DisplayController")
        self.log.debug("Loading the DisplayController")

        self.delay = DelayManager()

        self.hw_module = None
        self.fonts = None

        self.machine.request_pygame()

        # todo move this? Should be in the DMD module?
        self.dmd_palette = [(0, 0, 0), (1, 0, 0), (2, 0, 0), (3, 0, 0),
                            (4, 0, 0), (5, 0, 0), (6, 0, 0), (7, 0, 0),
                            (8, 0, 0), (9, 0, 0), (10, 0, 0), (11, 0, 0),
                            (12, 0, 0), (13, 0, 0), (14, 0, 0),
                            (15, 0, 0)] * 16

        self.transitions = dict()
        self.decorators = dict()
        self.display_elements = dict()

        self.displays = dict()
        self.default_display = None
        self.slidebuilder = SlideBuilder(self.machine)

        # Register for events
        if 'window' in self.machine.config:
            self.machine.events.add_handler('init_phase_2',
                                            self.machine.get_window,
                                            priority=1000)

        self.machine.events.add_handler('init_phase_1',
                                        self._load_display_modules)
        self.machine.events.add_handler('init_phase_1',
                                        self._load_display_element_modules)
        self.machine.events.add_handler('init_phase_1', self._load_fonts)
        self.machine.events.add_handler('init_phase_1', self._load_transitions)
        self.machine.events.add_handler('init_phase_1', self._load_decorators)
        self.machine.events.add_handler('action_show_slide', self.show_slide)

        if 'slideplayer' in self.machine.config:
            self.machine.events.add_handler('pygame_initialized',
                                            self._load_slidebuilder_config)

    def _load_slidebuilder_config(self):
        # This has to be a separate method since slidebuilder.process config
        # returns an unloader method so we can't use it as an event handler
        self.slidebuilder.process_config(self.machine.config['slideplayer'],
                                         priority=0)

    def _load_display_modules(self):
        # Load the display modules as specified in the config files

        # todo this could be cleaned up a bit

        self.machine.config['mediacontroller']['display_modules'][
            'modules'] = (self.machine.config['mediacontroller']
                          ['display_modules']['modules'].split(' '))

        for module in (self.machine.config['mediacontroller']
                       ['display_modules']['modules']):
            i = __import__('mpf.media_controller.display_modules.' +
                           module.split('.')[0],
                           fromlist=[''])

            if i.is_used(self.machine.config):
                self.hw_module = getattr(i, module.split('.')[1])(self.machine)
                return  # we only support one type of hw_module at a time

    def _load_display_element_modules(self):

        # adds the available display elements to the list
        # creates asset managers for display assets that need them

        for module in (self.machine.config['mediacontroller']
                       ['display_modules']['elements']):

            display_element_module = __import__(
                'mpf.media_controller.elements.' + module, fromlist=[''])
            self.display_elements[module] = display_element_module

            if display_element_module.create_asset_manager:
                AssetManager(
                    machine=self.machine,
                    config_section=display_element_module.config_section,
                    path_string=(
                        self.machine.config['mediacontroller']['paths'][
                            display_element_module.path_string]),
                    asset_class=display_element_module.asset_class,
                    asset_attribute=display_element_module.asset_attribute,
                    file_extensions=display_element_module.file_extensions)

    def _load_fonts(self):
        if 'fonts' not in self.machine.config:
            self.machine.config['fonts'] = dict()

        self.fonts = FontManager(self.machine, self.machine.config['fonts'])

    def _load_transitions(self):
        # This is tricky because we don't want to import them, rather, we just
        # want to create a list of them.

        # todo this could be cleaned up by adding module attributes which point
        # to the classes in the module

        for k, v in (self.machine.config['mediacontroller']['display_modules']
                     ['transitions'].iteritems()):
            __import__('mpf.media_controller.transitions.' + v.split('.')[0])
            module = eval('mpf.media_controller.transitions.' +
                          v.split('.')[0])
            cls = v.split('.')[1]
            self.transitions[k] = (module, cls)

    def _load_decorators(self):
        # This is tricky because we don't want to import them, rather, we just
        # want to list them.

        # todo this could be cleaned up by adding module attributes which point
        # to the classes in the module

        for k, v in (self.machine.config['mediacontroller']['display_modules']
                     ['decorators'].iteritems()):
            __import__('mpf.media_controller.decorators.' + v.split('.')[0])
            module = eval('mpf.media_controller.decorators.' + v.split('.')[0])
            cls = v.split('.')[1]
            self.decorators[k] = (module, cls)

    def set_default_display(self, display_name):
        """Sets the default display.

        Args:
            display_name: String name of the display you'd like to set to be
                the default.

        Returns: None on success, False on failure.

        """

        if display_name in self.displays:
            self.default_display = self.displays[display_name]

        else:
            return False

    def show_slide(self, slide, display=None, **kwargs):
        """ Shows a slide. This method assumes the slide exists for this display
        already.

        Args:
            slide: The Slide object you want to show.
            display: The name of the display you'd like to show this slide on.
            **kwargs: Optional dictionary of settings which could add a
                transition. See the documentation on the SlideBuilder for all
                the options.
        """

        # figure out which display we're dealing with
        if not display:
            display = self.default_display
        else:
            display = self.displays[display]

        if 'transition' in kwargs:
            transition_settings = kwargs['transition']
            transition_type = kwargs['transition'].pop('type')

            display.transition(new_slide=display.slides[slide],
                               transition=transition_type,
                               **transition_settings)

    def remove_slides(self, removal_key):

        for display_obj in self.displays.values():
            display_obj.remove_slides_by_key(removal_key)