Example #1
0
    def __init__(self, app):
        SelectDialogTreeData.__init__(self)
        self.all_games_gi = 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 filter(select_func, self.all_games_gi):
                    continue
                gg.append(SelectGameNode(None, _(name), select_func))
            g.append(gg)
        select_mahjongg_game = lambda gi: gi.si.game_type == GI.GT_MAHJONGG
        gg = None
        if 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:
            select_func = lambda gi, games=games: gi.id in games
            if name is None or not 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:
            select_func = lambda gi, games=games: gi.id in games
            if name is None or not filter(select_func, self.all_games_gi):
                continue
            name = _("New games in v. ") + 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:
            select_func = lambda gi, games=games: gi.id in games
            if name is None or not 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 = filter(
            None,
            (
                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, "Variable redeals",
                                ##                                    lambda gi: gi.si.redeals == -2),
                                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,
            ))
Example #2
0
 def test_set_string2(self):
     a = UserList([1, 2, 3])
     inline_tools.inline('a[1] = std::complex<double>(1,1);', ['a'])
     assert_equal(sys.getrefcount(a[1]), 2)
     assert_equal(a[1], 1 + 1j)
Example #3
0
 def setUp(self):
     self.it = iter(UserList(range(n)))
Example #4
0
 def test_delitem(self):
     u = UserList([0, 1])
     del u[1]
     del u[0]
     self.assertRaises(IndexError, u.__delitem__, 0)
Example #5
0
 def test_set_char(self):
     a = UserList([1, 2, 3])
     inline_tools.inline('a[1] = "bubba";', ['a'])
     assert_equal(sys.getrefcount(a[1]), 2)
     assert_equal(a[1], 'bubba')
Example #6
0
 def test_imul(self):
     u = UserList((0, 1))
     u *= 3
     self.assertEqual(u, [0, 1, 0, 1, 0, 1])
Example #7
0
 def test_getitem(self):
     u = UserList([0, 1, 2])
     for i in xrange(len(u)):
         self.assertEqual(u[i], i)
Example #8
0
print 'chr'
if chr(32) != ' ': raise TestFailed, 'chr(32)'
if chr(65) != 'A': raise TestFailed, 'chr(65)'
if chr(97) != 'a': raise TestFailed, 'chr(97)'

# cmp
print 'cmp'
if cmp(-1, 1) != -1: raise TestFailed, 'cmp(-1, 1)'
if cmp(1, -1) != 1: raise TestFailed, 'cmp(1, -1)'
if cmp(1, 1) != 0: raise TestFailed, 'cmp(1, 1)'
# verify that circular objects are handled
a = []; a.append(a)
b = []; b.append(b)
from UserList import UserList
c = UserList(); c.append(c)
if cmp(a, b) != 0: raise TestFailed, "cmp(%s, %s)" % (a, b)
if cmp(b, c) != 0: raise TestFailed, "cmp(%s, %s)" % (b, c)
if cmp(c, a) != 0: raise TestFailed, "cmp(%s, %s)" % (c, a)
if cmp(a, c) != 0: raise TestFailed, "cmp(%s, %s)" % (a, c)
# okay, now break the cycles
a.pop(); b.pop(); c.pop()

