/usr/share/games/pysycache/datas.py is in pysycache 3.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | #!/usr/bin/env python
# -*- coding: utf8 -*-
#***********************************************************************
# pysycache : a program for learn to use the mouse
# Copyright (C) 2005-2007 Vincent DEROO (vincent.pysycache@free.fr)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc. :
# 51 Franklin Street, Fifth Floor, Boston, MA02110-1301, USA
#***********************************************************************
#*******************************************************************************
# Importation des modules
#*******************************************************************************
import sys
import getopt, string
import random, os
import glob
import locale
import pygame
from pygame.locals import *
import const
#*******************************************************************************
# Fonctions #
#*******************************************************************************
#*******************************************************************************
# Show help about pysycache
#*******************************************************************************
def Help_message():
print '''
Pysycache is an educative software for teach to use the mouse
Usage :
python ./pysycache.py
Options :
-h : displays this help message
-nf : no fullscreen mode
-ns : no sound mode
-nh : no sounds for menus
-nc : no credits at the end of the game
-debug : show message for debug
-lang=XX : use the XX lang for menus
(see in the directory lang for remplace
XX by the correct name)
-font=XX : use the font filename XX for menus
(it must be placed in the fonts directory)
--version : displays Pysycache version
---python-version : displays Pysycache version
'''
sys.exit(0)
#*******************************************************************************
# Show a unicode message in the console
#*******************************************************************************
def DebugMessage(message):
if const.GDebug == 1:
print message.encode(const.GConsoleLocale, "ignore")
#*******************************************************************************
# Charge une image (png, bmp ou jpeg) #
# isfullpath : 0 relative path #
# : 1 absolute path #
#*******************************************************************************
def Load_image(dirname, filename, colorkey=None, isfullpath=False):
""" Load png, bmp or jpeg image"""
#recherche de l'extension
(shortname, extension) = os.path.splitext(filename)
if string.upper(extension) == '.BMP':
imagetmp, imagetmp_rect = Load_bmp(dirname, filename, colorkey, isfullpath)
if string.upper(extension) == '.JPG':
imagetmp, imagetmp_rect = Load_bmp(dirname, filename, colorkey, isfullpath)
if string.upper(extension) == '.JPEG':
imagetmp, imagetmp_rect = Load_bmp(dirname, filename, colorkey, isfullpath)
if string.upper(extension) == '.PNG':
imagetmp, imagetmp_rect = Load_png(dirname, filename, isfullpath)
return imagetmp, imagetmp_rect
#*******************************************************************************
# Charge une image de type bmp ou jpeg
#*******************************************************************************
def Load_bmp(dirname, filename, colorkey=None, isfullpath=False):
""" Load bmp or jpeg image and return image object"""
if isfullpath:
#le chemin est complet
fullname = filename.encode(const.GConsoleLocale)
else:
fullname = os.path.join(const.GRepPysycache, dirname, filename).encode(const.GConsoleLocale)
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image: ', fullname
raise SystemExit, message
image = image.convert()
if colorkey is not None:
if colorkey is -1:
colorkey = image.get_at((0,0))
image.set_colorkey(colorkey, RLEACCEL)
return image, image.get_rect()
#*******************************************************************************
# Charge une image de type png
#*******************************************************************************
def Load_png(dirname, filename, isfullpath=False):
""" Load png image and return image object"""
if isfullpath:
#le chemin est complet
fullname = filename.encode(const.GConsoleLocale)
else:
fullname = os.path.join(const.GRepPysycache, dirname, filename).encode(const.GConsoleLocale)
try:
image = pygame.image.load(fullname)
(ht, lg) = image.get_size()
if image.get_alpha is None:
image = image.convert()
else:
image = image.convert_alpha()
except pygame.error, message:
print 'Cannot load image:', fullname
raise SystemExit, message
#A GARDER !!!!!!!!!!!!!!!!!!
# imagescaled = pygame.transform.scale(image, (ht * 0.8, lg * 0.8)) #0.8 = 640 / 800
return image, image.get_rect()
# return imagescaled, image.get_rect()
#*******************************************************************************
# Play sound #
#*******************************************************************************
def Load_sound(dirname, filename):
""" Play sound """
#on joue la musique
if const.GWithSound == 1:
if const.GSoundError == 0:
fullname = os.path.join(const.GRepPysycache, dirname, filename).encode(const.GConsoleLocale)
if not pygame.mixer.get_init():
print "Cannot load sound : pygame error : ", pygame.get_error()
else:
if os.path.isfile(fullname):
pygame.mixer.music.load(fullname)
pygame.mixer.music.play(0)
else:
DebugMessage("sound file %s doesn't exist ! " % os.path.join(const.GRepPysycache, dirname, filename))
#*******************************************************************************
# Play the winner sound
#*******************************************************************************
def PlayWinnerSound():
idxsnd = random.randint(0, 2)
if idxsnd == 0 :
Load_sound("sounds", "youpee.ogg")
elif idxsnd == 1 :
Load_sound("sounds", "yahoo.ogg")
else :
Load_sound("sounds", "rire.ogg")
#*******************************************************************************
# Make transition between two pictures
#*******************************************************************************
def ShowTransitionOfTheme(duree, fileimage, withsound = 1):
screen = pygame.display.get_surface()
if withsound == 1:
Load_sound("sounds", "transition.ogg")
background_image2, background_rect = Load_image("images", fileimage)
for i in range(300):
tr2 = pygame.Rect([0, i, 800, 1] )
screen.blit(background_image2, (0, i), tr2)
pygame.display.update(tr2)
tr2 = pygame.Rect([0, 600 - i, 800, 1] )
screen.blit(background_image2, (0, 600 - i), tr2)
pygame.display.update(tr2)
pygame.time.wait(duree)
#mettre tous les boutons en petits
# if const.GIdBtnSurvol != 99:
# if LstBtn != None :
# for obj in LstBtn.sprites() :
# obj.ShowSmallBtn()
const.GIdBtnSurvol = 99
screen.blit(background_image2, (0,0))
pygame.display.update()
#*******************************************************************************
# Change the mouse in hand #
#*******************************************************************************
#def ChangeMouseInHand(left, top):
## filename = os.path.join("images", 'souris.xbm')
## maskname = os.path.join("images", 'souris-mask.xbm')
## cursor = pygame.cursors.Load_xbm(filename, maskname)
## cursor = cursor[0], (cursor[0][0] / 2, cursor[0][1] / 2), cursor[2], cursor[3]
## pygame.mouse.set_cursor(cursor[0], (0, 0), cursor[2], cursor[3])
## filename = dirname = os.path.join(const.GRepPysycache, "images", 'souris.png')
# const.GMaSouris, imgtmprect = Load_image("images", 'souris.png')
# const.GMaSouris_position = const.GMaSouris.get_rect()
# const.GMaSouris_position.left = left
# const.GMaSouris_position.top = top
# const.GMaSourisOldPositionX = left
# const.GMaSourisOldPositionY = top
# pygame.mouse.set_pos((const.GMaSouris_position.left, const.GMaSouris_position.top))
#*******************************************************************************
# Attends le temps necessaire #
#*******************************************************************************
def Temporisation():
# const.Gclock.tick ( const.Gfps ) #max XXX fps / sec
#Note that this function uses SDL_Delay function which
#is not accurate on every platform, but does not use much cpu
pygame.time.wait(1)
#*******************************************************************************
# Show the FPS #
#*******************************************************************************
def ShowFPS():
if const.GDebug == 1:
# const.frames += 1
if pygame.time.get_ticks() - const.lastFPSTime >= 400:
# print "fps pygame=", const.Gclock.get_fps()
# #toutes les secondes, on affiche le nb de fps
# print "FPS:", const.frames
# const.frames = 0
const.lastFPSTime = pygame.time.get_ticks()
#*******************************************************************************
# Verification des limites de la souris : il ne faut pas qu'elle sorte #
# de la zone de jeux #
#*******************************************************************************
def VerifLimitesSouris(LimX = 780, LimY = 580, LimXX = 0, LimYY = 0):
if const.GMaSourisCurrentPositionX > LimX :
const.GMaSourisCurrentPositionX = LimX
if const.GMaSourisCurrentPositionY > LimY :
const.GMaSourisCurrentPositionY = LimY
if const.GMaSourisCurrentPositionX < LimXX :
const.GMaSourisCurrentPositionX = LimXX
if const.GMaSourisCurrentPositionY < LimYY :
const.GMaSourisCurrentPositionY = LimYY
#*******************************************************************************
# Charge le dictionnaire de la langue
#*******************************************************************************
def LoadDicoLang():
#vider
const.GDicoLangue.clear()
filename = os.path.join(const.GRepPysycache, "lang", const.GMyLocale, "textes.txt")
#lecture du fichier de langue
DebugMessage("")
DebugMessage("Reading the lang file %s " % filename )
if os.path.isfile(filename):
f = open(filename, 'r')
lignes = f.readlines()
for lig in lignes:
lig = lig.strip()
lig = lig.split('=')
if len(lig) < 2:
continue
const.GDicoLangue[lig[0]] = lig[1].decode("utf-8", "ignore")
f.close()
else:
DebugMessage("")
DebugMessage("Lang file doesn't exist")
#*******************************************************************************
#
#*******************************************************************************
def GetTextInLang(IdText, Default):
if const.GDicoLangue.has_key(IdText):
text = const.GDicoLangue[IdText]
else:
text = Default
return text
#*******************************************************************************
# Ecrit le texte dans la langue #
#*******************************************************************************
def WriteTextInLang(IdText, Default, image, left, top, size, largmax = -1):
"""Write a text on the screen in the locale lang \n
if left = -1 : the text is centered
"""
myfont = os.path.join(const.GRepPysycache, 'fonts', const.GFontName).encode(const.GConsoleLocale)
font = pygame.font.Font(myfont, size)
textcolor = 46, 113, 169
str = GetTextInLang(IdText, Default)
#OK text = font.render(unicode(username, "utf-8"), 1, textcolor).convert_alpha()
text = font.render(str , 1, textcolor).convert_alpha()
(larg, haut) = text.get_size()
if left == -1:
if largmax > 0 :
if larg > largmax:
larg = largmax
left = 10 + int( (720- larg) / 2 )
tr2 = pygame.Rect([0, 0, larg, haut] )
image.blit(text, (left, top), tr2 )
else:
left = 10 + int( (720- larg) / 2 )
image.blit(text, (left, top))
else:
if largmax > 0 :
if larg > largmax:
larg = largmax
tr2 = pygame.Rect([0, 0, larg, haut] )
image.blit(text, (left, top), tr2 )
else:
image.blit(text, (left, top))
#*******************************************************************************
#
#*******************************************************************************
def ShowHelpOfBoutonMenu(id, imgdest):
myfont = os.path.join(const.GRepPysycache, 'fonts', const.GFontName ).encode(const.GConsoleLocale)
font = pygame.font.Font(myfont, 20)
textcolor = 46, 113, 169
screen = pygame.display.get_surface()
myrep = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale )
#joue le fichier d'aide
if const.GWithSound == 1:
if const.GWithHelp == 1 :
dirname = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale)
filename = 'menu' + str(id) + '.ogg'
Load_sound(dirname, filename)
#affiche l'aide
if os.path.isdir(myrep):
filename = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale , 'menu' + str(id) + '.txt')
else :
filename = os.path.join(const.GRepPysycache, 'lang', 'en_EN' , 'menu' + str(id) + '.txt')
filename = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale , 'menu' + str(id) + '.txt')
if os.path.isfile(filename):
f = open(filename, 'r')
lignes = f.readlines()
cptligne = 0
for j in lignes:
j = j.strip()
# text = font.render(unicode(j, "utf-8"), 1, textcolor)
text = font.render(j.decode("utf-8", "ignore"), 1, textcolor)
imgdest.blit(text, (200, 361 + 25 * cptligne))
screen.blit(text, (200, 361 + 25 * cptligne))
cptligne += 1
f.close()
pygame.display.update()
#*******************************************************************************
#
#*******************************************************************************
def InitializePreferences():
#------ confrontation des pref utilisateur et valeurs par defaut -----------
if const.GPrefUserFromOptions.FullScreen == 0:
#valeur ecrasee par passage parametre
const.GWithFullScreen = 0
else:
const.GWithFullScreen = const.GPrefUserInit.FullScreen
if const.GPrefUserFromOptions.Sound == 0:
#valeur ecrasee par passage parametre
const.GWithSound = 0
else:
const.GWithSound = const.GPrefUserInit.Sound
if const.GDureeTransition != const.GPrefUserInit.Transition:
const.GDureeTransition = const.GPrefUserInit.Transition
#*******************************************************************************
#
#*******************************************************************************
def InitializeLang():
DebugMessage("")
DebugMessage ("Lang asked : %s " % const.GPrefUserFromOptions.Lang)
DebugMessage ("Detection of the lang")
if const.GPrefUserFromOptions.Lang != "":
#on a force la langue
DebugMessage("MyLocale comes from option ")
const.GMyLocale = const.GPrefUserFromOptions.Lang
else:
if const.GPrefUserInit.Lang != '':
#on prend la valeur du fichier de configuration
DebugMessage("MyLocale comes from file ")
const.GMyLocale = const.GPrefUserInit.Lang
else:
DebugMessage("MyLocale comes from automatic detection ")
const.GMyLocale = locale.getdefaultlocale()[0]
# locale.setlocale(locale.LC_ALL, localeold)
# print locale.getlocale()
# print myencoding
DebugMessage("MyLocale (Lang) found is %s " % const.GMyLocale)
if const.GMyLocale == None:
const.GMyLocale = 'en_EN'
if const.GMyLocale.strip() == "":
const.GMyLocale = 'en_EN'
myrep = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale )
if os.path.isdir(myrep):
#le repertoire de la locale existe : rien a faire
pass
else :
#chance 1 : on essaie sur les deux premiers caracteres en double (le pays)
#par exemple fr_FR en place de fr_BE
myrep = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale[0:2] + '_' + string.upper(const.GMyLocale[0:2]) )
if os.path.isdir(myrep):
const.GMyLocale = const.GMyLocale[0:2] + '_' + string.upper(const.GMyLocale[0:2])
else :
#chance 2 : on essaie sur le seul pays (par exemple fr)
myrep = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale[0:2] )
if os.path.isdir(myrep):
const.GMyLocale = const.GMyLocale[0:2]
else :
#valeur par defaut
const.GMyLocale = 'en_EN'
#test pour la police et les langes arabes
if const.GPrefUserFromOptions.FontName != "" :
#une langue a ete passee en parametres : on l'utilise
const.GFontName = const.GPrefUserFromOptions.FontName
else:
#aucune langue passe en parametres, mais est-ce
#une langue qui necessite une police speciale ?
if string.upper(const.GMyLocale[0:2]) == "AR" :
const.GFontName = "ae_AlMothnna_bold.ttf"
else:
const.GFontName = "FreeSansBold.ttf"
DebugMessage("Lang used = %s " % const.GMyLocale)
#*******************************************************************************
#
#*******************************************************************************
def ShowCreditsOfPySyCache(consoleadmin):
myfont = os.path.join(const.GRepPysycache, 'fonts', const.GFontName ).encode(const.GConsoleLocale)
font = pygame.font.Font(myfont, 30)
textcolor = 46, 113, 169
screen = pygame.display.get_surface()
#credits auteur
fichier = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale, 'credits.txt')
if os.path.isfile(fichier):
#afficher le contenu
f = open(fichier, 'r')
lignes = f.readlines()
cptligne = 0
for j in lignes:
j = j.strip()
# text = font.render(unicode(j, "utf-8"), 1, textcolor)
text = font.render(j.decode("utf-8", "ignore"), 1, textcolor)
screen.blit(text, (30, 30 + 40 * cptligne))
cptligne += 1
pygame.display.update()
f.close()
pygame.time.wait(3500)
#pub pour autres themes
fichier = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale, 'themes.txt')
if os.path.isfile(fichier):
const.Gbackground_image, background_rect = Load_image("images", "fond-themes.png")
ShowTransitionOfTheme(const.GDureeTransition, "fond-themes.png")
#afficher le contenu
f = open(fichier, 'r')
lignes = f.readlines()
cptligne = 0
for j in lignes:
j = j.rstrip()
# text = font.render(unicode(j, "utf-8"), 1, textcolor)
text = font.render(j.decode("utf-8", "ignore"), 1, textcolor)
screen.blit(text, (30, 30 + 40 * cptligne))
cptligne += 1
pygame.display.update()
f.close()
pygame.time.wait(3500)
#licence
fichier = os.path.join(const.GRepPysycache, 'lang', const.GMyLocale, 'licences.txt')
if os.path.isfile(fichier):
const.Gbackground_image, background_rect = Load_image("images", "fond-licences.png")
ShowTransitionOfTheme(const.GDureeTransition, "fond-licences.png")
#afficher le contenu
f = open(fichier, 'r')
lignes = f.readlines()
cptligne = 0
for j in lignes:
j = j.rstrip()
# text = font.render(unicode(j, "utf-8"), 1, textcolor)
text = font.render(j.decode("utf-8", "ignore"), 1, textcolor)
screen.blit(text, (30, 30 + 40 * cptligne))
cptligne += 1
pygame.display.update()
f.close()
#credit des themes
if const.GWithCredits :
pygame.time.wait(5000)
const.Gbackground_image, background_rect = Load_image("images", "fond5.png")
ShowTransitionOfTheme(const.GDureeTransition, "fond5.png")
#credit images for themes
if const.GAdmin == 0:
if consoleadmin == 0:
#credits de pysycache
const.AppMove.ReadCreditOfDirectory(const.GRepPysycache)
const.AppClick.ReadCreditOfDirectory(const.GRepPysycache)
const.AppButtons.ReadCreditOfDirectory(const.GRepPysycache)
const.AppDblClick.ReadCreditOfDirectory(const.GRepPysycache)
const.AppPuzzle.ReadCreditOfDirectory(const.GRepPysycache)
#credits des themes dans le rep des utilisateurs
if const.GPysyUserMode == 0:
#mode utilisateur simple
const.AppMove.ReadCreditOfDirectory(const.GRepPersoUser)
const.AppClick.ReadCreditOfDirectory(const.GRepPersoUser)
const.AppButtons.ReadCreditOfDirectory(const.GRepPersoUser)
const.AppDblClick.ReadCreditOfDirectory(const.GRepPersoUser)
const.AppPuzzle.ReadCreditOfDirectory(const.GRepPersoUser)
else:
#mode multiutilisateurs
for f in os.listdir( const.GRepUsersPysycache ):
dirname = os.path.join(const.GRepUsersPysycache, f)
if (os.path.isdir(dirname)):
const.AppMove.ReadCreditOfDirectory(dirname)
const.AppClick.ReadCreditOfDirectory(dirname)
const.AppButtons.ReadCreditOfDirectory(dirname)
const.AppDblClick.ReadCreditOfDirectory(dirname)
const.AppPuzzle.ReadCreditOfDirectory(dirname)
|