Exemple #1
0
def all_games(sort_by='id'):
    # rules_dir = 'rules'
    print('''<table border="2">
<tr><th>ID</th><th>Name</th><th>Alternate names</th><th>Type</th></tr>
''')

    if sort_by == 'id':
        get_games_func = GAME_DB.getGamesIdSortedById
    else:
        get_games_func = GAME_DB.getGamesIdSortedByName

    for id in get_games_func():
        gi = GAME_DB.get(id)
        if not gi.rules_filename:
            rules_fn = getGameRulesFilename(gi.name)
        else:
            rules_fn = gi.rules_filename
        gt = CSI.TYPE_NAME[gi.category]
        if gt == 'French':
            gt = 'French (%s)' % GAME_BY_TYPE[gi.si.game_type]
        name = gi.name.encode('utf-8')
        altnames = '<br>'.join(gi.altnames).encode('utf-8')
        fn = os.path.join(rules_dir, rules_fn)
        if 1 and os.path.exists(fn):
            print('''<tr><td>%s</td><td>
<a href="%s" title="Rules for this game">%s</a>
</td><td>%s</td><td>%s</td></tr>
''' % (id, fn, name, altnames, gt))
        else:
            print('''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>
''' % (id, name, altnames, gt))
    print('</table>')
Exemple #2
0
def create_html(sort_by):
    if html_mode != 'bare':
        print('''<!DOCTYPE html><html lang="en-US">
<head>
  <title>PySolFC - List of solitaire games</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
''')
    print('<strong>Total games: %d</strong>' %
          len(GAME_DB.getGamesIdSortedById()))
    print('<section>')
    print('<h2>Categories</h2>')
    by_category()
    print('</section>')
    print('<section>')
    print('<h2>Types</h2>')
    by_type()
    print('</section>')
    # print '<h2>All games</h2>'
    print('<section>')
    print('<h2>The games</h2>')
    all_games(sort_by)
    print('</section>')
    if html_mode != 'bare':
        print('</body></html>')
Exemple #3
0
def get_text():
    # get_games_func = GAME_DB.getGamesIdSortedById
    get_games_func = GAME_DB.getGamesIdSortedByName

    games_list = {}  # for unique
    for id in get_games_func():
        gi = GAME_DB.get(id)
        games_list[gi.name] = ''
        if gi.name != gi.short_name:
            games_list[gi.short_name] = ''
        for n in gi.altnames:
            games_list[n] = ''
    games_list = list(games_list.keys())
    games_list.sort()
    print('''\
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PySol 0.0.1\\n"
"POT-Creation-Date: %s\\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <*****@*****.**>\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=CHARSET\\n"
"Content-Transfer-Encoding: ENCODING\\n"
"Generated-By: %s 0.1\\n"

''' % (time.asctime(), sys.argv[0]))
    for g in games_list:
        print('msgid "%s"\nmsgstr ""\n' % g)
Exemple #4
0
def get_text():
    # get_games_func = GAME_DB.getGamesIdSortedById
    get_games_func = GAME_DB.getGamesIdSortedByName

    games_list = {}  # for unique
    for id in get_games_func():
        gi = GAME_DB.get(id)
        games_list[gi.name] = ''
        if gi.name != gi.short_name:
            games_list[gi.short_name] = ''
        for n in gi.altnames:
            games_list[n] = ''
    games_list = list(games_list.keys())
    games_list.sort()
    print('''\
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: PySol 0.0.1\\n"
"POT-Creation-Date: %s\\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n"
"Language-Team: LANGUAGE <*****@*****.**>\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=CHARSET\\n"
"Content-Transfer-Encoding: ENCODING\\n"
"Generated-By: %s 0.1\\n"

''' % (time.asctime(), sys.argv[0]))
    for g in games_list:
        print('msgid "%s"\nmsgstr ""\n' % g)
Exemple #5
0
def all_games(sort_by='id'):
    # rules_dir = 'rules'
    print('''<table border="2">
<tr><th>ID</th><th>Name</th><th>Alternate names</th><th>Type</th></tr>
''')

    if sort_by == 'id':
        get_games_func = GAME_DB.getGamesIdSortedById
    else:
        get_games_func = GAME_DB.getGamesIdSortedByName

    for id in get_games_func():
        gi = GAME_DB.get(id)
        if not gi.rules_filename:
            rules_fn = getGameRulesFilename(gi.name)
        else:
            rules_fn = gi.rules_filename
        gt = CSI.TYPE_NAME[gi.category]
        if gt == 'French':
            gt = 'French (%s)' % GAME_BY_TYPE[gi.si.game_type]
        name = gi.name
        altnames = '<br>'.join(gi.altnames)
        fn = os.path.join(rules_dir, rules_fn)
        if 1 and os.path.exists(fn):
            print('''<tr><td>%s</td><td>
<a href="%s" title="Rules for this game">%s</a>
</td><td>%s</td><td>%s</td></tr>
''' % (id, fn, name, altnames, gt))
        else:
            print('''<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>
''' % (id, name, altnames, gt))
    print('</table>')