print 'coerce'
if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
if coerce(1, 1L) != (1L, 1L): raise TestFailed, 'coerce(1, 1L)'
if fcmp(coerce(1L, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1L, 1.1)'

try: coerce(0.5, long("12345" * 1000))
except OverflowError: pass
else: raise TestFailed, 'coerce(0.5, long("12345" * 1000))'
Example #9
0
 def test_contains(self):
     u = UserList([0, 1, 2])
     for i in u:
         self.assert_(i in u)
     for i in min(u)-1, max(u)+1:
         self.assert_(i not in u)
Example #10
0
# verify softspace is writable
f.softspace = softspace  # merely shouldn't blow up

# verify the others aren't
for attr in 'name', 'mode', 'closed':
    try:
        setattr(f, attr, 'oops')
    except TypeError:
        pass
    else:
        raise TestFailed('expected TypeError setting file attr %r' % attr)
f.close()

# verify writelines with instance sequence
l = UserList(['1', '2'])
f = open(TESTFN, 'wb')
f.writelines(l)
f.close()
f = open(TESTFN, 'rb')
buf = f.read()
f.close()
verify(buf == '12')

# verify readinto
a = array('c', 'x' * 10)
f = open(TESTFN, 'rb')
n = f.readinto(a)
f.close()
verify(buf == a.tostring()[:n])
Example #11
0
 def setUp(self):
     self.list = UserList()
Example #12
0
 def test_iadd(self):
     super(UserListTest, self).test_iadd()
     u = [0, 1]
     u += UserList([0, 1])
     self.assertEqual(u, [0, 1, 0, 1])
Example #13
0

# Use check instead of assert so -O doesn't render the
# test useless.
def check(predicate, msg):
    if not predicate:
        raise TestFailed(msg + " failed")


l0 = []
l1 = [0]
l2 = [0, 1]

# Test constructors

u = UserList()
u0 = UserList(l0)
u1 = UserList(l1)
u2 = UserList(l2)

uu = UserList(u)
uu0 = UserList(u0)
uu1 = UserList(u1)
uu2 = UserList(u2)

v = UserList(tuple(u))


class OtherList:
    def __init__(self, initlist):
        self.__data = initlist
Example #14
0
       i = obj.mcall("inc",args);
       result[1] = i;

       obj.set_attr("val",5);
       i = obj.attr("val");
       result[2] = i;

       return_val = result;
       """

print('initial, inc(2), set(5)/get:', weave.inline(code,['obj']))

#----------------------------------------------------------------------------
# indexing of values.
#----------------------------------------------------------------------------
from UserList import UserList
obj = UserList([1,[1,2],"hello"])
code = """
       int i;
       // find obj length and access each of its items
       //std::cout << "UserList items: ";
       //for(i = 0; i < obj.length(); i++)
       //    std::cout << obj[i].str() << " ";
       //std::cout << std::endl;
       // assign new values to each of its items
       for(i = 0; i < obj.length(); i++)
           obj[i] = "goodbye";
       """
weave.inline(code,['obj'])
print("obj with new values:", obj)
Example #15
0
 def test_sort(self):
     u = UserList([1, 0])
     u.sort()
     self.assertEqual(u, [0, 1])
Example #16
0
 def test_add_specials(self):
     u = UserList("spam")
     u2 = u + "eggs"
     self.assertEqual(u2, list("spameggs"))
Example #17
0
 def test_slice(self):
     u = UserList("spam")
     u[:2] = "h"
     self.assertEqual(u, list("ham"))
Example #18
0
 def test_radd_specials(self):
     u = UserList("eggs")
     u2 = "spam" + u
     self.assertEqual(u2, list("spameggs"))
     u2 = u.__radd__(UserList("spam"))
     self.assertEqual(u2, list("spameggs"))
Example #19
0
    def test_constructors(self):
        l0 = []
        l1 = [0]
        l2 = [0, 1]

        u = UserList()
        u0 = UserList(l0)
        u1 = UserList(l1)
        u2 = UserList(l2)

        uu = UserList(u)
        uu0 = UserList(u0)
        uu1 = UserList(u1)
        uu2 = UserList(u2)

        v = UserList(tuple(u))
        class OtherList:
            def __init__(self, initlist):
                self.__data = initlist
            def __len__(self):
                return len(self.__data)
            def __getitem__(self, i):
                return self.__data[i]
        v0 = UserList(OtherList(u0))
        vv = UserList("this is also a sequence")
Example #20
0
 def test_append(self):
     u = UserList((0, ))
     u.append(1)
     self.assertEqual(u, [0, 1])
Example #21
0
 def test_setitem(self):
     u = UserList([0, 1])
     u[0] = 0
     u[1] = 100
     self.assertEqual(u, [0, 100])
     self.assertRaises(IndexError, u.__setitem__, 2, 200)
Example #22
0
 def test_insert(self):
     u = UserList((0, 1))
     u.insert(0, -1)
     self.assertEqual(u, [-1, 0, 1])
Example #23
0
 def test_set_double(self):
     a = UserList([1, 2, 3])
     inline_tools.inline("a[1] = 123.0;", ['a'])
     assert_equal(sys.getrefcount(a[1]), 2)
     assert_equal(a[1], 123.0)
Example #24
0
 def test_pop(self):
     u = UserList((-1, 0, 1))
     u.pop()
     self.assertEqual(u, [-1, 0])
     u.pop(0)
     self.assertEqual(u, [0])
Example #25
0
 def test_set_string1(self):
     a = UserList([1, 2, 3])
     inline_tools.inline('a[1] = std::string("sissy");', ['a'])
     assert_equal(sys.getrefcount(a[1]), 2)
     assert_equal(a[1], 'sissy')
Example #26
0
 def test_remove(self):
     u = UserList((0, 1))
     u.remove(1)
     self.assertEqual(u, [0])
Example #27
0
 def testWritelinesIntegersUserList(self):
     # verify writelines with integers in UserList
     l = UserList([1, 2, 3])
     self.assertRaises(TypeError, self.f.writelines, l)
Example #28
0
 def test_count(self):
     u = UserList((0, 1))*3
     self.assertEqual(u.count(0), 3)
     self.assertEqual(u.count(1), 3)
     self.assertEqual(u.count(2), 0)
Example #29
0
 def setUp(self):
     self.it = reversed(UserList(range(n)))
Example #30
0
 def test_precomputed(self):
     for func, data, elem, expected in self.precomputedCases:
         self.assertEqual(func(data, elem), expected)
         self.assertEqual(func(UserList(data), elem), expected)