Package icaro-bloques :: Module main
[hide private]
[frames] | no frames]

Source Code for Module icaro-bloques.main

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  #  mainn.py 
  5  #   
  6  #  Copyright 2012 Valentin Basel <valentinbasel@gmail.com> 
  7  #   
  8  #  This program is free software; you can redistribute it and/or modify 
  9  #  it under the terms of the GNU General Public License as published by 
 10  #  the Free Software Foundation; either version 2 of the License, or 
 11  #  (at your option) any later version. 
 12  #   
 13  #  This program is distributed in the hope that it will be useful, 
 14  #  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  #  GNU General Public License for more details. 
 17  #   
 18  #  You should have received a copy of the GNU General Public License 
 19  #  along with this program; if not, write to the Free Software 
 20  #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 21  #  MA 02110-1301, USA. 
 22  #   
 23  #   
 24  import pygame 
 25  import os, sys 
 26  pygame.init() 
27 -class Text:
28 - def __init__(self, fondo,FontName = None, FontSize = 40):
29 pygame.font.init() 30 self.font = pygame.font.Font(FontName, FontSize) 31 self.size = FontSize 32 self.fondo=fondo
33 - def render(self, text, color, pos):
34 #text = unicode(text, "UTF-8") 35 x, y = pos 36 for i in text.split("\r"): 37 self.fondo.pantalla.blit(self.font.render(i, 1, color), (x, y)) 38 39 y += self.size
40 -class VENTANA(pygame.sprite.Sprite):
41 """ Class doc """ 42
43 - def __init__ (self):
44 """ Class initialiser """ 45 pygame.sprite.Sprite.__init__(self) 46 self.pantalla=pygame.display.set_mode((800,600)) 47 pygame.display.set_caption("proyecto icaro") 48 icono=pygame.image.load(sys.path[0] +"/imagenes/icaro.png") 49 pygame.display.set_icon(icono) 50 self.cadena=""
51 - def update(self):
52 pygame.display.update() 53 pygame.event.get() 54 self.pantalla.fill((123,180,255)) 55 self.mouse_x, self.mouse_y = pygame.mouse.get_pos() 56 self.mouse_buton=pygame.mouse.get_pressed()
57 58 59
60 -class BOTON(pygame.sprite.Sprite):
61 """ Class doc """ 62 redct=0
63 - def __init__ (self,pantalla,x,y,img,ej,texto):
64 """ Class initialiser """ 65 pygame.sprite.Sprite.__init__(self) 66 self.imagen=pygame.image.load(img) 67 self.pantalla=pantalla 68 self.posicion=x,y 69 self.ejecuta=ej 70 self.rect = self.imagen.get_rect() 71 self.rect[0]=x 72 self.rect[1]=y 73 self.texto=texto
74 - def update(self):
75 y=100 76 self.pantalla.blit(self.imagen,self.posicion) 77 if self.rect.collidepoint ( 78 ventana.mouse_x, 79 ventana.mouse_y 80 ): 81 for txt in self.texto: 82 texto.render(txt,(255,255,255),(350,y)) 83 y+=40 84 if ( 85 self.rect.collidepoint ( 86 ventana.mouse_x, 87 ventana.mouse_y 88 ) and 89 ventana.mouse_buton[0]): 90 os.system(self.ejecuta)
91 92
93 -class SALIR(pygame.sprite.Sprite):
94 """ Class doc """ 95
96 - def __init__ (self,pantalla,x,y,img,texto):
97 """ Class initialiser """ 98 pygame.sprite.Sprite.__init__(self) 99 self.imagen=pygame.image.load(img) 100 self.pantalla=pantalla 101 self.posicion=x,y 102 self.rect = self.imagen.get_rect() 103 self.rect[0]=x 104 self.rect[1]=y 105 self.texto=texto
106 - def update(self):
107 y=100 108 self.pantalla.blit(self.imagen,self.posicion) 109 if self.rect.collidepoint ( 110 ventana.mouse_x, 111 ventana.mouse_y 112 ): 113 for txt in self.texto: 114 texto.render(txt,(255,255,255),(350,y)) 115 y+=40 116 if ( 117 self.rect.collidepoint ( 118 ventana.mouse_x, 119 ventana.mouse_y 120 ) and 121 ventana.mouse_buton[0]): 122 exit() 123 pass
124 config=[] 125 pyt= ["Lanza la teminal interactiva ","con el modulo apicaro. Necesita ","tener IDLE instalado"] 126 tur= ["Lanza TurtleArt con el modulo ","Tortucaro. ","para manejo conectado ","a la netbook"] 127 icr= ["Lanza Icaro-bloques para ","manejo de robots autonomos"] 128 sal=["Sale del sistema"] 129 conf=open(sys.path[0] +"/config.dat","r") 130 dat=conf.readlines() 131 for txt in dat: 132 config.append(txt) 133 conf.close() 134 ventana=VENTANA() 135 BotonPython=BOTON(ventana.pantalla,100,10,sys.path[0] +"/imagenes/main/python.png","idle -c 'import apicaro; icaro=apicaro.puerto(); icaro.iniciar()'",pyt) 136 BotonIcaro=BOTON(ventana.pantalla,100,150,sys.path[0] +"/imagenes/main/icaro.png","python "+sys.path[0] +"/icaro.py",icr) 137 BotonTurtle=BOTON(ventana.pantalla,100,290,sys.path[0] +"/imagenes/main/tortucaro.png",config[1],tur) 138 texto=Text(ventana) 139 salir=SALIR(ventana.pantalla,100,430,sys.path[0] +"/imagenes/main/salir.png",sal)
140 -def main():
141 142 while True: 143 for evento in pygame.event.get(): 144 if evento.type==pygame.QUIT: 145 pygame.quit() 146 ventana.update() 147 BotonIcaro.update() 148 BotonTurtle.update() 149 BotonPython.update() 150 salir.update() 151 152 return 0
153 154 if __name__ == '__main__': 155 main() 156