Exemple #6
0
def by_category():
    games = GAME_DB.getGamesIdSortedById()
    games_by_cat = {}
    for id in games:
        gi = GAME_DB.get(id)
        gt = CSI.TYPE_NAME[gi.category]
        if games_by_cat.has_key(gt):
            games_by_cat[gt] += 1
        else:
            games_by_cat[gt] = 1
    games_by_cat_list = [(i, j) for i, j in games_by_cat.items()]
    games_by_cat_list.sort(lambda i, j: cmp(j[1], i[1]))
##     print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
##     for i in games_by_cat_list:
##         print '<tr><td>%s</td><td>%s</td></tr>' % i
##     print '</table>'
    print '<ul>'
    for i in games_by_cat_list:
        print '<li>%s (%s games)</li>' % i
    print '</ul>'
    return
Exemple #7
0
def by_category():
    games = GAME_DB.getGamesIdSortedById()
    games_by_cat = {}
    for id in games:
        gi = GAME_DB.get(id)
        gt = CSI.TYPE_NAME[gi.category]
        if games_by_cat.has_key(gt):
            games_by_cat[gt] += 1
        else:
            games_by_cat[gt] = 1
    games_by_cat_list = [(i, j) for i, j in games_by_cat.items()]
    games_by_cat_list.sort(lambda i, j: cmp(j[1], i[1]))
    ##     print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
    ##     for i in games_by_cat_list:
    ##         print '<tr><td>%s</td><td>%s</td></tr>' % i
    ##     print '</table>'
    print "<ul>"
    for i in games_by_cat_list:
        print "<li>%s (%s games)</li>" % i
    print "</ul>"
    return
Exemple #8
0
def plain_text():
    get_games_func = GAME_DB.getGamesIdSortedByName
    for id in get_games_func():
        gi = GAME_DB.get(id)
        if gi.category == GI.GC_FRENCH:
            # print str(gi.gameclass)
            # gc = gi.gameclass
            # h = gc.Hint_Class is None and 'None' or gc.Hint_Class.__name__
            # print gi.name.encode('utf-8'), h
            print(gi.name)
            for n in gi.altnames:
                print(n)
Exemple #9
0
def plain_text():
    get_games_func = GAME_DB.getGamesIdSortedByName
    for id in get_games_func():
        gi = GAME_DB.get(id)
        if gi.category == GI.GC_FRENCH:
            ##print str(gi.gameclass)
            ##gc = gi.gameclass
            ##h = gc.Hint_Class is None and 'None' or gc.Hint_Class.__name__
            ##print gi.name.encode('utf-8'), h
            print gi.name.encode("utf-8")
            for n in gi.altnames:
                print n.encode("utf-8")
Exemple #10
0
def by_category():
    games = GAME_DB.getGamesIdSortedById()
    games_by_cat = {}
    for id in games:
        gi = GAME_DB.get(id)
        gt = CSI.TYPE_NAME[gi.category]
        if gt in games_by_cat:
            games_by_cat[gt] += 1
        else:
            games_by_cat[gt] = 1
    games_by_cat_list = [(i, j) for i, j in games_by_cat.items()]
    games_by_cat_list.sort(key=lambda x: x[1])
    games_by_cat_list = games_by_cat_list[::-1]
#     print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
#     for i in games_by_cat_list:
#         print '<tr><td>%s</td><td>%s</td></tr>' % i
#     print '</table>'
    print('<ul>')
    for i in games_by_cat_list:
        print('<li>%s (%s games)</li>' % i)
    print('</ul>')
    return
Exemple #11
0
def by_category():
    games = GAME_DB.getGamesIdSortedById()
    games_by_cat = {}
    for id in games:
        gi = GAME_DB.get(id)
        gt = CSI.TYPE_NAME[gi.category]
        if gt in games_by_cat:
            games_by_cat[gt] += 1
        else:
            games_by_cat[gt] = 1
    games_by_cat_list = [(i, j) for i, j in games_by_cat.items()]
    games_by_cat_list.sort(key=lambda x: x[1])
    games_by_cat_list = games_by_cat_list[::-1]
#     print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
#     for i in games_by_cat_list:
#         print '<tr><td>%s</td><td>%s</td></tr>' % i
#     print '</table>'
    print('<ul>')
    for i in games_by_cat_list:
        print('<li>%s (%s games)</li>' % i)
    print('</ul>')
    return
Exemple #12
0
def by_type():
    games = GAME_DB.getGamesIdSortedById()
    games_by_type = {}
    for id in games:
        gi = GAME_DB.get(id)
        if not GAME_BY_TYPE.has_key(gi.si.game_type):
            print gi.si.game_type
            continue
        gt = GAME_BY_TYPE[gi.si.game_type]
        if games_by_type.has_key(gt):
            games_by_type[gt] += 1
        else:
            games_by_type[gt] = 1
    games_by_type_list = games_by_type.items()
    games_by_type_list.sort(lambda i, j: cmp(i[0], j[0]))
    ##     print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
    ##     for i in games_by_type_list:
    ##         print '<tr><td>%s</td><td>%s</td></tr>' % i
    ##     print '</table>'
    print "<ul>"
    for i in games_by_type_list:
        print "<li>%s (%s games)</li>" % i
    print "</ul>"
    return
