From 9e4a1b1ec60a8908532fc358cb26b26e70f6a34a Mon Sep 17 00:00:00 2001 From: toomanybrians Date: Wed, 4 May 2016 21:23:57 -0700 Subject: [PATCH] Added triggers for widget animations This is better than the last commit since it works in widgets no matter where they were defined. fixes #2 for real --- mpfmc/_version.py | 4 +- mpfmc/config_collections/widget.py | 6 +++ mpfmc/config_players/slide_player.py | 4 -- mpfmc/config_players/widget_player.py | 1 + .../config/test_slide_player.yaml | 27 ++++++++++++ mpfmc/tests/test_SlidePlayer.py | 41 +++++++++++++++++-- 6 files changed, 74 insertions(+), 9 deletions(-) diff --git a/mpfmc/_version.py b/mpfmc/_version.py index 10d24e29..d932a7b8 100644 --- a/mpfmc/_version.py +++ b/mpfmc/_version.py @@ -1,7 +1,7 @@ -__version__ = '0.30.0.dev371' +__version__ = '0.30.0.dev373' __bcp_version__ = '1.0' __config_version__ = '4' -__mpf_version_required__ = '0.30.0.dev1282' +__mpf_version_required__ = '0.30.0.dev1310' version = "MPF-MC v{} (config_version={}, BCP v{}, Requires MPF v{})".format( __version__, __config_version__, __bcp_version__, __mpf_version_required__) diff --git a/mpfmc/config_collections/widget.py b/mpfmc/config_collections/widget.py index 575943a3..d892721f 100644 --- a/mpfmc/config_collections/widget.py +++ b/mpfmc/config_collections/widget.py @@ -94,6 +94,12 @@ def process_animations(self, config): for event_name, event_settings in config.items(): + # make sure the event_name is registered as a trigger event so MPF + # will send those events as triggers via BCP + if event_name != 'entrance': + self.mc.bcp_processor.send(bcp_command='register_trigger', + event=event_name) + # str means it's a list of named animations if type(event_settings) is str: event_settings = Util.string_to_list(event_settings) diff --git a/mpfmc/config_players/slide_player.py b/mpfmc/config_players/slide_player.py index 09f9f6a4..414a53f8 100644 --- a/mpfmc/config_players/slide_player.py +++ b/mpfmc/config_players/slide_player.py @@ -399,10 +399,6 @@ def process_animations(self, config): config[event_name] = new_list - # make sure the event_name is registered as a trigger event so MPF - # will send those events as triggers via BCP - self.machine.bcp.add_registered_trigger_event(event_name) - return config def process_animation(self, config, mode=None): diff --git a/mpfmc/config_players/widget_player.py b/mpfmc/config_players/widget_player.py index 4a33cc6f..f008de86 100644 --- a/mpfmc/config_players/widget_player.py +++ b/mpfmc/config_players/widget_player.py @@ -11,6 +11,7 @@ class MpfWidgetPlayer(PluginPlayer): """ config_file_section = 'widget_player' + show_section = 'widgets' def play(self, settings, mode=None, play_kwargs=None, **kwargs): diff --git a/mpfmc/tests/machine_files/slide_player/config/test_slide_player.yaml b/mpfmc/tests/machine_files/slide_player/config/test_slide_player.yaml index 4ab3ad88..b2b9cbd0 100644 --- a/mpfmc/tests/machine_files/slide_player/config/test_slide_player.yaml +++ b/mpfmc/tests/machine_files/slide_player/config/test_slide_player.yaml @@ -98,6 +98,19 @@ slides: height: 300 color: lime transition: move_in + machine_slide_10: + widgets: + - type: text + text: WIDGET 1 + animations: + flash_widget_1: + - property: opacity + value: 1 + duration: .25s + - property: opacity + value: 0 + duration: .25s + repeat: yes slide_player: show_slide_1: machine_slide_1 @@ -187,3 +200,17 @@ slide_player: slide2_expire_1s: machine_slide_2: expire: 1s + show_slide_with_animations: + my_slide: + widgets: + - type: text + text: WIDGET 1 + animations: + flash_widget_2: + - property: opacity + value: 1 + duration: .25s + - property: opacity + value: 0 + duration: .25s + repeat: yes diff --git a/mpfmc/tests/test_SlidePlayer.py b/mpfmc/tests/test_SlidePlayer.py index e9b68cc2..aaaa5786 100644 --- a/mpfmc/tests/test_SlidePlayer.py +++ b/mpfmc/tests/test_SlidePlayer.py @@ -1,11 +1,12 @@ -import json - from kivy.uix.screenmanager import WipeTransition, FadeTransition -from mpf.core.bcp import decode_command_string from mpf.core.config_player import ConfigPlayer from mpfmc.tests.MpfMcTestCase import MpfMcTestCase from mpfmc.transitions.move_in import MoveInTransition +from mpf.tests.MpfTestCase import MpfTestCase + +import mpfmc.core +import os class TestSlidePlayer(MpfMcTestCase): @@ -483,3 +484,37 @@ def test_remove_already_removed_slide(self): slide1.remove() self.advance_time() + + def test_animation_triggers(self): + bcp_command = ('register_trigger', None, {'event': 'flash_widget_1'}) + self.assertIn(bcp_command, self.sent_bcp_commands) + + bcp_command = ('register_trigger', None, {'event': 'flash_widget_2'}) + self.assertIn(bcp_command, self.sent_bcp_commands) + + +class TestMpfSlidePlayer(MpfTestCase): + + # runs the MPF tests (and not the MPF-MC ones) to test the MPF side of the + # slide player plugin + + def __init__(self, methodName): + super().__init__(methodName) + # remove config patch which disables bcp + del self.machine_config_patches['bcp'] + + def getAbsoluteMachinePath(self): + # override the base to we set the patch based on the mpfmc location + return os.path.abspath(os.path.join( + mpfmc.core.__path__[0], os.pardir, self.getMachinePath())) + + def get_enable_plugins(self): + return True + + def getConfigFile(self): + return 'test_slide_player.yaml' + + def getMachinePath(self): + return 'tests/machine_files/slide_player/' + + # todo add tests