Пример #1
0
def unmatched_sconfs(unmatched_ttypes):
    return [[
        SingleTallyConfig(screen_index=0,
                          tally_index=0,
                          tally_type=TallyType.from_str(ttype))
        for ttype in ttypes
    ] for ttypes in unmatched_ttypes]
Пример #2
0
 def __getitem__(self, key: StrOrTallyType) -> TallyColor:
     if not isinstance(key, TallyType):
         key = TallyType.from_str(key)
     if key.is_iterable:
         color = TallyColor.OFF
         for tt in key:
             color |= getattr(self, tt.name)
         return color
     return getattr(self, key.name)
Пример #3
0
def test_single_tally_matching():
    tally_type = TallyType.rh_tally
    for i in range(10):
        all_screens = SingleTallyConfig(
            screen_index=None,
            tally_index=i,
            tally_type=tally_type,
        )
        assert all_screens.matches_screen(0xffff)

        for j in range(10):
            assert all_screens.matches_screen(j)

            tconf0 = SingleTallyConfig(
                screen_index=j,
                tally_index=i,
                tally_type=tally_type,
            )
            tconf1 = SingleTallyConfig(
                screen_index=j,
                tally_index=i + 1,
                tally_type=tally_type,
            )
            tconf2 = SingleTallyConfig(
                screen_index=j + 1,
                tally_index=i,
                tally_type=tally_type,
            )
            tconfs = [tconf0, tconf1, tconf2]

            for tconf in tconfs:
                assert tconf.matches(tconf.id, tconf.tally_type)
                assert tconf.matches(
                    tconf.id, tconf.tally_type, return_matched=True) is tconf
                assert tconf.matches(tconf,
                                     tally_type=TallyType.from_str('rh|lh'))
                assert not tconf.matches(tconf, tally_type=TallyType.txt_tally)
                assert tconf.matches_screen(0xffff)
                assert tconf.matches_screen(all_screens)
                assert all_screens.matches_screen(tconf)
                if tconf.tally_index == i:
                    assert tconf.matches(all_screens)
                    assert tconf.matches(all_screens.id,
                                         all_screens.tally_type)
                else:
                    assert not tconf.matches(all_screens)
                    assert not tconf.matches(all_screens.id,
                                             all_screens.tally_type)

            assert tconf0.matches_screen(tconf1)
            assert tconf0.matches_screen(j)
            assert not tconf0.matches_screen(tconf2)
            assert not tconf0.matches_screen(j + 1)
            assert not tconf0.matches(tconf1)
            assert not tconf0.matches(tconf1.id, tconf1.tally_type)
            assert not tconf0.matches(tconf2)
            assert not tconf0.matches(tconf2.id, tconf2.tally_type)
Пример #4
0
 def __setitem__(self, key: StrOrTallyType, value: StrOrTallyColor):
     if not isinstance(key, TallyType):
         key = TallyType.from_str(key)
     if not isinstance(value, TallyColor):
         value = TallyColor.from_str(value)
     if key.is_iterable:
         for tt in key:
             setattr(self, tt.name, value)
     else:
         setattr(self, key.name, value)
Пример #5
0
 def get_init_options(cls) -> Tuple[Option]:
     tt_choices = tuple((tt.name for tt in TallyType))
     return (
         Option(name='tally_index', type=int, required=True, title='Index'),
         Option(
             name='tally_type', type=str, required=True, choices=tt_choices,
             serialize_cb=lambda x: x.to_str(),
             validate_cb=lambda x: TallyType.from_str(x),
             title='TallyType',
         ),
         TallyColorOption,
         Option(name='screen_index', type=int, required=False, title='Screen'),
         Option(name='name', type=str, required=False, default='', title='Name'),
     )
Пример #6
0
 async def on_receiver_tally_change(self, tally: Tally,
                                    props_changed: Set[str], **kwargs):
     changed = set()
     for prop in props_changed:
         if prop not in TallyType.__members__:
             continue
         ttype = TallyType.from_str(prop)
         pixel = self.tally_type_map.get(tally.id + (ttype, ))
         color = self.get_merged_tally(tally, ttype)
         if color == self.get(pixel):
             continue
         self[pixel] = color
         changed.add(pixel)
     await self.queue_update(*changed)
Пример #7
0
 async def wait_for_rx(tally_type):
     tally_types = set()
     if not isinstance(tally_type, TallyType):
         tally_type = TallyType.from_str(tally_type)
     if tally_type.is_iterable:
         for tt in tally_type:
             tally_types.add(tt.name)
     else:
         tally_types.add(tally_type.name)
     props = set()
     for _ in range(len(tally_types)):
         evt_args, evt_kwargs = await tally_listener.get()
         props |= evt_args[1]
         if props == tally_types:
             break
     assert props == tally_types
Пример #8
0
 def from_dict(cls, d: Dict) -> 'SingleTallyConfig':
     kw = d.copy()
     if not isinstance(kw['tally_type'], TallyType):
         kw['tally_type'] = TallyType.from_str(kw['tally_type'])
     return super().from_dict(kw)