Exemple #13
0
def by_type():
    games = GAME_DB.getGamesIdSortedById()
    games_by_type = {}
    for id in games:
        gi = GAME_DB.get(id)
        if gi.si.game_type not in GAME_BY_TYPE:
            print(gi.si.game_type)
            continue
        gt = GAME_BY_TYPE[gi.si.game_type]
        if gt in games_by_type:
            games_by_type[gt] += 1
        else:
            games_by_type[gt] = 1
    games_by_type_list = list(games_by_type.items())
    games_by_type_list.sort(key=lambda x: x[0])
    #  print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
    #  for i in games_by_type_list:
    #      print '<tr><td>%s</td><td>%s</td></tr>' % i
    #  print '</table>'
    print('<ul>')
    for i in games_by_type_list:
        print('<li>%s (%s games)</li>' % i)
    print('</ul>')
    return
Exemple #14
0
def by_type():
    games = GAME_DB.getGamesIdSortedById()
    games_by_type = {}
    for id in games:
        gi = GAME_DB.get(id)
        if not GAME_BY_TYPE.has_key(gi.si.game_type):
            print gi.si.game_type
            continue
        gt = GAME_BY_TYPE[gi.si.game_type]
        if games_by_type.has_key(gt):
            games_by_type[gt] += 1
        else:
            games_by_type[gt] = 1
    games_by_type_list = games_by_type.items()
    games_by_type_list.sort(lambda i, j: cmp(i[0], j[0]))
##     print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
##     for i in games_by_type_list:
##         print '<tr><td>%s</td><td>%s</td></tr>' % i
##     print '</table>'
    print '<ul>'
    for i in games_by_type_list:
        print '<li>%s (%s games)</li>' % i
    print '</ul>'
    return
Exemple #15
0
def old_plain_text():
    # get_games_func = GAME_DB.getGamesIdSortedById
    get_games_func = GAME_DB.getGamesIdSortedByName
    games_list = {}  # for unique
    for id in get_games_func():
        gi = GAME_DB.get(id)
        games_list[gi.name] = ""
        # if gi.name != gi.short_name:
        #    games_list[gi.short_name] = ''
        for n in gi.altnames:
            games_list[n] = ""
    games_list = games_list.keys()
    games_list.sort()
    for g in games_list:
        print g.encode("utf-8")
Exemple #16
0
def old_plain_text():
    # get_games_func = GAME_DB.getGamesIdSortedById
    get_games_func = GAME_DB.getGamesIdSortedByName
    games_list = {}  # for unique
    for id in get_games_func():
        gi = GAME_DB.get(id)
        games_list[gi.name] = ''
        # if gi.name != gi.short_name:
        #    games_list[gi.short_name] = ''
        for n in gi.altnames:
            games_list[n] = ''
    games_list = games_list.keys()
    games_list.sort()
    for g in games_list:
        print(g)
Exemple #17
0
def by_type():
    games = GAME_DB.getGamesIdSortedById()
    games_by_type = {}
    for id in games:
        gi = GAME_DB.get(id)
        if gi.si.game_type not in GAME_BY_TYPE:
            print(gi.si.game_type)
            continue
        gt = GAME_BY_TYPE[gi.si.game_type]
        if gt in games_by_type:
            games_by_type[gt] += 1
        else:
            games_by_type[gt] = 1
    games_by_type_list = list(games_by_type.items())
    games_by_type_list.sort(key=lambda x: x[0])
    #  print '<table border="2"><tr><th>Name</th><th>Number</th></tr>'
    #  for i in games_by_type_list:
    #      print '<tr><td>%s</td><td>%s</td></tr>' % i
    #  print '</table>'
    print('<ul>')
    for i in games_by_type_list:
        print('<li>%s (%s games)</li>' % i)
    print('</ul>')
    return
Exemple #18
0
def create_html(sort_by):
    print """<html>
<head>
  <title>PySolFC - List of solitaire games</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
"""
    print "<b>Total games: %d</b>" % len(GAME_DB.getGamesIdSortedById())
    print "<h2>Categories</h2>"
    by_category()
    print "<h2>Types</h2>"
    by_type()
    # print '<h2>All games</h2>'
    all_games(sort_by)
    print "</body></html>"
Exemple #19
0
def create_html(sort_by):
    print('''<html>
<head>
  <title>PySolFC - List of solitaire games</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
''')
    print('<b>Total games: %d</b>' % len(GAME_DB.getGamesIdSortedById()))
    print('<h2>Categories</h2>')
    by_category()
    print('<h2>Types</h2>')
    by_type()
    # print '<h2>All games</h2>'
    all_games(sort_by)
    print('</body></html>')
