Skip to content

Commit

Permalink
Added triggers for widget animations
Browse files Browse the repository at this point in the history
This is better than the last commit since it works in widgets no matter
where they were defined. fixes #2 for real
  • Loading branch information
toomanybrians committed May 5, 2016
1 parent 6faef0d commit 9e4a1b1
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions mpfmc/_version.py
Original file line number Diff line number Diff line change
@@ -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__)
6 changes: 6 additions & 0 deletions mpfmc/config_collections/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions mpfmc/config_players/slide_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions mpfmc/config_players/widget_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
41 changes: 38 additions & 3 deletions mpfmc/tests/test_SlidePlayer.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 9e4a1b1

Please sign in to comment.