From 29f122c98491893482a32f6d1f19e9f64a022f61 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Thu, 22 Oct 2009 03:48:01 +0000 Subject: agrego los archivos iniciales --- diff --git a/Animals.py b/Animals.py new file mode 100644 index 0000000..9b3943e --- /dev/null +++ b/Animals.py @@ -0,0 +1,348 @@ +### By Gonzalo Odiard, 2006 godiard at gmail.com +### GPL License - http://www.gnu.org/copyleft/gpl.html + +import gobject, gtk , cairo,os +import random +import World + +print "Init aimals" + +def getRandomDirection(): + return 1+int(random.random()*7) + +# Deltas +# 1 2 3 +# 8 X 4 +# 7 6 5 + +def getNextDirection(direction): + if (direction == 8): + return 1 + else: + return direction + 1 + +def getDeltaX(direction): + #print "getDeltaX",direction + if (direction == 1) or (direction == 8) or (direction == 7): + return -1 + if (direction == 2) or (direction == 6): + return 0 + if (direction == 3) or (direction == 4) or (direction == 5): + return 1 + return 0 +def getDeltaY(direction): + #print "getDeltaY",direction + if (direction == 1) or (direction == 2) or (direction == 3): + return -1 + if (direction == 8) or (direction == 4): + return 0 + if (direction == 7) or (direction == 6) or (direction == 5): + return 1 + return 0 + + +def getState(world,x,y): + # verify limits + if (x >= World.CANT_TILES-1): + x = 0 + if (y >= World.CANT_TILES-1): + y = 0 + if (x < 0): + x = World.CANT_TILES-2 + if (y < 0): + y = World.CANT_TILES-2 + #print "getState",x,y,world.state[x][y].STATE + return world.state[x][y].STATE + +def internalMove(world,x,y,direction): + tentativeX = x + int(getDeltaX(direction)) + tentativeY = y + int(getDeltaY(direction)) + if (tentativeX >= World.CANT_TILES-1): + tentativeX = 0 + if (tentativeY >= World.CANT_TILES-1): + tentativeY = 0 + if (tentativeX < 0): + tentativeX = World.CANT_TILES-2 + if (tentativeY < 0): + tentativeY = World.CANT_TILES-2 + return tentativeX,tentativeY + + + +class AbstractAnimal: + + edadMaxima = 100 + madurezSexual = 50 + nivelCadenaAlimenticia = 1 + minFrecuenciaAlimentacion = 10 + maxFrecuenciaAlimentacion = 1 + especie = "Indefinida" + maxNumeroCrias = 4 + frecuenciaSexual = 10 + + def __init__(self,x,y): + print "Iniciando AbstractAnimal" + self.orden = 0 + self.edad = 30 + self.sexo = "F" + self.ultimaActSexual = self.edad + self.ultimaAlimentacion = self.edad + self.posX = x + self.posY = y + self.ultimaDireccion = -1 + + def draw(ctx): + print "Draw" + + def move(self): + print "Move" + + def checkLive(self): + if (self.edad > self.edadMaxima): + print "Muere por edad" + return False + elif ((self.edad - self.ultimaAlimentacion) > self.minFrecuenciaAlimentacion): + print "Muere por falta de alimentacion" + return False + else: + return True + +# RABBIT + +class Rabbit(AbstractAnimal): + #print "Inicio conejo" + + path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"images") + + imageSmallMale = cairo.ImageSurface.create_from_png (os.path.join(path,"rabbit_small_m.png")) + imageSmallFem = cairo.ImageSurface.create_from_png (os.path.join(path,"rabbit_small_f.png")) + imageMale = cairo.ImageSurface.create_from_png (os.path.join(path,"rabbit_m.png")) + imageFem = cairo.ImageSurface.create_from_png (os.path.join(path,"rabbit_f.png")) + + especie = "Rabbit" + + + def __init__(self,x,y,world): + #print "Iniciando Rabbit" + self._world = world + + self.orden = 0 + self.edad = 1 + self.sexo = "F" + if (random.random() > 0.5): + self.sexo = "M" + self.ultimaActSexual = self.edad + self.ultimaAlimentacion = self.edad + self.posX = x + self.posY = y + self.ultimaDireccion = -1 + self.edadMaxima = world.rabbit_data.edadMaxima + self.madurezSexual = world.rabbit_data.madurezSexual + self.frecuenciaSexual = world.rabbit_data.frecuenciaSexual + self.nivelCadenaAlimenticia = world.rabbit_data.nivelCadenaAlimenticia + self.minFrecuenciaAlimentacion = world.rabbit_data.minFrecuenciaAlimentacion + self.maxFrecuenciaAlimentacion = world.rabbit_data.maxFrecuenciaAlimentacion + self.maxNumeroCrias = world.rabbit_data.maxNumeroCrias + + def draw(self,ctx): + #print "Draw" + x1 = World.MARGEN+(self.posX*World.SIZE_TILE) + y1 = World.MARGEN +(self.posY*World.SIZE_TILE) + ctx.move_to(x1,y1) + ctx.translate(x1,y1) + ctx.rectangle(0,0,World.SIZE_TILE,World.SIZE_TILE); + ctx.set_source_rgb(146.0/256.0,98.0/256.0,46.0/256.0) + if (self.sexo == "M"): + if (self.edad < self.madurezSexual): + ctx.set_source_surface(Rabbit.imageSmallMale,1,1) + else: + ctx.set_source_surface(Rabbit.imageMale,1,1) + if (self.sexo == "F"): + if (self.edad < self.madurezSexual): + ctx.set_source_surface(Rabbit.imageSmallFem,1,1) + else: + ctx.set_source_surface(Rabbit.imageFem,1,1) + + ctx.fill() + + + def move(self,world): + self.edad = self.edad + 1 + + # eat + if (world.state[self.posX][self.posY].STATE >=1): + world.state[self.posX][self.posY].STATE = world.state[self.posX][self.posY].STATE - 3 + if (world.state[self.posX][self.posY].STATE <0): + world.state[self.posX][self.posY].STATE = 0 + self.ultimaAlimentacion = self.edad + + # move + if (self.ultimaDireccion == -1) : + self.ultimaDireccion = getRandomDirection() + # verify green in the next position + self.tentativeX,self.tentativeY = internalMove(world,self.posX,self.posY,self.ultimaDireccion) + self.tentativeDirection = getNextDirection(self.ultimaDireccion) + + while ((getState(world,self.tentativeX,self.tentativeY) == 0) and + (self.tentativeDirection != self.ultimaDireccion)): + #print self.tentativeX, self.tentativeY, self.tentativeDirection, self.ultimaDireccion + self.tentativeX,self.tentativeY = internalMove(world,self.posX,self.posY,self.tentativeDirection) + self.tentativeDirection = getNextDirection(self.tentativeDirection) + + self.posX = self.tentativeX + self.posY = self.tentativeY + + # if female verify for male rabbit + if ((self.sexo == "F") and + (self.edad > self.madurezSexual) and + ((self.edad - self.ultimaActSexual) > self.frecuenciaSexual)): + + animalsNearArray = world.animalsNear(self.posX,self.posY) + if (len(animalsNearArray) > 0): + maleOk = False + n = 0 + while (n < len(animalsNearArray) and not (maleOk)): + nearAnimal = animalsNearArray[n] + if ((nearAnimal.sexo == "M") and + (nearAnimal.especie == self.especie) and + (nearAnimal.edad > self.madurezSexual) and + ((nearAnimal.edad - nearAnimal.ultimaActSexual) > self.frecuenciaSexual)): + # born rabbits + self.ultimaActSexual = self.edad + cantCrias = int(random.random()*self.maxNumeroCrias) + for n in range(cantCrias): + child = Rabbit(self.posX,self.posY,self._world) + world.animals.append(child) + print "Nace conejo" + # salgo del while + maleOk = True + + n = n + 1 + + +# FOX + +class Fox(AbstractAnimal): + #print "Inicio zorro" + + path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"images") + + imageSmallMale = cairo.ImageSurface.create_from_png (os.path.join(path,"fox_small_m.png")) + imageSmallFem = cairo.ImageSurface.create_from_png (os.path.join(path,"fox_small_f.png")) + imageMale = cairo.ImageSurface.create_from_png (os.path.join(path,"fox_m.png")) + imageFem = cairo.ImageSurface.create_from_png (os.path.join(path,"fox_f.png")) + + especie = "Fox" + + def __init__(self,x,y,world): + #print "Iniciando Fox" + self._world = world + + self.orden = 0 + self.edad = 1 + self.sexo = "F" + if (random.random() > 0.5): + self.sexo = "M" + self.ultimaActSexual = self.edad + self.minFrecuenciaAlimentacion = 30 + self.ultimaAlimentacion = self.edad + self.posX = x + self.posY = y + self.ultimaDireccion = -1 + self.maxNumeroCrias = 2 + + self.edadMaxima = world.fox_data.edadMaxima + self.madurezSexual = world.fox_data.madurezSexual + self.frecuenciaSexual = world.fox_data.frecuenciaSexual + self.nivelCadenaAlimenticia = world.fox_data.nivelCadenaAlimenticia + self.minFrecuenciaAlimentacion = world.fox_data.minFrecuenciaAlimentacion + self.maxFrecuenciaAlimentacion = world.fox_data.maxFrecuenciaAlimentacion + self.maxNumeroCrias = world.fox_data.maxNumeroCrias + + + def draw(self,ctx): + #print "Draw" + x1 = World.MARGEN+(self.posX*World.SIZE_TILE) + y1 = World.MARGEN +(self.posY*World.SIZE_TILE) + ctx.move_to(x1,y1) + ctx.translate(x1,y1) + ctx.rectangle(0,0,World.SIZE_TILE,World.SIZE_TILE); + ctx.set_source_rgb(146.0/256.0,98.0/256.0,46.0/256.0) + if (self.sexo == "M"): + if (self.edad < self.madurezSexual): + ctx.set_source_surface(Fox.imageSmallMale,1,1) + else: + ctx.set_source_surface(Fox.imageMale,1,1) + if (self.sexo == "F"): + if (self.edad < self.madurezSexual): + ctx.set_source_surface(Fox.imageSmallFem,1,1) + else: + ctx.set_source_surface(Fox.imageFem,1,1) + + ctx.fill() + + + def move(self,world): + self.edad = self.edad + 1 + + # move + if (self.ultimaDireccion == -1) : + self.ultimaDireccion = getRandomDirection() + # verify green in the next position + self.tentativeX,self.tentativeY = internalMove(world,self.posX,self.posY,self.ultimaDireccion) + self.tentativeDirection = getNextDirection(self.ultimaDireccion) + + while ((getState(world,self.tentativeX,self.tentativeY) == 0) and + (self.tentativeDirection != self.ultimaDireccion)): + #print self.tentativeX, self.tentativeY, self.tentativeDirection, self.ultimaDireccion + self.tentativeX,self.tentativeY = internalMove(world,self.posX,self.posY,self.tentativeDirection) + self.tentativeDirection = getNextDirection(self.tentativeDirection) + + self.posX = self.tentativeX + self.posY = self.tentativeY + + # eat + animalsNearArray = world.animalsNear(self.posX,self.posY) + if ((self.edad - self.ultimaAlimentacion) > self.maxFrecuenciaAlimentacion ): + if (len(animalsNearArray) > 0): + n = 0 + eat = False + while ((n < len(animalsNearArray)) and not eat): + nearAnimal = animalsNearArray[n] + if (nearAnimal.nivelCadenaAlimenticia < self.nivelCadenaAlimenticia): + print "Comer conejo!!" + n = n+1 + world.animals.remove(nearAnimal) + eat = True + self.ultimaAlimentacion = self.edad + n = n+1 + + # if female verify for male fox + if ((self.sexo == "F") and + (self.edad > self.madurezSexual) and + ((self.edad - self.ultimaActSexual) > self.frecuenciaSexual)): + + if (len(animalsNearArray) > 0): + maleOk = False + n = 0 + while (n < len(animalsNearArray) and not (maleOk)): + nearAnimal = animalsNearArray[n] + if ((nearAnimal.sexo == "M") and + (nearAnimal.especie == self.especie) and + (nearAnimal.edad > self.madurezSexual) and + ((nearAnimal.edad - nearAnimal.ultimaActSexual) > self.frecuenciaSexual) ): + #print "IUPI!!!!" + # born foxs + self.ultimaActSexual = self.edad + cantCrias = int(random.random()*self.maxNumeroCrias) + for n in range(cantCrias): + child = Fox(self.posX,self.posY,self._world) + world.animals.append(child) + print "Nace zorro" + # salgo del while + maleOk = True + + n = n + 1 + + + diff --git a/Green.py b/Green.py new file mode 100644 index 0000000..41f04cf --- /dev/null +++ b/Green.py @@ -0,0 +1,96 @@ +### By Gonzalo Odiard, 2006 godiard at gmail.com +### GPL License - http://www.gnu.org/copyleft/gpl.html + +import gobject, gtk , cairo, os +import World + +print "Init Green" +path = os.path.join(os.path.dirname(os.path.abspath(__file__)),"images") + +print "Despues de ver el path" +image1 = cairo.ImageSurface.create_from_png (os.path.join(path,"green1.png")) +image2 = cairo.ImageSurface.create_from_png (os.path.join(path,"green2.png")) +image3 = cairo.ImageSurface.create_from_png (os.path.join(path,"green3.png")) +image4 = cairo.ImageSurface.create_from_png (os.path.join(path,"green4.png")) + +def getImagesGreen(world,ctx,n,p): + state = world.state[n][p].STATE + x1 = World.MARGEN+(World.SIZE_TILE*n) + y1 = World.MARGEN +(World.SIZE_TILE*p) + ctx.move_to(x1,y1) + ctx.translate(x1,y1) + ctx.rectangle(0,0,World.SIZE_TILE,World.SIZE_TILE); + ctx.set_source_rgb(146.0/256.0,98.0/256.0,46.0/256.0) + if state ==1: + ctx.set_source_surface(image1,1,1) + elif state ==2: + ctx.set_source_surface(image2,1,1) + elif state ==3: + ctx.set_source_surface(image3,1,1) + elif state ==4: + ctx.set_source_surface(image4,1,1) + ctx.fill() + +# MARRON RGB 146,98,46 +# VERDE1 166,202,128 +# VERDE2 127,175,76 +# VERDE3 102,160,40 +# VERDE4 78,143,8 + +def getColorTile(world,ctx,n,p): + state = world.state[n][p].STATE + #print state + x1 = World.MARGEN+(World.SIZE_TILE*n) + y1 = World.MARGEN +(World.SIZE_TILE*p) + ctx.move_to(x1,y1) + ctx.rectangle(x1,y1,World.SIZE_TILE,World.SIZE_TILE); + + if state == 0: + ctx.set_source_rgb(146.0/256.0,98.0/256.0,46.0/256.0) + elif state ==1: + ctx.set_source_rgb(166.0/256.0,202.0/256.0,128.0/256.0) + elif state ==2: + ctx.set_source_rgb(127.0/256.0,175.0/256.0,76.0/256.0) + elif state ==3: + ctx.set_source_rgb(102.0/256.0,160.0/256.0,40.0/256.0) + elif state ==4: + ctx.set_source_rgb(78.0/256.0,143.0/256.0,8.0/256.0) + ctx.fill() + + +def grow(world): + for n in range(0,World.CANT_TILES-1): + for p in range(0,World.CANT_TILES-1): + if ((world.state[n][p].STATE != 0) and + (world.state[n][p].STATE < 4)): + world.state[n][p].STATE = world.state[n][p].STATE + 1 + x1 = World.MARGEN+(World.SIZE_TILE*n) + y1 = World.MARGEN +(World.SIZE_TILE*p) + #drawingarea.queue_draw_area(x1, y1, World.SIZE_TILE, World.SIZE_TILE) + level = 0 + if (world.state[n][p].STATE == 0): + if (n != 0) and (world.state[n-1][p].STATE > 1): + level = level + world.state[n-1][p].STATE + if ((n != 0) and (p != 0) and + (world.state[n-1][p-1].STATE > 1)): + level = level + world.state[n-1][p-1].STATE + if ((n != 0) and (p < World.CANT_TILES) and + (world.state[n-1][p+1].STATE > 1)): + level = level + world.state[n-1][p+1].STATE + if (p != 0) and (world.state[n][p-1].STATE > 1): + level = level + world.state[n][p-1].STATE + if (p < World.CANT_TILES) and (world.state[n][p+1].STATE > 1): + level = level + world.state[n][p+1].STATE + if (n < World.CANT_TILES) and (world.state[n+1][p].STATE > 1): + level = level + world.state[n+1][p].STATE + if ((n < World.CANT_TILES) and (p != 0) and + (world.state[n+1][p-1].STATE > 1)): + level = level + world.state[n+1][p-1].STATE + if ((n < World.CANT_TILES) and (p < World.CANT_TILES) and + (world.state[n+1][p+1].STATE > 1 )): + level = level + world.state[n+1][p+1].STATE + if (level > 3): + world.state[n][p].STATE = 1 + x1 = World.MARGEN+(World.SIZE_TILE*n) + y1 = World.MARGEN +(World.SIZE_TILE*p) + #drawingarea.queue_draw_area(x1, y1, World.SIZE_TILE, World.SIZE_TILE) diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..c4adb99 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,41 @@ +Todo.txt +World.py +ecomundo.py +ChangeLog +glade_util.py +Changelog.txt +ecomundoactivity.py +setup.py +Animals.py +Green.py +locale/es/activity.linfo +locale/es/LC_MESSAGES/org.laptop.sample.Ecomundo.mo +po/Ecomundo.pot +po/es.po +po/es.mo +po/POTFILES.in +images/rabbit_small_f.png +images/rabbit_small_m.png +images/fox_m.png +images/fox_small.png +images/fox_f.png +images/green3.png +images/fox.png +images/green2.png +images/rabbit_f.png +images/rabbit.png +images/green4.svg +images/green3.svg +images/rabbit_small.png +images/fox_small_m.png +images/green4.png +images/rabbit_m.png +images/green1.svg +images/fox_small_f.png +images/green1.png +images/green2.svg +activity/activity-ecomundo.svg +activity/activity-web.svg +activity/activity-ecomundo3.svg +activity/activity-ecomundo2.svg +activity/activity.info diff --git a/World.py b/World.py new file mode 100644 index 0000000..58c6a3e --- /dev/null +++ b/World.py @@ -0,0 +1,54 @@ +### By Gonzalo Odiard, 2006 godiard at gmail.com +### GPL License - http://www.gnu.org/copyleft/gpl.html + +# inicializacion +MARGEN = 10 +SIZE_WORLD = 800 # 700 +CANT_TILES = 25 # 30 +print "*** calculo SIZE " +SIZE_TILE = int((SIZE_WORLD - MARGEN * 2) / CANT_TILES) +print "Size tile:", SIZE_TILE + +class RabbitData: + edadMaxima = 100 + madurezSexual = 20 + frecuenciaSexual = 10 + nivelCadenaAlimenticia = 1 + minFrecuenciaAlimentacion = 10 + maxFrecuenciaAlimentacion = 1 + maxNumeroCrias = 5 + + +class FoxData: + edadMaxima = 150 + madurezSexual = 20 + frecuenciaSexual = 10 + nivelCadenaAlimenticia = 2 + minFrecuenciaAlimentacion = 20 + maxFrecuenciaAlimentacion = 3 + maxNumeroCrias = 3 + +class World: + initialGreen = 10 + initialRabbits = 10 + initialFoxs = 10 + playState = False + state = [] + animals = [] + + rabbit_data = RabbitData() + fox_data = FoxData() + + + def animalsNear(self,x,y): + animalsNear = [] + for n in range(len(self.animals)): + animal = self.animals[n] + if ((abs(animal.posX-x) == 1) and + (abs(animal.posY-y) == 1)): + animalsNear.append(animal) + #print "Encuentra",x,y,animal.posX,animal.posY + return animalsNear + + + diff --git a/activity/activity-ecomundo3.svg b/activity/activity-ecomundo3.svg new file mode 100644 index 0000000..a6bb8d3 --- /dev/null +++ b/activity/activity-ecomundo3.svg @@ -0,0 +1,37 @@ + + +]> + + + + + + + + + + + diff --git a/activity/activity.info b/activity/activity.info new file mode 100644 index 0000000..4ae03a5 --- /dev/null +++ b/activity/activity.info @@ -0,0 +1,9 @@ +[Activity] +name = Ecomundo +service_name = org.laptop.sample.Ecomundo +icon = activity-ecomundo3 +class = ecomundoactivity.EcomundoActivity +activity_version = 2 +host_version = 1 +show_launcher = yes +license = GPLV2+ \ No newline at end of file diff --git a/ecomundoactivity.py b/ecomundoactivity.py new file mode 100644 index 0000000..5d4ef82 --- /dev/null +++ b/ecomundoactivity.py @@ -0,0 +1,250 @@ +#!/usr/bin/env python + +### Simulacion de un ecosistema, en el que existe pasto, conejos y zorros. +### By Gonzalo Odiard, 2006 godiard at gmail.com +### GPL License - http://www.gnu.org/copyleft/gpl.html + +import gobject, gtk , cairo +import math, random +import os +import hippo + +import pango +import logging +from gettext import gettext as _ +import World,Animals,Green +import sugar +from sugar.activity import activity +from sugar.graphics import style +from sugar.graphics.toolbutton import ToolButton + + +world = World.World() + +class Tile: + def __init__ (self,x,y): + self.X = x + self.Y = y + self.STATE = 0; + + +def drawGrid(ctx): + ctx.set_line_width(2) + ctx.set_source_rgb(0,0,0) + for n in range(0,World.CANT_TILES): + ctx.move_to(World.MARGEN,World.MARGEN +(World.SIZE_TILE*n)) + ctx.line_to(World.SIZE_TILE * (World.CANT_TILES-1) + World.MARGEN, + World.MARGEN +(World.SIZE_TILE*n)) + ctx.move_to(World.MARGEN +(World.SIZE_TILE*n),World.MARGEN) + ctx.line_to(World.MARGEN +(World.SIZE_TILE*n), + World.SIZE_TILE * (World.CANT_TILES-1)+ World.MARGEN) + ctx.stroke() + +def initWorld(): + world.state = [] + world.animals = [] + for n in range(0,World.CANT_TILES): + world.state.append([]) + for p in range(0,World.CANT_TILES): + tile = Tile(n,p) + world.state[n].append(tile) + + +def drawStateWorld(ctx): + #print "drawStateWorld" + ctx.move_to(0,0) + ctx.rectangle(0,0,World.SIZE_WORLD+(2*World.MARGEN),World.SIZE_WORLD+(2*World.MARGEN)) + #ctx.set_source_rgb(style.COLOR_PANEL_GREY.get_gdk_color()) + ctx.set_source_rgb(192.0/256.0,192.0/256.0,192.0/256.0) + ctx.fill() + + + for n in range(0,World.CANT_TILES-1): + for p in range(0,World.CANT_TILES-1): + ctx.save() + Green.getImagesGreen(world,ctx,n,p) + #Green.getColorTile(world,ctx,n,p) + ctx.restore() + for n in range(len(world.animals)): + #print "Animal",n + animal = world.animals[n] + ctx.save() + animal.draw(ctx) + ctx.restore() + +def initGreen(): + for n in range(world.initialGreen): + x = int(random.random()*World.CANT_TILES) + y = int(random.random()*World.CANT_TILES) + world.state[x][y].STATE = 2 + +def initAnimals(): + for n in range(world.initialRabbits): + x = int(random.random()*(World.CANT_TILES-1)) + y = int(random.random()*(World.CANT_TILES-1)) + #print "Init Rabbit",x,y + animal = Animals.Rabbit(x,y,world) + world.animals.append(animal) + for n in range(world.initialFoxs): + x = int(random.random()*(World.CANT_TILES-1)) + y = int(random.random()*(World.CANT_TILES-1)) + #print "Init Fox",x,y + animal = Animals.Fox(x,y,world) + world.animals.append(animal) + + +def updateState(drawingarea): + #print "update State" + if (world.playState): + Green.grow(world) + n = 0 + + while (n < len(world.animals)): + animal = world.animals[n] + animal.move(world) + if (not animal.checkLive()): + cantAnimals = len(world.animals) + world.animals[n] = cantAnimals + world.animals.remove(cantAnimals) + else : + #Actualizo donde esta + x1 = World.MARGEN+(World.SIZE_TILE*animal.posX) + y1 = World.MARGEN +(World.SIZE_TILE*animal.posY) + n = n+1 + drawingarea.queue_draw_area(0, 0,World.SIZE_WORLD, World.SIZE_WORLD) + source_id = gobject.timeout_add(1000, updateState,drawingarea) + + +class EcomundoActivity(activity.Activity): + + def __init__(self,handle): + activity.Activity.__init__(self,handle) + + self.set_title("Ecomundo") + print "Init activity Ecomundo" + #print os.path.abspath(__file__) + + toolbox = activity.ActivityToolbox(self) + self.toolbar = gtk.Toolbar() + + toolbox.add_toolbar(_('Ecomundo'), self.toolbar) + self.toolbar.show() + self.set_toolbox(toolbox) + toolbox.show() + + self.btnNew = ToolButton('reload') + self.btnNew.connect('clicked', self.onBtNewClicked) + self.toolbar.insert(self.btnNew, -1) + self.btnNew.show() + + self.btPlay = ToolButton('next') + self.btPlay.connect('clicked', self.onBtPlayClicked) + self.toolbar.insert(self.btPlay, -1) + self.btPlay.show() + + self.btStop = ToolButton('process-stop') + self.btStop.connect('clicked', self.onBtStopClicked) + self.toolbar.insert(self.btStop, -1) + self.btStop.show() + + self.btStop.props.sensitive = False; + self.btPlay.props.sensitive = True; + + toolbox.set_current_toolbar(1) + + hBox = gtk.HBox(False, 0) + self.set_canvas(hBox) + + self.drawingarea1 = gtk.DrawingArea() + self.drawingarea1.set_size_request(World.SIZE_WORLD+(2*World.MARGEN),World.SIZE_WORLD+(2*World.MARGEN)) + self.drawingarea1.show() + + hBox.pack_start(self.drawingarea1, False, True, 5) + + table = gtk.Table(rows=4, columns=2, homogeneous=False) + hBox.pack_start(table, False, False, 5) + + label_attributes = pango.AttrList() + label_attributes.insert(pango.AttrSize(14000, 0, -1)) + label_attributes.insert(pango.AttrForeground(65535, 65535, 65535, 0, -1)) + + lbTitle = gtk.Label() + lbTitle.set_attributes(label_attributes) + lbTitle.set_text(_('Initial Values')) + #table.attach(lbTitle, 0, 1, 0, 1,yoptions=gtk.SHRINK,xpadding=5) + table.attach(lbTitle, 0, 2, 0, 1,yoptions=gtk.SHRINK,xpadding=10) + + lbGreen = gtk.Label() + lbGreen.set_attributes(label_attributes) + lbGreen.set_text(_('Green')) + table.attach(lbGreen, 0, 1, 1, 2,yoptions=gtk.SHRINK,xoptions=gtk.SHRINK,xpadding=10) + + adjGreen = gtk.Adjustment(10, 1, 400, 1, 1, 0) + self.spbGreen = gtk.SpinButton(adjustment=adjGreen, climb_rate=1.0, digits=2) + table.attach(self.spbGreen, 1, 2, 1, 2,yoptions=gtk.SHRINK,xoptions=gtk.SHRINK,ypadding=10) + + lbRabbit = gtk.Label() + lbRabbit.set_attributes(label_attributes) + lbRabbit.set_text(_('Rabbits')) + table.attach(lbRabbit, 0, 1, 2, 3,yoptions=gtk.SHRINK,xoptions=gtk.SHRINK,xpadding=10) + + adjRabbit = gtk.Adjustment(10, 1, 400, 1, 1, 0) + self.spbRabbit = gtk.SpinButton(adjustment=adjRabbit, climb_rate=1.0, digits=2) + table.attach(self.spbRabbit, 1, 2, 2, 3,yoptions=gtk.SHRINK,xoptions=gtk.SHRINK,ypadding=10) + + lbFox = gtk.Label() + lbFox.set_attributes(label_attributes) + lbFox.set_text(_('Foxs')) + table.attach(lbFox, 0, 1, 3, 4,yoptions=gtk.SHRINK,xoptions=gtk.SHRINK,xpadding=10) + + adjFox = gtk.Adjustment(10, 1, 400, 1, 1, 0) + self.spbFox = gtk.SpinButton(adjustment=adjFox, climb_rate=1.0, digits=2) + table.attach(self.spbFox, 1, 2, 3, 4,yoptions=gtk.SHRINK,xoptions=gtk.SHRINK,ypadding=10) + + + print "test resize" + print "antes de initWorld" + initWorld() + print "antes de init Green" + initGreen() + print "antes de init Animals" + initAnimals() + + hBox.resize_children() + hBox.show_all() + + self.drawingarea1.connect('expose-event', self.onDrawingAreaExposed) + + + def onDrawingAreaExposed(self,da, event): + #print "drawingarea exposed" + x, y, width, height = da.allocation + ctx = da.window.cairo_create() + drawStateWorld(ctx) + drawGrid(ctx) + + def onBtPlayClicked(self,widget): + self.btStop.props.sensitive = True; + self.btPlay.props.sensitive = False; + world.playState = True + source_id = gobject.timeout_add(2000, updateState,self.drawingarea1) + # http://www.pygtk.org/pygtk2tutorial-es/ch-TimeoutsIOAndIdleFunctions.html#sec-Timeouts + + def onBtStopClicked(self,widget): + self.btStop.props.sensitive = False; + self.btPlay.props.sensitive = True; + world.playState = False + + def onBtNewClicked(self,widget): + initWorld() + world.initialGreen = self.spbGreen.get_value_as_int() + world.initialRabbits = self.spbRabbit.get_value_as_int() + world.initialFoxs = self.spbFox.get_value_as_int() + initGreen() + initAnimals() + # Despues de esto hay que recargar la pantalla + drawingarea1 = self.drawingarea1 + ctx = drawingarea1.window.cairo_create() + drawStateWorld(ctx) + drawGrid(ctx) + diff --git a/images/fox.png b/images/fox.png new file mode 100644 index 0000000..6bef989 --- /dev/null +++ b/images/fox.png Binary files differ diff --git a/images/fox_f.png b/images/fox_f.png new file mode 100644 index 0000000..6c623a4 --- /dev/null +++ b/images/fox_f.png Binary files differ diff --git a/images/fox_m.png b/images/fox_m.png new file mode 100644 index 0000000..47dd530 --- /dev/null +++ b/images/fox_m.png Binary files differ diff --git a/images/fox_small.png b/images/fox_small.png new file mode 100644 index 0000000..ed10875 --- /dev/null +++ b/images/fox_small.png Binary files differ diff --git a/images/fox_small_f.png b/images/fox_small_f.png new file mode 100644 index 0000000..62f097c --- /dev/null +++ b/images/fox_small_f.png Binary files differ diff --git a/images/fox_small_m.png b/images/fox_small_m.png new file mode 100644 index 0000000..e2d3f2d --- /dev/null +++ b/images/fox_small_m.png Binary files differ diff --git a/images/green1.png b/images/green1.png new file mode 100644 index 0000000..64058f4 --- /dev/null +++ b/images/green1.png Binary files differ diff --git a/images/green1.svg b/images/green1.svg new file mode 100644 index 0000000..3beb113 --- /dev/null +++ b/images/green1.svg @@ -0,0 +1,71 @@ + + + + + + + + + image/svg+xml + + + + + + + + + diff --git a/images/green2.png b/images/green2.png new file mode 100644 index 0000000..6a47dd6 --- /dev/null +++ b/images/green2.png Binary files differ diff --git a/images/green2.svg b/images/green2.svg new file mode 100644 index 0000000..4e6bb6d --- /dev/null +++ b/images/green2.svg @@ -0,0 +1,79 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/images/green3.png b/images/green3.png new file mode 100644 index 0000000..9d69f5a --- /dev/null +++ b/images/green3.png Binary files differ diff --git a/images/green3.svg b/images/green3.svg new file mode 100644 index 0000000..953a0e7 --- /dev/null +++ b/images/green3.svg @@ -0,0 +1,95 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/images/green4.png b/images/green4.png new file mode 100644 index 0000000..9481229 --- /dev/null +++ b/images/green4.png Binary files differ diff --git a/images/green4.svg b/images/green4.svg new file mode 100644 index 0000000..6bfca25 --- /dev/null +++ b/images/green4.svg @@ -0,0 +1,123 @@ + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/images/rabbit.png b/images/rabbit.png new file mode 100644 index 0000000..71252b2 --- /dev/null +++ b/images/rabbit.png Binary files differ diff --git a/images/rabbit_f.png b/images/rabbit_f.png new file mode 100644 index 0000000..655d225 --- /dev/null +++ b/images/rabbit_f.png Binary files differ diff --git a/images/rabbit_m.png b/images/rabbit_m.png new file mode 100644 index 0000000..985b0d2 --- /dev/null +++ b/images/rabbit_m.png Binary files differ diff --git a/images/rabbit_small.png b/images/rabbit_small.png new file mode 100644 index 0000000..5215ec0 --- /dev/null +++ b/images/rabbit_small.png Binary files differ diff --git a/images/rabbit_small_f.png b/images/rabbit_small_f.png new file mode 100644 index 0000000..dd7aa06 --- /dev/null +++ b/images/rabbit_small_f.png Binary files differ diff --git a/images/rabbit_small_m.png b/images/rabbit_small_m.png new file mode 100644 index 0000000..19ec748 --- /dev/null +++ b/images/rabbit_small_m.png Binary files differ diff --git a/locale/es/LC_MESSAGES/org.laptop.sample.Ecomundo.mo b/locale/es/LC_MESSAGES/org.laptop.sample.Ecomundo.mo new file mode 100644 index 0000000..1857442 --- /dev/null +++ b/locale/es/LC_MESSAGES/org.laptop.sample.Ecomundo.mo Binary files differ diff --git a/locale/es/activity.linfo b/locale/es/activity.linfo new file mode 100644 index 0000000..bde805d --- /dev/null +++ b/locale/es/activity.linfo @@ -0,0 +1,2 @@ +[Activity] +name = Ecomundo diff --git a/po/Ecomundo.pot b/po/Ecomundo.pot new file mode 100644 index 0000000..b7edddd --- /dev/null +++ b/po/Ecomundo.pot @@ -0,0 +1,38 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-09-28 20:24-0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: activity/activity.info:2 +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:130 +msgid "Ecomundo" +msgstr "" + +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:173 +msgid "Initial Values" +msgstr "" + +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:178 +msgid "Green" +msgstr "" + +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:187 +msgid "Rabbits" +msgstr "" + +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:196 +msgid "Foxs" +msgstr "" diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 0000000..d8b523f --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,7 @@ +encoding: UTF-8 +Animals.py +ecomundoactivity.py +ecomundo.py +glade_util.py +Green.py +World.py diff --git a/po/es.mo b/po/es.mo new file mode 100644 index 0000000..f74a8ea --- /dev/null +++ b/po/es.mo Binary files differ diff --git a/po/es.po b/po/es.po new file mode 100644 index 0000000..182d530 --- /dev/null +++ b/po/es.po @@ -0,0 +1,38 @@ +# Spanish translations for PACKAGE package. +# Copyright (C) 2009 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# Gonzalo Odiard , 2009. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2009-09-28 20:24-0300\n" +"PO-Revision-Date: 2009-09-28 20:25-0300\n" +"Last-Translator: Gonzalo Odiard \n" +"Language-Team: Spanish\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ASCII\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: activity/activity.info:2 +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:130 +msgid "Ecomundo" +msgstr "Ecomundo" + +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:173 +msgid "Initial Values" +msgstr "Valores Iniciales" + +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:178 +msgid "Green" +msgstr "Pasto" + +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:187 +msgid "Rabbits" +msgstr "Conejos" + +#: /home/gonzalo/Activities/Ecomundo.activity/ecomundoactivity.py:196 +msgid "Foxs" +msgstr "Zorros" diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..bd1e319 --- /dev/null +++ b/setup.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python +from sugar.activity import bundlebuilder +if __name__ == "__main__": + bundlebuilder.start() + -- cgit v0.9.1