Exemple #20
0
def all_games(sort_by="id"):
    # rules_dir = 'rules'
    print """<table border="2">
<tr><th>ID</th><th>Name</th><th>Alternate names</th><th>Type</th></tr>
"""

    if sort_by == "id":
        get_games_func = GAME_DB.getGamesIdSortedById
    else:
        get_games_func = GAME_DB.getGamesIdSortedByName

    for id in get_games_func():
        gi = GAME_DB.get(id)
        if not gi.rules_filename:
            rules_fn = getGameRulesFilename(gi.name)
        else:
            rules_fn = gi.rules_filename
        gt = CSI.TYPE_NAME[gi.category]
        if gt == "French":
            gt = "French (%s)" % GAME_BY_TYPE[gi.si.game_type]
        name = gi.name.encode("utf-8")
        altnames = "<br>".join(gi.altnames).encode("utf-8")
        fn = os.path.join(rules_dir, rules_fn)
        if 1 and os.path.exists(fn):
            print """<tr><td>%s</td><td>
<a href="%s" title="Rules for this game">%s</a>
</td><td>%s</td><td>%s</td></tr>
""" % (
                id,
                fn,
                name,
                altnames,
                gt,
            )
        else:
            print """<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>
""" % (
                id,
                name,
                altnames,
                gt,
            )
    print "</table>"
Exemple #21
0
def pysol_init(app, args):

    # init commandline options (undocumented)
    opts = parse_option(args)
    if not opts:
        return 1
        sys.exit(1)
    opts, filename = opts
    if filename:
        app.commandline.loadgame = filename
    app.commandline.deal = opts['deal']
    app.commandline.game = opts['game']
    if opts['gameid'] is not None:
        try:
            app.commandline.gameid = int(opts['gameid'])
        except ValueError:
            print_err(_('invalid game id: ') + opts['gameid'])

    # try to create the config directory
    for d in (
        app.dn.config,
        app.dn.savegames,
        os.path.join(app.dn.config, "music"),
        # os.path.join(app.dn.config, "screenshots"),
        os.path.join(app.dn.config, "tiles"),
        os.path.join(app.dn.config, "tiles", "stretch"),
        os.path.join(app.dn.config, "tiles", "save-aspect"),
        os.path.join(app.dn.config, "cardsets"),
        os.path.join(app.dn.config, "plugins"),
            ):
        if not os.path.exists(d):
            try:
                os.makedirs(d)
            except Exception:
                traceback.print_exc()
                pass

    # init DataLoader
    f = os.path.join("html", "license.html")
    app.dataloader = DataLoader(args[0], f)

    # init toolkit 1)
    top = MfxRoot(className=TITLE)
    app.top = top
    app.top_bg = top.cget("bg")
    app.top_cursor = top.cget("cursor")

    # load options
    try:
        app.loadOptions()
    except Exception:
        traceback.print_exc()
        pass

    # init toolkit 2)
    init_root_window(top, app)

    # prepare the progress bar
    app.loadImages1()
    if not app.progress_images:
        app.progress_images = (loadImage(app.gimages.logos[0]),
                               loadImage(app.gimages.logos[1]))
    app.wm_withdraw()

    # create the progress bar
    title = _("Welcome to %s") % TITLE
    color = app.opt.colors['table']
    if app.tabletile_index > 0:
        color = "#008200"
    app.intro.progress = PysolProgressBar(app, top, title=title, color=color,
                                          images=app.progress_images, norm=2.0)
    app.intro.progress.update(step=1)

    # init games database
    def progressCallback(*args):
        app.intro.progress.update(step=1)
    GAME_DB.setCallback(progressCallback)
    import pysollib.games
    if not opts['french-only']:
        import pysollib.games.ultra
        import pysollib.games.mahjongg
        import pysollib.games.special
        pysollib.games.special.no_use()

    # try to load plugins
    if not opts["noplugins"]:
        for dir in (os.path.join(app.dataloader.dir, "games"),
                    os.path.join(app.dataloader.dir, "plugins"),
                    app.dn.plugins):
            try:
                app.loadPlugins(dir)
            except Exception:
                pass
    GAME_DB.setCallback(None)

    # init audio 1)
    app.audio = None
    sounds = {'pss':     PysolSoundServerModuleClient,
              'pygame':  PyGameAudioClient,
              'oss':     OSSAudioClient,
              'win':     Win32AudioClient}
    if TOOLKIT == 'kivy':
        sounds['kivy'] = KivyAudioClient
    if opts["nosound"] or SOUND_MOD == 'none':
        app.audio = AbstractAudioClient()
    elif opts['sound-mod']:
        c = sounds[opts['sound-mod']]
        app.audio = c()
    elif SOUND_MOD == 'auto':
        snd = []
        snd.append(PyGameAudioClient)
        if TOOLKIT == 'kivy':
            snd.append(KivyAudioClient)
        if pysolsoundserver:
            snd.append(PysolSoundServerModuleClient)
        snd.append(OSSAudioClient)
        snd.append(Win32AudioClient)
        snd.append(AbstractAudioClient)
        for c in snd:
            try:
                app.audio = c()
                app.audio.startServer()
                app.audio.connectServer(app)
            except Exception:
                pass
            else:
                # success
                break
    else:
        c = sounds[SOUND_MOD]
        app.audio = c()
        app.audio.startServer()
        app.audio.connectServer(app)

    # update sound_mode
    if isinstance(app.audio, PysolSoundServerModuleClient):
        app.opt.sound_mode = 1
    else:
        app.opt.sound_mode = 0

    # check games
    if len(app.gdb.getGamesIdSortedByName()) == 0:
        app.wm_withdraw()
        app.intro.progress.destroy()
        d = MfxMessageDialog(top, title=_("%s installation error") % TITLE,
                             text=_('''
No games were found !!!

Main data directory is:
%s

Please check your %s installation.
''') % (app.dataloader.dir, TITLE), bitmap="error", strings=(_("&Quit"),))
        return 1

    # init cardsets
    app.initCardsets()
    cardset = None
    c = app.opt.cardset.get(0)
    if c:
        cardset = app.cardset_manager.getByName(c[0])
        if cardset and c[1]:
            cardset.updateCardback(backname=c[1])
    if not cardset:
        cardset = app.cardset_manager.get(0)
    if app.cardset_manager.len() == 0 or not cardset:
        fatal_no_cardsets(app)
        return 3

    # init tiles
    manager = app.tabletile_manager
    tile = Tile()
    tile.color = app.opt.colors['table']
    tile.name = "None"
    tile.filename = None
    manager.register(tile)
    app.initTiles()
    if app.opt.tabletile_name:  # and top.winfo_screendepth() > 8:
        for tile in manager.getAll():
            if app.opt.tabletile_name == tile.basename:
                app.tabletile_index = tile.index
                break

    # init samples and music resources
    app.initSamples()
    app.initMusic()

    # init audio 2)
    if not app.audio.CAN_PLAY_SOUND:
        app.opt.sound = 0
    app.audio.updateSettings()
    # start up the background music
    if app.audio.CAN_PLAY_MUSIC:
        music = app.music_manager.getAll()
        if music:
            app.music_playlist = list(music)[:]
            app.miscrandom.shuffle(app.music_playlist)
            if 1:
                for m in app.music_playlist:
                    if m.name.lower() == "bye_for_now":
                        app.music_playlist.remove(m)
                        app.music_playlist.insert(0, m)
                        break
            app.audio.playContinuousMusic(app.music_playlist)

    # prepare other images
    app.loadImages2()
    app.loadImages3()
    app.loadImages4()

    # load cardset
    progress = app.intro.progress
    if not app.loadCardset(cardset, progress=progress, update=1):
        for cardset in app.cardset_manager.getAll():
            progress.reset()
            if app.loadCardset(cardset, progress=progress, update=1):
                break
        else:
            fatal_no_cardsets(app)
            return 3

    # ok
    return 0
 def constructGame(self, id):
     gi = GAME_DB.get(id)
     if gi is None:
         raise Exception("Unknown game (id %d)" % id)
     return gi.gameclass(gi)
