Example #1
0
 def __init__(self, cls, initial_list=None):
     UserList.__init__(self)
     if initial_list:
         for item in initial_list:
             if isinstance(item, cls):
                 self.data.append(item)
             elif isinstance(item, dict):
                 self.data.append(cls.from_json(item))
 def __init__(self, cls, initial_list=None):
     UserList.__init__(self)
     if initial_list:
         for item in initial_list:
             if isinstance(item, cls):
                 self.data.append(item)
             elif isinstance(item, dict):
                 self.data.append(cls.from_json(item))
Example #3
0
    def __init__(self, app):
        SelectDialogTreeData.__init__(self)
        self.all_games_gi = list(
            map(app.gdb.get, app.gdb.getGamesIdSortedByName()))
        self.no_games = [
            SelectGameLeaf(None, None, _("(no games)"), None),
        ]
        #
        s_by_type = s_oriental = s_special = s_original = s_contrib = \
            s_mahjongg = None
        g = []
        for data in (
                GI.SELECT_GAME_BY_TYPE,
                GI.SELECT_ORIENTAL_GAME_BY_TYPE,
                GI.SELECT_SPECIAL_GAME_BY_TYPE,
                GI.SELECT_ORIGINAL_GAME_BY_TYPE,
                GI.SELECT_CONTRIB_GAME_BY_TYPE,
        ):
            gg = []
            for name, select_func in data:
                if name is None or not list(
                        filter(select_func, self.all_games_gi)):
                    continue
                gg.append(SelectGameNode(None, _(name), select_func))
            g.append(gg)

        def select_mahjongg_game(gi):
            return gi.si.game_type == GI.GT_MAHJONGG

        gg = None
        if list(filter(select_mahjongg_game, self.all_games_gi)):
            gg = SelectGameNode(None, _("Mahjongg Games"),
                                select_mahjongg_game)
        g.append(gg)
        if g[0]:
            s_by_type = SelectGameNode(None,
                                       _("French Games"),
                                       tuple(g[0]),
                                       expanded=1)
        if g[1]:
            s_oriental = SelectGameNode(None, _("Oriental Games"), tuple(g[1]))
        if g[2]:
            s_special = SelectGameNode(None, _("Special Games"), tuple(g[2]))
        if g[3]:
            s_original = SelectGameNode(None, _("Original Games"), tuple(g[3]))
        # if g[4]:
        #   s_contrib = SelectGameNode(None, "Contributed Games", tuple(g[4]))
        if g[5]:
            s_mahjongg = g[5]
        #
        s_by_compatibility, gg = None, []
        for name, games in GI.GAMES_BY_COMPATIBILITY:

            def select_func(gi, games=games):
                return gi.id in games

            if name is None or not list(filter(select_func,
                                               self.all_games_gi)):
                continue
            gg.append(SelectGameNode(None, name, select_func))
        if 1 and gg:
            s_by_compatibility = SelectGameNode(None, _("by Compatibility"),
                                                tuple(gg))
        #
        s_by_pysol_version, gg = None, []
        for name, games in GI.GAMES_BY_PYSOL_VERSION:

            def select_func(gi, games=games):
                return gi.id in games

            if name is None or not list(filter(select_func,
                                               self.all_games_gi)):
                continue
            name = _("New games in v. %(version)s") % {'version': name}
            gg.append(SelectGameNode(None, name, select_func))
        if 1 and gg:
            s_by_pysol_version = SelectGameNode(None, _("by PySol version"),
                                                tuple(gg))
        s_by_inventors, gg = None, []
        for name, games in GI.GAMES_BY_INVENTORS:

            def select_func(gi, games=games):
                return gi.id in games

            if name is None or not list(filter(select_func,
                                               self.all_games_gi)):
                continue
            gg.append(SelectGameNode(None, name, select_func))
        if 1 and gg:
            s_by_inventors = SelectGameNode(None, _("by Inventors"), tuple(gg))
        #
        ul_alternate_names = UserList(
            list(app.gdb.getGamesTuplesSortedByAlternateName()))
        #
        self.rootnodes = [
            _f for _f in (
                SelectGameNode(None, _("All Games"), None, expanded=0),
                SelectGameNode(None, _("Alternate Names"), ul_alternate_names),
                SelectGameNode(None, _("Popular Games"),
                               lambda gi: gi.si.game_flags & GI.GT_POPULAR),
                s_by_type,
                s_mahjongg,
                s_oriental,
                s_special,
                SelectGameNode(None, _("Custom Games"),
                               lambda gi: gi.si.game_type == GI.GT_CUSTOM),
                SelectGameNode(None, _('by Skill Level'), (
                    SelectGameNode(None, _('Luck only'),
                                   lambda gi: gi.skill_level == GI.SL_LUCK),
                    SelectGameNode(
                        None, _('Mostly luck'),
                        lambda gi: gi.skill_level == GI.SL_MOSTLY_LUCK),
                    SelectGameNode(None, _('Balanced'), lambda gi: gi.
                                   skill_level == GI.SL_BALANCED),
                    SelectGameNode(
                        None, _('Mostly skill'),
                        lambda gi: gi.skill_level == GI.SL_MOSTLY_SKILL),
                    SelectGameNode(None, _('Skill only'),
                                   lambda gi: gi.skill_level == GI.SL_SKILL),
                )),
                SelectGameNode(None, _("by Game Feature"), (
                    SelectGameNode(None, _("by Number of Cards"), (
                        SelectGameNode(None, _("32 cards"),
                                       lambda gi: gi.si.ncards == 32),
                        SelectGameNode(None, _("48 cards"),
                                       lambda gi: gi.si.ncards == 48),
                        SelectGameNode(None, _("52 cards"),
                                       lambda gi: gi.si.ncards == 52),
                        SelectGameNode(None, _("64 cards"),
                                       lambda gi: gi.si.ncards == 64),
                        SelectGameNode(None, _("78 cards"),
                                       lambda gi: gi.si.ncards == 78),
                        SelectGameNode(None, _("104 cards"),
                                       lambda gi: gi.si.ncards == 104),
                        SelectGameNode(None, _("144 cards"),
                                       lambda gi: gi.si.ncards == 144),
                        SelectGameNode(
                            None, _("Other number"), lambda gi: gi.si.ncards
                            not in (32, 48, 52, 64, 78, 104, 144)),
                    )),
                    SelectGameNode(None, _("by Number of Decks"), (
                        SelectGameNode(None, _("1 deck games"),
                                       lambda gi: gi.si.decks == 1),
                        SelectGameNode(None, _("2 deck games"),
                                       lambda gi: gi.si.decks == 2),
                        SelectGameNode(None, _("3 deck games"),
                                       lambda gi: gi.si.decks == 3),
                        SelectGameNode(None, _("4 deck games"),
                                       lambda gi: gi.si.decks == 4),
                    )),
                    SelectGameNode(None, _("by Number of Redeals"), (
                        SelectGameNode(None, _("No redeal"),
                                       lambda gi: gi.si.redeals == 0),
                        SelectGameNode(None, _("1 redeal"),
                                       lambda gi: gi.si.redeals == 1),
                        SelectGameNode(None, _("2 redeals"),
                                       lambda gi: gi.si.redeals == 2),
                        SelectGameNode(None, _("3 redeals"),
                                       lambda gi: gi.si.redeals == 3),
                        SelectGameNode(None, _("Unlimited redeals"),
                                       lambda gi: gi.si.redeals == -1),
                        SelectGameNode(
                            None, _("Other number of redeals"),
                            lambda gi: gi.si.redeals not in (-1, 0, 1, 2, 3)),
                    )),
                    s_by_compatibility,
                )),
                s_by_pysol_version,
                s_by_inventors,
                SelectGameNode(None, _("Other Categories"), (
                    SelectGameNode(
                        None, _("Games for Children (very easy)"),
                        lambda gi: gi.si.game_flags & GI.GT_CHILDREN),
                    SelectGameNode(None, _("Games with Scoring"),
                                   lambda gi: gi.si.game_flags & GI.GT_SCORE),
                    SelectGameNode(
                        None, _("Games with Separate Decks"),
                        lambda gi: gi.si.game_flags & GI.GT_SEPARATE_DECKS),
                    SelectGameNode(None, _("Open Games (all cards visible)"),
                                   lambda gi: gi.si.game_flags & GI.GT_OPEN),
                    SelectGameNode(None, _("Relaxed Variants"), lambda gi: gi.
                                   si.game_flags & GI.GT_RELAXED),
                )),
                s_original,
                s_contrib,
            ) if _f
        ]
Example #4
0
 def __init__(self, prefix=None, suffix=None):
     UserList.__init__(self)
     self.prefix = prefix
     self.suffix = suffix
Example #5
0
 def __init__(self, value=None, tag=None):
     BERStructured.__init__(self, tag)
     assert value is not None
     UserList.__init__(self, value)
Example #6
0
 def __init__(self, *args, **kwargs):
     PdfType.__init__(self)
     UserList.__init__(self, *args, **kwargs)
Example #7
0
 def pop(self, *args):
     UserList.pop(*args)
     self._update()
Example #8
0
 def __init__(self, *args, **kwargs):
     PdfType.__init__(self)
     UserList.__init__(self, *args, **kwargs)
Example #9
0
 def remove(self, *args):
     UserList.remove(*args)
     self._update()
Example #10
0
 def insert(self, *args):
     UserList.insert(*args)
     self._update()
Example #11
0
 def append(self, value):
     UserList.append(self, value)
     self._update()
Example #12
0
 def __setitem__(self, key, value):
     UserList.__setitem__(self, key, value)
     self._update()
Example #13
0
 def __init__(self, name='', *args):
     UserList.__init__(self, *args)
     self.__name__ = name
     if args:
         self._update()