예제 #1
0
파일: baseio.py 프로젝트: nocarryr/tallypi
    async def bind_to_tally(self, inp: BaseInput, tally: Tally):
        """Update current state and subscribe to changes from the given
        :class:`~tslumd.tallyobj.Tally`

        Calls :meth:`~BaseIO.on_receiver_tally_change` and binds tally update
        events to it
        """

        loop = asyncio.get_event_loop()
        tally_key = tally.id
        if tally_key not in self.bound_input_tally_keys:
            self.bound_input_tally_keys[tally_key] = set()
        self.bound_input_tally_keys[tally_key].add(inp.id)
        tally.bind_async(loop, on_update=self.on_receiver_tally_change)
        props_changed = ('rh_tally', 'txt_tally', 'lh_tally')
        await self.on_receiver_tally_change(tally, props_changed=props_changed)
예제 #2
0
async def test_update_event(faker):
    loop = asyncio.get_event_loop()
    listener = Listener()

    tally = Tally(0)
    tally.bind_async(loop, on_update=listener.callback)
    tally.text = 'foo'

    _, props_changed = await listener.get()
    assert set(props_changed) == set(['text'])

    d = dict(rh_tally=TallyColor.RED, txt_tally=TallyColor.GREEN, lh_tally=TallyColor.AMBER)
    tally.update(**d)

    _, props_changed = await listener.get()
    assert set(props_changed) == set(d.keys())


    disp = Display(index=0, text=tally.text)
    tally.update_from_display(disp)
    assert disp == tally

    _, props_changed = await listener.get()
    assert set(props_changed) == set(['rh_tally', 'txt_tally', 'lh_tally'])


    for tally_type, color in iter_tally_types_and_colors():
        attr = tally_type.name
        should_change = getattr(tally, attr) != color
        # print(f'{tally_type=}, {color=}, {should_change=}')
        setattr(tally, attr, color)
        if should_change:
            _, props_changed = await listener.get()
            assert set(props_changed) == set([attr])
        else:
            await asyncio.sleep(.01)
            assert listener.results.empty()