Exemple #23
0
def gen_rules_html():
    # ls = glob(os.path.join('rules', '*.html'))
    rules_ls = os.listdir('rules')
    rules_ls.sort()
    wikipedia_ls = os.listdir('wikipedia')
    wikipedia_ls.sort()

    games = GAME_DB.getGamesIdSortedByName()
    rules_list = []
    files_list = []
    for fn, tt in rules_files:
        rules_list.append(('rules', fn, tt, ''))
        files_list.append(fn)
    for fn, tt in wikipedia_files:
        rules_list.append(('wikipedia', fn, tt, ''))
        files_list.append(fn)
    altnames = []

    # open file of list of all rules
    out_rules = open(os.path.join('html', 'rules.html'), 'w')
    print >> out_rules, main_header % 'PySol - a Solitaire Game Collection'
    print >> out_rules, open('rules.html').read()

    for id in games:
        # create list of rules

        gi = GAME_DB.get(id)

        rules_fn = gi.rules_filename
        if not rules_fn:
            rules_fn = getGameRulesFilename(gi.name)

        if rules_fn in files_list:
            continue

        if rules_fn in rules_ls:
            rules_dir = 'rules'
        elif rules_fn in wikipedia_ls:
            rules_dir = 'wikipedia'
        else:
            print('missing rules for %s (file: %s)'
                  % (gi.name.encode('utf-8'), rules_fn))
            continue

        # print '>>>', rules_fn

        title = 'PySol - Rules for ' + gi.name
        s = ''
        if gi.si.game_type == GI.GT_HANAFUDA:
            s = '<a href="../hanafuda.html">General Flower Card rules</a>'
        elif gi.si.game_type == GI.GT_DASHAVATARA_GANJIFA:
            s = '<a href="../ganjifa.html">About Ganjifa</a>'
        elif gi.si.game_type == GI.GT_HEXADECK:
            s = '<a href="../hexadeck.html">General Hex A Deck rules</a>'
        elif gi.si.game_type == GI.GT_MUGHAL_GANJIFA:
            s = '<a href="../ganjifa.html">About Ganjifa</a>'
            # print '***', gi.name, '***'

        rules_list.append((rules_dir, rules_fn, title, s))
        files_list.append(rules_fn)
        # rules_list.append((rules_fn, gi.name))
        print >> out_rules, '<li><a href="rules/%s">%s</a>' \
            % (rules_fn, gi.name.encode('utf-8'))
        for n in gi.altnames:
            altnames.append((n, rules_fn))

    print >> out_rules, '</ul>\n' + \
        main_footer % '<a href="index.html">Back to the index</a>'

    # create file of altnames
    out_rules_alt = open(os.path.join('html', 'rules_alternate.html'), 'w')
    print >> out_rules_alt, main_header % 'PySol - a Solitaire Game Collection'
    print >> out_rules_alt, open('rules_alternate.html').read()
    altnames.sort()
    for name, fn in altnames:
        print >> out_rules_alt, '<li> <a href="rules/%s">%s</a>' \
              % (fn, name.encode('utf-8'))
    print >> out_rules_alt, '</ul>\n' + \
        main_footer % '<a href="index.html">Back to the index</a>'

    # create rules
    for dir, filename, title, footer in rules_list:
        outfile = open(os.path.join('html', 'rules', filename), 'w')
        if dir == 'rules':
            print >> outfile, (rules_header % title).encode('utf-8')
        else:  # d == 'wikipedia'
            print >> outfile, (wikipedia_header % title).encode('utf-8')
        print >> outfile, open(os.path.join(dir, filename)).read()
        print >> outfile, rules_footer % footer
