|
From: <vin...@us...> - 2010-06-13 15:51:35
|
Revision: 13
http://pacemaker.svn.sourceforge.net/pacemaker/?rev=13&view=rev
Author: vincentniakos
Date: 2010-06-13 15:51:28 +0000 (Sun, 13 Jun 2010)
Log Message:
-----------
Un comit de la nouvelle structure.
D?\195?\169sormais on charge le menu des actions par le fichier xml, ainsi que pour les sets.
Une barre de menu a ?\195?\169t?\195?\169 ajout?\195?\169e ?\195?\169galement. Elle s'ouvre par la touche "f1" et se ferme quand on clique en dehors de la zone
Pour le moment il y a un leger bug sur l'evenement click quand on a choisit l'action "aller" (l'icone verte), en effet seule la zone 2 fonctionne car il y a une erreur dans l'initialisation des sets avec les tableaux assosiatifs.
Modified Paths:
--------------
PACEmaker/src/apprentissage1.py
PACEmaker/src/apprentissage2.py
Added Paths:
-----------
PACEmaker/src/Asset.py
PACEmaker/src/Set.py
PACEmaker/src/SetParser.py
PACEmaker/src/Zone.py
PACEmaker/src/animation.py
PACEmaker/src/menuBarParser.py
PACEmaker/src/menuParser.py
Added: PACEmaker/src/Asset.py
===================================================================
--- PACEmaker/src/Asset.py (rev 0)
+++ PACEmaker/src/Asset.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -0,0 +1,23 @@
+#-*- coding:Utf-8 -*-
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+__author__="Eric Mercier <mer...@gm...>"
+__date__ ="$15 févr. 2010 18:44:25$"
+
+class Asset:
+
+ depth = None
+ file = None
+
+ def __init__(self):
+ """Documentation"""
+ self.depth = None
+ self.file = None
+
+ def to_string(self):
+ """Documentation"""
+ response = "Depth: " + self.depth
+ response+= "\nFile: " + self.file
+ return response
+
\ No newline at end of file
Added: PACEmaker/src/Set.py
===================================================================
--- PACEmaker/src/Set.py (rev 0)
+++ PACEmaker/src/Set.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -0,0 +1,59 @@
+#-*- coding:Utf-8 -*-
+from Asset import *
+from xml.dom import *
+
+__author__ = "Eric Mercier <mer...@gm...>"
+__date__ = "$14 févr. 2010 22:08:08$"
+
+
+class Set:
+ name = None
+ description = None
+ entryZones = None
+ exitZones = None
+ assets = None
+ zones = None
+
+ def __init__(self):
+ """Constructeur d'un set"""
+ self.name = None
+ self.description = None
+ self.entryZones = {}
+ self.exitZones = {}
+
+ def addAsset(self, nodeAsset):
+ if nodeAsset.nodeType == nodeAsset.ELEMENT_NODE :
+ asset = Asset()
+ try:
+ asset.depth = self.getText(nodeAsset.getAttributeNode("depth"))
+ asset.file = self.getText(nodeAsset.getAttributeNode("file"))
+ except:
+ print 'Un des TAGS suivant est manquant : depth, file'
+ self.assets.append(asset)
+
+ def getText(self, node):
+ return node.childNodes[0].nodeValue
+
+
+ def toString(self):
+ """Documentation"""
+ response = "Name: " + self.name
+
+ response += "\nDescription: " + self.description
+
+# response.append("Entry Zones: ")
+# response.append(self.entry_zones.to_string())
+#
+# response.append("Entry Zones: ")
+# reponse.append(self.entry_zones.to_string())
+#
+# response.append("Exit Zones: ")
+# reponse.append(self.exit_zones.to_string())
+#
+# response.append("Zones: ")
+# response.append(self.zones.to_string())
+#
+# response.append("Assets: ")
+# response.append(self.assets.to_string())
+
+ return response
Added: PACEmaker/src/SetParser.py
===================================================================
--- PACEmaker/src/SetParser.py (rev 0)
+++ PACEmaker/src/SetParser.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -0,0 +1,66 @@
+#-*- coding:Utf-8 -*-
+from Set import Set
+from Zone import Zone
+import pygame
+from pygame.locals import *
+import xml.dom.minidom
+
+__author__ = "Ong Vincent <Vin...@gm...>"
+__date__ = "$11 Juin. 2010 19:00:00$"
+
+
+class SetParser:
+ __currentNode__ = None
+ # __sets__ = listes des scenes
+ __sets__ = None
+ # activeSet : permet de connaitre le set courant
+ activeSet = "START"
+ # initialisation de la classe
+ def __init__(self, xml_path):
+ self.readXml(xml_path)
+ self.initSets()
+
+ #chargement du fichier xml contenant les sets
+ def readXml(self, xml_path):
+ self.doc = xml.dom.minidom.parse(xml_path)
+
+ #recup\xE9ration du premier noeud (racine) du fichier xml
+ def getRootElement(self):
+ if self.__currentNode__ == None:
+ self.__currentNode__ = self.doc.documentElement
+ return self.__currentNode__
+
+ #initialisation de la listes des sets
+ def initSets(self):
+ if self.__sets__ != None:
+ return
+ self.__sets__ = {}
+ for set in self.getRootElement().getElementsByTagName("set"):
+ if set.nodeType == set.ELEMENT_NODE:
+ s = Set()
+ try:
+ s.name = self.getText(set.getAttributeNode("name"))
+ s.description = set.getElementsByTagName("description")
+ s.assets = []
+ for assets in set.getElementsByTagName("assets"):
+ for asset in assets.getElementsByTagName("asset"):
+ s.addAsset(asset)
+ s.zones = {}
+ z = Zone()
+ for zone in set.getElementsByTagName("zones")[0].getElementsByTagName("zone") :
+ x = int(self.getText(zone.getAttributeNode("initX")))
+ y = int(self.getText(zone.getAttributeNode("initY")))
+ width = int(self.getText(zone.getAttributeNode("width")))
+ height = int(self.getText(zone.getAttributeNode("height")))
+ z.RectZone = pygame.Rect(x, y, width, height)
+ s.zones[self.getText(zone.getAttributeNode("name"))] = z
+ for exitZone in set.getElementsByTagName("exitZones")[0].getElementsByTagName("exitZone") :
+ s.exitZones[self.getText(exitZone.getAttributeNode("zoneName"))] = self.getText(exitZone.getAttributeNode("to"))
+ self.__sets__[self.getText(set.getAttributeNode("name"))] = s
+ except Exception as inst:
+ print "Erreur :", inst
+ #self.__sets__.append(s)
+ return self.__sets__
+
+ def getText(self, node):
+ return node.childNodes[0].nodeValue
Added: PACEmaker/src/Zone.py
===================================================================
--- PACEmaker/src/Zone.py (rev 0)
+++ PACEmaker/src/Zone.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -0,0 +1,12 @@
+#-*- coding: UTf-8 -*-
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+__author__="Vincent"
+__date__ ="$13 juin 2010 14:23:58$"
+
+class Zone :
+ RectZone = None
+
+ def __init__(self):
+ pass
\ No newline at end of file
Added: PACEmaker/src/animation.py
===================================================================
--- PACEmaker/src/animation.py (rev 0)
+++ PACEmaker/src/animation.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -0,0 +1,103 @@
+#! /usr/bin/python
+
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+__author__="Vincent"
+__date__ ="$13 juin 2010 01:14:04$"
+
+import pygame, sys, time
+from pygame.locals import *
+
+# set up pygame
+pygame.init()
+
+# set up the window
+WINDOWWIDTH = 400
+WINDOWHEIGHT = 400
+windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
+pygame.display.set_caption('Animation')
+
+# set up direction variables
+DOWNLEFT = 1
+DOWNRIGHT = 3
+UPLEFT = 7
+UPRIGHT = 9
+
+MOVESPEED = 4
+
+# set up the colors
+BLACK = (0, 0, 0)
+RED = (255, 0, 0)
+GREEN = (0, 255, 0)
+BLUE = (0, 0, 255)
+
+# set up the block data structure
+b1 = {'rect':pygame.Rect(300, 80, 50, 100), 'color':RED, 'dir':UPRIGHT}
+b2 = {'rect':pygame.Rect(200, 200, 20, 20), 'color':GREEN, 'dir':UPLEFT}
+b3 = {'rect':pygame.Rect(100, 150, 60, 60), 'color':BLUE, 'dir':DOWNLEFT}
+blocks = [b1, b2, b3]
+
+# run the game loop
+while True:
+ # check for the QUIT event
+ for event in pygame.event.get():
+ if event.type == QUIT:
+ pygame.quit()
+ sys.exit()
+
+ # draw the black background onto the surface
+ windowSurface.fill(BLACK)
+
+ for b in blocks:
+ # move the block data structure
+ if b['dir'] == DOWNLEFT:
+ b['rect'].left -= MOVESPEED
+ b['rect'].top += MOVESPEED
+ if b['dir'] == DOWNRIGHT:
+ b['rect'].left += MOVESPEED
+ b['rect'].top += MOVESPEED
+ if b['dir'] == UPLEFT:
+ b['rect'].left -= MOVESPEED
+ b['rect'].top -= MOVESPEED
+ if b['dir'] == UPRIGHT:
+ b['rect'].left += MOVESPEED
+ b['rect'].top -= MOVESPEED
+
+ # check if the block has move out of the window
+ if b['rect'].top < 0:
+ # block has moved past the top
+ if b['dir'] == UPLEFT:
+ b['dir'] = DOWNLEFT
+ if b['dir'] == UPRIGHT:
+ b['dir'] = DOWNRIGHT
+ if b['rect'].bottom > WINDOWHEIGHT:
+ # block has moved past the bottom
+ if b['dir'] == DOWNLEFT:
+ b['dir'] = UPLEFT
+ if b['dir'] == DOWNRIGHT:
+ b['dir'] = UPRIGHT
+ if b['rect'].left < 0:
+ # block has moved past the left side
+ if b['dir'] == DOWNLEFT:
+ b['dir'] = DOWNRIGHT
+ if b['dir'] == UPLEFT:
+ b['dir'] = UPRIGHT
+ if b['rect'].right > WINDOWWIDTH:
+ # block has moved past the right side
+ if b['dir'] == DOWNRIGHT:
+ b['dir'] = DOWNLEFT
+ if b['dir'] == UPRIGHT:
+ b['dir'] = UPLEFT
+
+ # draw the block onto the surface
+ pygame.draw.rect(windowSurface, b['color'], b['rect'])
+
+ # draw the window onto the screen
+ pygame.display.update()
+ time.sleep(0.02)
+
+
+
+if __name__ == "__main__":
+ print "Hello World";
Modified: PACEmaker/src/apprentissage1.py
===================================================================
--- PACEmaker/src/apprentissage1.py 2010-02-27 17:50:14 UTC (rev 12)
+++ PACEmaker/src/apprentissage1.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -1,218 +1,186 @@
#-*- coding:Utf-8 -*-
# To change this template, choose Tools | Templates
# and open the template in the editor.
-from pygame import cursors
+from menuBarParser import *
+from menuParser import *
+from SetParser import *
import math
-from pygame import mouse
import pygame
from pygame.locals import *
__author__ = "Vincent"
-__date__ = "$1 f�vr. 2010 21:52:29$"
+__date__ = "$1 f\xE8vr. 2010 21:52:29$"
if __name__ == "__main__":
- print "Hello World"
- colorkey = None
- icones = []
- #pygame.init()
+ print "Hello World"
+ colorkey = None
+ menuGame = None
+ icones = []
+ #pygame.init()
- #decorPath = os.path.join(os.getcwd(), '\\ressources\\images\\decord1.png')
- decorPath = "../ressources/images/decord1.png"
- imagePath = "../ressources/images/"
- print __file__
- print decorPath
- try:
- background = pygame.image.load(decorPath)
- except pygame.error, message:
- print "impossible d'ouvrir l'image"
- raise SystemExit, message
- backgroundRect = background.get_rect()
- size = (width, height) = background.get_size()
- screen = pygame.display.set_mode(size)
- if colorkey is not None:
- if colorkey is -1:
- colorkey = background.get_at((0, 0))
- background.set_colorkey(colorkey, RLEACCEL)
- running = 1
- icone_rect = []
- lstimage = ("icone1.png", "icone2.png", "icone3.png", "icone4.png")
- beta = 2 * math.pi / 4
- for i in range(4):
- icones.append(pygame.image.load(imagePath + lstimage[i]))
- icone_rect.append(icones[i].get_rect())
- isClick = 0
- while running:
- screen.blit(background, backgroundRect)
- event = pygame.event.poll()
- if event.type == pygame.QUIT:
- running = 0
- elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 3:
- print "mouse at (%d, %d)" % event.pos
- pos = x, y = event.pos
- for i in range(4):
- posx = round(math.cos(beta * i)*50,0)
- posy = round(math.sin(beta * i)*50,0)
- dx = x + posx - 32
- dy = y + posy - 32
- icone_rect[i] = icone_rect[i].move(dx, dy)
- print "position x :" , posx , " position y : ", posy , "\n"
- isClick = 1
- elif event.type == pygame.MOUSEBUTTONUP and event.button == 3:
- for i in range(4):
- posx = round(math.cos(beta * i)*50,0)
- posy = round(math.sin(beta * i)*50,0)
- dx = x + posx - 32
- dy = y + posy - 32
- icone_rect[i] = icone_rect[i].move(-dx, -dy)
- isClick = 0
- elif event.type == pygame.MOUSEMOTION and isClick ==1:
- print "ca bouge la souris"
- i = 0
- newPos = nx, ny = event.pos
- #mouseRec = Rect(5, 5, nx, ny)
- while i < 4:
- #if mouseRec.colliderect(icone_rect[i]):
- if icone_rect[i].collidepoint(newPos):
- break
- i = i + 1
- if i < 4:
- print "collision avec l'image : ", i+1
+ imagePath = '../ressources/images/'
+ decorPath = imagePath+"decord1.png"
+ persoPath = imagePath+"PersoTest.png"
- if isClick == 1:
- for i in range(4):
- screen.blit(icones[i], icone_rect[i])
-
- pygame.display.flip()
+ #creation de l'instance du menu en passant le fichier xml \xE0 charger
+ menuGame = Menu('../exemples/actionMenu.xml')
+ menuBar = MenuBar('../exemples/menuBar.xml')
+ lstSets = SetParser('../exemples/set.xml')
+
+ # Affiche dans la console le fichier courant avec son chemin absolu
+ print __file__
-"""
+ #chargement de la scene
+ try:
+ background = pygame.image.load(lstSets.__sets__[lstSets.activeSet].assets[0].file)
+ except pygame.error, message:
+ print "impossible d'ouvrir l'image"
+ raise SystemExit, message
+ backgroundRect = background.get_rect()
+ size = (width, height) = background.get_size()
+ screen = pygame.display.set_mode(size)
+ if colorkey is not None:
+ if colorkey is -1:
+ colorkey = background.get_at((0, 0))
+ background.set_colorkey(colorkey, RLEACCEL)
- def punch(self, target):
- "Renvoi true si le poing entre en collision avec la cible"
- if not self.punching:
- self.punching = 1
- hitbox = self.rect.inflate(-5, -5)
- return hitbox.colliderect(target.rect)
-class Personne:
+ """try:
+ background = pygame.image.load(decorPath)
+ except pygame.error, message:
+ print "impossible d'ouvrir l'image"
+ raise SystemExit, message
+ backgroundRect = background.get_rect()
+ size = (width, height) = background.get_size()
+ screen = pygame.display.set_mode(size)
+ if colorkey is not None:
+ if colorkey is -1:
+ colorkey = background.get_at((0, 0))
+ background.set_colorkey(colorkey, RLEACCEL)
+ """
- nom = None
- prenom = None
+ #isMenuBarOpen :permet de savoir si la barre de menu est ouverte ou non
+ isMenuBarOpen = 0
+ #initialisation de l'horloge pour la vitesse du jeux
+ clock = pygame.time.Clock()
- adresse = Adresse()
+ running = 1
+ # sizeIcone repr\xE9sente et l'\xE9chelle de distance qui permettra d'agrandir le cercle
+ sizeIcone = 1.5*menuGame.lstSousMenus[0].iconeMenu.get_width()
+ # isClick : permet de soit si on bouton est maintenu enfonc\xE9
+ isClick = 0
+ # imageActive permet de savoir si un sous menu doit \xEAtre affich\xE9 dans son \xE9tat actif ou non (quand le curseur est dessus)
+ # Sa valeur contient l'indice de la liste de sous menu, ou -1 si aucun sous menus n'a le curseur par dessus
+ imageActive = -1
+ actionToDo = "aller"
+ # execution des instructions principales en boucle
+ while running:
+ #on affiche dans un premier temps la scene
+ screen.blit(background, backgroundRect)
+ #si \xE9v\xE9nement est rencontr\xE9...
+ event = pygame.event.poll()
+ if event.type == pygame.QUIT: #si on demande de quitter on arr\xEAte l'executiondu programme
+ running = 0
+ elif event.type is KEYDOWN and event.key == 282 and isMenuBarOpen == 0 :
+ #menuBar.showMenu()
+ isMenuBarOpen = 1
+ elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 3: #si le bouton droit est enfonc\xE9 ...
+ #on r\xE9cup\xE8re les coordonn\xE9ees de la souris
+ pos = x, y = event.pos
+ # On place les elements du menu de fa\xE7on circulaire
+ for i in range(menuGame.nbElemMenu):
+ if i > 7 :
+ nbCircleMenu = menuGame.nbElemMenu%8
+ coef = 1+(i/7)
+ if nbCircleMenu == 0 :
+ posx = round(math.cos(menuGame.beta * i)*coef*sizeIcone,0)
+ posy = round(math.sin(menuGame.beta* i)*coef*sizeIcone,0)
+ else :
+ betaBis = 2 * math.pi / nbCircleMenu
+ posx = round(math.cos(betaBis * i)*coef*sizeIcone,0)
+ posy = round(math.sin(betaBis * i)*coef*sizeIcone,0)
+ else :
+ posx = round(math.cos(menuGame.beta * i)*sizeIcone,0)
+ posy = round(math.sin(menuGame.beta* i)*sizeIcone,0)
+ sizex = menuGame.lstSousMenus[i].iconeMenu.get_width()
+ sizey = menuGame.lstSousMenus[i].iconeMenu.get_height()
+ dx = x + posx - (sizex/2)
+ dy = y + posy - (sizey/2)
+ menuGame.lstSousMenus[i].imagePos = menuGame.lstSousMenus[i].imagePos.move(dx, dy)
+ #print "position x :" , posx , " position y : ", posy , "\n"
+ isClick = 1
+ elif event.type == pygame.MOUSEBUTTONUP and event.button == 3:
+ for i in range(menuGame.nbElemMenu):
+ if i > 7 :
+ nbCircleMenu = menuGame.nbElemMenu%8
+ coef = 1+(i/7)
+ if nbCircleMenu == 0 :
+ posx = round(math.cos(menuGame.beta * i)*coef*sizeIcone,0)
+ posy = round(math.sin(menuGame.beta* i)*coef*sizeIcone,0)
+ else :
+ betaBis = 2 * math.pi / nbCircleMenu
+ posx = round(math.cos(betaBis * i)*coef*sizeIcone,0)
+ posy = round(math.sin(betaBis * i)*coef*sizeIcone,0)
+ else :
+ posx = round(math.cos(menuGame.beta * i)*sizeIcone,0)
+ posy = round(math.sin(menuGame.beta* i)*sizeIcone,0)
+ sizex = menuGame.lstSousMenus[i].iconeMenu.get_width()
+ sizey = menuGame.lstSousMenus[i].iconeMenu.get_height()
+ dx = x + posx - (sizex/2)
+ dy = y + posy - (sizey/2)
+ menuGame.lstSousMenus[i].imagePos = menuGame.lstSousMenus[i].imagePos.move(-dx, -dy)
+ isClick = 0
+ elif event.type == pygame.MOUSEBUTTONUP and event.button == 1:
+ i = 0
+ newPos = nx, ny = event.pos
+ if isClick==1:
+ while i < menuGame.nbElemMenu:
+ if menuGame.lstSousMenus[i].imagePos.collidepoint(newPos):
+ #print "Action a effectuer : "+menuGame.lstSousMenus[i].action
+ actionToDo = menuGame.lstSousMenus[i].action
+ break
+ i = i + 1
+ elif isMenuBarOpen == 1 and (ny > menuBar.menuButtons[0].imagePos.bottom or
+ (ny <= menuBar.height and nx > menuBar.width ) ):
+ #menuBar.hideMenu()
+ isMenuBarOpen = 0
+ elif actionToDo == "aller":
+ activeSet = lstSets.activeSet
+ for zone in lstSets.__sets__[activeSet].zones :
+ print lstSets.__sets__[activeSet].zones
+ if lstSets.__sets__[activeSet].zones[zone].RectZone.collidepoint(newPos) :
+ print "collisionnnn"
+ lstSets.activeSet = lstSets.__sets__[activeSet].exitZones[zone]
+ try:
+ background = pygame.image.load(lstSets.__sets__[lstSets.activeSet].assets[0].file)
+ except pygame.error, message:
+ print "impossible d'ouvrir l'image"
+ raise SystemExit, message
+ break
+ elif event.type == pygame.MOUSEMOTION and isClick ==1:
+ i = 0
+ newPos = nx, ny = event.pos
+ while i < menuGame.nbElemMenu:
+ if menuGame.lstSousMenus[i].imagePos.collidepoint(newPos):
+ break
+ i = i + 1
+ if i < menuGame.nbElemMenu:
+ imageActive = i
+ else :
+ imageActive = -1
+ if isMenuBarOpen== 1 :
+ for unMenu in menuBar.menuButtons :
+ screen.blit(unMenu.image, unMenu.imagePos)
+ if isClick == 1:
+ for i in range(menuGame.nbElemMenu):
+ if i==imageActive :
+ screen.blit(menuGame.lstSousMenus[i].iconeActiveMenu, menuGame.lstSousMenus[i].imagePos)
+ else :
+ screen.blit(menuGame.lstSousMenus[i].iconeMenu, menuGame.lstSousMenus[i].imagePos)
- def __init__(self):
-
- pass
-
-
-
-class Adresse:
-
- ville = None
-
-
-
- def __init__(self):
-
- pass
-
-
-
-class TransformXmlToPersonnes:
-
-
-
- __currentNode__ = None
-
- __personneList__ = None
-
-
-
- def __init__(self):
-
- self.readXml()
-
-
-
- def readXml(self):
-
- from xml.dom.minidom import parse
-
- self.doc = parse('E:/python/samplexml/personnes.xml')
-
-
-
- def getRootElement(self):
-
- if self.__currentNode__ == None:
-
- self.__currentNode__ = self.doc.documentElement
-
- return self.__currentNode__
-
-
-
- def getPersonnes(self):
-
- if self.__personneList__ != None:
-
- return
-
- self.__personneList__ = []
-
- for personnes in self.getRootElement().getElementsByTagName("personne"):
-
- if personnes.nodeType == personnes.ELEMENT_NODE:
-
- p = Personne()
-
- try:
-
- p.nom = self.getText(personnes.getElementsByTagName("nom")[0])
-
- p.prenom = self.getText(personnes.getElementsByTagName("prenom")[0])
-
- p.adresse = self.getAdresse(personnes.getElementsByTagName("adresse")[0])
-
- except:
-
- print 'Un des TAGS suivant est manquents : nom, prenom, adresse'
-
- self.__personneList__.append(p)
-
- return self.__personneList__
-
-
-
- def getAdresse(self, node):
-
- adress = Adresse()
-
- try:
-
- adress.ville = self.getText(node.getElementsByTagName("ville")[0])
-
- except:
-
- adress.ville = None
-
- return adress
-
-
-
- def getText(self, node):
-
- return node.childNodes[0].nodeValue
-
-
-
-if __name__ == "__main__":
-
- x=TransformXmlToPersonnes()
-
- print x.getPersonnes()[1].nom
-"""
+ #pygame.display.update()
+ pygame.display.flip()
\ No newline at end of file
Modified: PACEmaker/src/apprentissage2.py
===================================================================
--- PACEmaker/src/apprentissage2.py 2010-02-27 17:50:14 UTC (rev 12)
+++ PACEmaker/src/apprentissage2.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -7,7 +7,7 @@
from scenarii.SetParser import SetParser
__author__ = "Eric"
-__date__ = "$15 fèvr. 2010 21:52:29$"
+__date__ = "$15 fevrier. 2010 21:52:29$"
if __name__ == "__main__":
Added: PACEmaker/src/menuBarParser.py
===================================================================
--- PACEmaker/src/menuBarParser.py (rev 0)
+++ PACEmaker/src/menuBarParser.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -0,0 +1,84 @@
+#-*- coding:Utf-8 -*-
+#To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+import pygame
+from pygame.locals import *
+import xml.dom.minidom
+
+
+
+__author__="Ong Vincent"
+__date__ ="$Jun 12, 2010 01:00:00 AM$"
+
+class MenuBar :
+ __currentNode__ = None
+ menuButtons = None
+ height = None
+ width = None
+
+ def __init__(self, xml_path):
+ self.readXml(xml_path)
+ self.initMenuBar()
+
+ def readXml(self, xml_path):
+ self.doc = xml.dom.minidom.parse(xml_path)
+
+ def getRootElement(self):
+ if self.__currentNode__ == None:
+ self.__currentNode__ = self.doc.documentElement
+ return self.__currentNode__
+
+
+ def initMenuBar(self):
+ #Si le menu est d\xE9j\xE0 charg\xE9 on ne relit pas le fichier xml
+ if self.menuButtons != None:
+ return
+ self.menuButtons = []
+ self.width = 0
+ self.height = 0
+ for menu in self.getRootElement().getElementsByTagName("menu"):
+ if menu.nodeType == menu.ELEMENT_NODE:
+ m = Menu()
+ try:
+ m.action = menu.getAttributeNode("action").nodeValue
+ m.image = pygame.image.load(self.getText(menu.getElementsByTagName("image")[0]))
+ m.imagePos = m.image.get_rect()
+ m.imagePos.left = self.width
+ self.width += m.imagePos.width
+ except:
+ print 'Un des TAGS suivant est manquant : action, image'
+
+ self.menuButtons.append(m)
+ if len(self.menuButtons) >0:
+ self.height = self.menuButtons[0].imagePos.height
+
+ def getText(self, node):
+ return node.childNodes[0].nodeValue
+
+ def getAllMenu(self):
+ return self.menuButtons
+
+ def getMenu(self, indice):
+ return self.menuButtons[indice]
+
+ def addMenu(self, sousMenu):
+ self.menuButtons.append(sousMenu)
+
+ def removeMenu(self, indice):
+ del self.menuButtons[indice]
+
+ def hideMenu(self):
+ for menu in self.menuButtons :
+ menu.imagePos.bottom = 0
+
+ def showMenu(self):
+ for menu in self.menuButtons :
+ menu.imagePos.bottom = self.height
+class Menu:
+ action = None
+ imagePos = None
+ image = None
+
+ def __init__(self):
+ pass
Added: PACEmaker/src/menuParser.py
===================================================================
--- PACEmaker/src/menuParser.py (rev 0)
+++ PACEmaker/src/menuParser.py 2010-06-13 15:51:28 UTC (rev 13)
@@ -0,0 +1,81 @@
+#-*- coding:Utf-8 -*-
+# Fichier menu.py permettant la cr\xE9ation du menu depuis un fichier xml
+import math
+import pygame
+from pygame.locals import *
+import xml.dom.minidom
+
+
+
+__author__="Ong Vincent"
+__date__ ="$Jun 11, 2010 18:00:00 PM$"
+
+class Menu:
+ __currentNode__ = None
+ lstSousMenus = None
+ nbElemMenu = None
+ beta = None
+ #beta = 2 * math.pi / nbElemMenu
+
+ def __init__(self, fichierMenu):
+ self.readXml(fichierMenu)
+ self.initMenu()
+ self.nbElemMenu = len(self.lstSousMenus)
+ if self.nbElemMenu < 8 :
+ self.beta = 2 * math.pi / self.nbElemMenu
+ else :
+ self.beta = 2 * math.pi / 8
+
+ def readXml(self, xml_path):
+ self.doc = xml.dom.minidom.parse(xml_path)
+
+
+ def getRootElement(self):
+ if self.__currentNode__ == None:
+ self.__currentNode__ = self.doc.documentElement
+ return self.__currentNode__
+
+
+ def initMenu(self):
+ #Si le menu est d\xE9j\xE0 charg\xE9 on ne relit pas le fichier xml
+ if self.lstSousMenus != None:
+ return
+ self.lstSousMenus = []
+ for unSousMenu in self.getRootElement().getElementsByTagName("action"):
+ if unSousMenu.nodeType == unSousMenu.ELEMENT_NODE:
+ sm = SousMenu()
+ try:
+ sm.action = unSousMenu.getAttributeNode("name").nodeValue
+ sm.iconeMenu = pygame.image.load(self.getText(unSousMenu.getElementsByTagName("icone")[0]))
+ sm.iconeActiveMenu = pygame.image.load(self.getText(unSousMenu.getElementsByTagName("active")[0]))
+ sm.imagePos = sm.iconeMenu.get_rect();
+ except:
+ print 'Un des TAGS suivant est manquents : action, icone, active'
+
+ self.lstSousMenus.append(sm)
+
+ def getText(self, node):
+ return node.childNodes[0].nodeValue
+
+ def getAllSousMenu(self):
+ return self.lstSousMenus
+
+ def getSousMenu(self, indice):
+ return self.lstSousMenus[indice]
+
+ def addSousMenu(self, sousMenu):
+ self.lstSousMenus.append(sousMenu)
+
+ def removeSousMenu(self, indice):
+ del self.lstSousMenus[indice]
+
+
+
+class SousMenu:
+ action = None
+ imagePos = None
+ iconeMenu = None
+ iconeActiveMenu = None
+
+ def __init__(self):
+ pass
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|