Exemple #24
0
def gen_rules_html():
    # ls = glob(os.path.join('rules', '*.html'))
    rules_ls = os.listdir('rules')
    rules_ls.sort()
    wikipedia_ls = os.listdir('wikipedia')
    wikipedia_ls.sort()

    games = GAME_DB.getGamesIdSortedByName()
    rules_list = []
    files_list = []
    for fn, tt in rules_files:
        rules_list.append(('rules', fn, tt, ''))
        files_list.append(fn)
    for fn, tt in wikipedia_files:
        rules_list.append(('wikipedia', fn, tt, ''))
        files_list.append(fn)
    altnames = []

    # open file of list of all rules
    out_rules = open(os.path.join('html', 'rules.html'), 'w')
    print >> out_rules, main_header % 'PySol - a Solitaire Game Collection'
    print >> out_rules, open('rules.html').read()

    for id in games:
        # create list of rules

        gi = GAME_DB.get(id)

        rules_fn = gi.rules_filename
        if not rules_fn:
            rules_fn = getGameRulesFilename(gi.name)

        if rules_fn in files_list:
            continue

        if rules_fn in rules_ls:
            rules_dir = 'rules'
        elif rules_fn in wikipedia_ls:
            rules_dir = 'wikipedia'
        else:
            print('missing rules for %s (file: %s)' %
                  (gi.name.encode('utf-8'), rules_fn))
            continue

        # print '>>>', rules_fn

        title = 'PySol - Rules for ' + gi.name
        s = ''
        if gi.si.game_type == GI.GT_HANAFUDA:
            s = '<a href="../hanafuda.html">General Flower Card rules</a>'
        elif gi.si.game_type == GI.GT_DASHAVATARA_GANJIFA:
            s = '<a href="../ganjifa.html">About Ganjifa</a>'
        elif gi.si.game_type == GI.GT_HEXADECK:
            s = '<a href="../hexadeck.html">General Hex A Deck rules</a>'
        elif gi.si.game_type == GI.GT_MUGHAL_GANJIFA:
            s = '<a href="../ganjifa.html">About Ganjifa</a>'
            # print '***', gi.name, '***'

        rules_list.append((rules_dir, rules_fn, title, s))
        files_list.append(rules_fn)
        # rules_list.append((rules_fn, gi.name))
        print >> out_rules, '<li><a href="rules/%s">%s</a>' \
            % (rules_fn, gi.name.encode('utf-8'))
        for n in gi.altnames:
            altnames.append((n, rules_fn))

    print >> out_rules, '</ul>\n' + \
        main_footer % '<a href="index.html">Back to the index</a>'

    # create file of altnames
    out_rules_alt = open(os.path.join('html', 'rules_alternate.html'), 'w')
    print >> out_rules_alt, main_header % 'PySol - a Solitaire Game Collection'
    print >> out_rules_alt, open('rules_alternate.html').read()
    altnames.sort()
    for name, fn in altnames:
        print >> out_rules_alt, '<li> <a href="rules/%s">%s</a>' \
              % (fn, name.encode('utf-8'))
    print >> out_rules_alt, '</ul>\n' + \
        main_footer % '<a href="index.html">Back to the index</a>'

    # create rules
    for dir, filename, title, footer in rules_list:
        outfile = open(os.path.join('html', 'rules', filename), 'w')
        if dir == 'rules':
            print >> outfile, (rules_header % title).encode('utf-8')
        else:  # d == 'wikipedia'
            print >> outfile, (wikipedia_header % title).encode('utf-8')
        print >> outfile, open(os.path.join(dir, filename)).read()
        print >> outfile, rules_footer % footer
Exemple #25
0
def gen_rules_html():
    # ls = glob(os.path.join('rules', '*.html'))
    rules_ls = os.listdir('rules')
    rules_ls.sort()
    wikipedia_ls = os.listdir('wikipedia')
    wikipedia_ls.sort()

    games = GAME_DB.getGamesIdSortedByName()
    rules_list = []
    files_list = []
    for fn, tt in rules_files:
        rules_list.append(('rules', fn, tt, ''))
        files_list.append(fn)
    for fn, tt in wikipedia_files:
        rules_list.append(('wikipedia', fn, tt, ''))
        files_list.append(fn)
    altnames = []

    # open file of list of all rules
    out_rules = open(os.path.join('html', 'rules.html'), 'w')
    print(_fmt(main_header, {'title': 'PySol - a Solitaire Game Collection'}),
          file=out_rules)
    with open('rules.html', 'r') as file:
        print(file.read(), file=out_rules)

    for id in games:
        # create list of rules

        gi = GAME_DB.get(id)

        rules_fn = gi.rules_filename
        if not rules_fn:
            rules_fn = _get_game_rules_filename(gi.name)

        if rules_fn in rules_ls:
            rules_dir = 'rules'
        elif rules_fn in wikipedia_ls:
            rules_dir = 'wikipedia'
        else:
            print('missing rules for %s (file: %s)' % (gi.name, rules_fn))
            continue

        # print '>>>', rules_fn
        if rules_fn not in files_list:
            title = 'PySol - Rules for ' + gi.name
            s = ''
            if gi.si.game_type == GI.GT_HANAFUDA:
                s = '<a href="../hanafuda.html">General Flower Card rules</a>'
            elif gi.si.game_type == GI.GT_DASHAVATARA_GANJIFA or \
                    gi.si.game_type == GI.GT_MUGHAL_GANJIFA:
                s = '<a href="../ganjifa.html">About Ganjifa</a>'
            elif gi.si.game_type == GI.GT_HEXADECK:
                s = '<a href="../hexadeck.html">General Hex A Deck rules</a>'

            rules_list.append((rules_dir, rules_fn, title, s))
        files_list.append(rules_fn)
        # rules_list.append((rules_fn, gi.name))
        print('<li><a href="rules/%s">%s</a>' % (rules_fn, gi.name),
              file=out_rules)
        for n in gi.altnames:
            altnames.append((n, rules_fn))

    print('</ul>\n' + _fmt(
        main_footer,
        {'back_to_index_link': '<a href="index.html">Back to the index</a>'}),
          file=out_rules)

    out_rules.close()

    # create file of altnames
    out_rules_alt = open(os.path.join('html', 'rules_alternate.html'), 'w')
    print(_fmt(main_header, {'title': 'PySol - a Solitaire Game Collection'}),
          file=out_rules_alt)
    with open('rules_alternate.html', 'r') as file:
        print(file.read(), file=out_rules_alt)
    altnames.sort()
    for name, fn in altnames:
        print('<li> <a href="rules/%s">%s</a>' % (fn, name),
              file=out_rules_alt)
    print('</ul>\n' + _fmt(
        main_footer,
        {'back_to_index_link': '<a href="index.html">Back to the index</a>'}),
          file=out_rules_alt)
    out_rules_alt.close()

    # create rules
    for dir, filename, title, footer in rules_list:
        outfile = open(os.path.join('html', 'rules', filename),
                       'w',
                       encoding='utf-8')
        if dir == 'rules':
            print(_fmt(rules_header, {'title': title}), file=outfile)
        else:  # d == 'wikipedia'
            print(_fmt(wikipedia_header, {'title': title}), file=outfile)
        with open(os.path.join(dir, filename), 'r', encoding='utf-8') as file:
            print(file.read(), file=outfile)
        print(_fmt(rules_footer, {'footer': footer}), file=outfile)
        outfile.close()
Exemple #26
0
def pysol_init(app, args):

    # init commandline options (undocumented)
    opts = parse_option(args)
    if not opts:
        return 1
        sys.exit(1)
    opts, filename = opts
    if filename:
        app.commandline.loadgame = filename
    app.commandline.game = opts['game']
    if opts['gameid'] is not None:
        try:
            app.commandline.gameid = int(opts['gameid'])
        except ValueError:
            print_err(_('invalid game id: ') + opts['gameid'])

    # try to create the config directory
    for d in (
            app.dn.config,
            app.dn.savegames,
            os.path.join(app.dn.config, "music"),
            # os.path.join(app.dn.config, "screenshots"),
            os.path.join(app.dn.config, "tiles"),
            os.path.join(app.dn.config, "tiles", "stretch"),
            os.path.join(app.dn.config, "tiles", "save-aspect"),
            os.path.join(app.dn.config, "cardsets"),
            os.path.join(app.dn.config, "plugins"),
    ):
        if not os.path.exists(d):
            try:
                os.makedirs(d)
            except:
                traceback.print_exc()
                pass

    # init DataLoader
    f = os.path.join("html-src", "license.html")
    app.dataloader = DataLoader(args[0], f)

    # init toolkit 1)
    top = MfxRoot(className=TITLE)
    app.top = top
    app.top_bg = top.cget("bg")
    app.top_cursor = top.cget("cursor")

    # load options
    try:
        app.loadOptions()
    except:
        traceback.print_exc()
        pass

    # init toolkit 2)
    init_root_window(top, app)

    # prepare the progress bar
    app.loadImages1()
    if not app.progress_images:
        app.progress_images = (loadImage(app.gimages.logos[0]),
                               loadImage(app.gimages.logos[1]))
    app.wm_withdraw()

    # create the progress bar
    title = _("Welcome to %s") % TITLE
    color = app.opt.colors['table']
    if app.tabletile_index > 0:
        color = "#008200"
    app.intro.progress = PysolProgressBar(app,
                                          top,
                                          title=title,
                                          color=color,
                                          images=app.progress_images,
                                          norm=2.0)
    app.intro.progress.update(step=1)

    # init games database
    def progressCallback(*args):
        app.intro.progress.update(step=1)

    GAME_DB.setCallback(progressCallback)
    import pysollib.games
    if not opts['french-only']:
        import pysollib.games.ultra
        import pysollib.games.mahjongg
        import pysollib.games.special
        pysollib.games.special.no_use()

    # try to load plugins
    if not opts["noplugins"]:
        for dir in (os.path.join(app.dataloader.dir, "games"),
                    os.path.join(app.dataloader.dir,
                                 "plugins"), app.dn.plugins):
            try:
                app.loadPlugins(dir)
            except:
                pass
    GAME_DB.setCallback(None)

    # init audio 1)
    app.audio = None
    sounds = {
        'pss': PysolSoundServerModuleClient,
        'pygame': PyGameAudioClient,
        'oss': OSSAudioClient,
        'win': Win32AudioClient
    }
    if opts["nosound"] or SOUND_MOD == 'none':
        app.audio = AbstractAudioClient()
    elif opts['sound-mod']:
        c = sounds[opts['sound-mod']]
        app.audio = c()
    elif SOUND_MOD == 'auto':
        for c in (PyGameAudioClient, PysolSoundServerModuleClient,
                  OSSAudioClient, Win32AudioClient, AbstractAudioClient):
            try:
                app.audio = c()
                app.audio.startServer()
                app.audio.connectServer(app)
            except:
                pass
            else:
                # success
                break
    else:
        c = sounds[SOUND_MOD]
        app.audio = c()
        app.audio.startServer()
        app.audio.connectServer(app)

    # update sound_mode
    if isinstance(app.audio, PysolSoundServerModuleClient):
        app.opt.sound_mode = 1
    else:
        app.opt.sound_mode = 0

    # check games
    if len(app.gdb.getGamesIdSortedByName()) == 0:
        app.wm_withdraw()
        app.intro.progress.destroy()
        d = MfxMessageDialog(top,
                             title=_("%s installation error") % TITLE,
                             text=_('''
No games were found !!!

Main data directory is:
%s

Please check your %s installation.
''') % (app.dataloader.dir, TITLE),
                             bitmap="error",
                             strings=(_("&Quit"), ))
        return 1

    # init cardsets
    app.initCardsets()
    cardset = None
    c = app.opt.cardset.get(0)
    if c:
        cardset = app.cardset_manager.getByName(c[0])
        if cardset and c[1]:
            cardset.updateCardback(backname=c[1])
    if not cardset:
        cardset = app.cardset_manager.get(0)
    if app.cardset_manager.len() == 0 or not cardset:
        fatal_no_cardsets(app)
        return 3

    # init tiles
    manager = app.tabletile_manager
    tile = Tile()
    tile.color = app.opt.colors['table']
    tile.name = "None"
    tile.filename = None
    manager.register(tile)
    app.initTiles()
    if app.opt.tabletile_name:  # and top.winfo_screendepth() > 8:
        for tile in manager.getAll():
            if app.opt.tabletile_name == tile.basename:
                app.tabletile_index = tile.index
                break

    # init samples and music resources
    app.initSamples()
    app.initMusic()

    # init audio 2)
    if not app.audio.CAN_PLAY_SOUND:
        app.opt.sound = 0
    app.audio.updateSettings()
    # start up the background music
    if app.audio.CAN_PLAY_MUSIC:
        music = app.music_manager.getAll()
        if music:
            app.music_playlist = list(music)[:]
            app.miscrandom.shuffle(app.music_playlist)
            if 1:
                for m in app.music_playlist:
                    if m.name.lower() == "bye_for_now":
                        app.music_playlist.remove(m)
                        app.music_playlist.insert(0, m)
                        break
            app.audio.playContinuousMusic(app.music_playlist)

    # prepare other images
    app.loadImages2()
    app.loadImages3()
    app.loadImages4()

    # load cardset
    progress = app.intro.progress
    if not app.loadCardset(cardset, progress=progress, update=1):
        for cardset in app.cardset_manager.getAll():
            progress.reset()
            if app.loadCardset(cardset, progress=progress, update=1):
                break
        else:
            fatal_no_cardsets(app)
            return 3

    # ok
    return 0
Exemple #27
0
 def constructGame(self, id):
     gi = GAME_DB.get(id)
     if gi is None:
         raise Exception("Unknown game (id %d)" % id)
     return gi.gameclass(gi)