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

Source Code for Module icaro-bloques.componente_datos

  1  #!/usr/bin/python 
  2  # -*- coding: utf-8 -*- 
  3   
  4  # This program is free software: you can redistribute it and/or modify 
  5  # it under the terms of the GNU General Public License as published by 
  6  # the Free Software Foundation, either version 3 of the License, or 
  7  # (at your option) any later version. 
  8  # 
  9  # This program is distributed in the hope that it will be useful, 
 10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 12  # GNU General Public License for more details. 
 13   
 14  import sys, pygame 
 15  from os import system 
 16   
17 -class comp_dat_arg(pygame.sprite.Sprite):
18 posic_rel_x=0 19 posic_rel_y=0 20 pulsado=0 21 posicion=(0,0) 22 cadena_final="" 23 cadena_intermedia="" 24 #rectangulo que representa toda el area del componente 25 rectan=pygame.Rect(0,0,80,20) 26 ide=0 27 color=(125,100,83) 28 modificable=0 29 valor_cadena_no_mod="0" 30
31 - def __init__( 32 self, 33 x,y, 34 identidad, 35 mod, 36 texto, 37 color, 38 val_no_mod, 39 img, 40 tipo, 41 fondo, 42 ventana, 43 textorender 44 45 ):
46 pygame.sprite.Sprite.__init__(self) 47 self.ide=identidad 48 self.posicion=(x,y) 49 self.texto=texto 50 self.color=color 51 self.fondo=fondo 52 self.ventana=ventana 53 self.textorender=textorender 54 self.color_texto=self.fondo.color_texto 55 self.conector_m=pygame.Rect(0,0,10,20)#conector macho 56 self.conector_h=pygame.Rect(0,0,10,20)#conector hembra 57 self.pegado2=0 58 self.pegado_a2=0 59 self.pegado=0 60 self.pegado_a=0 61 self.pegado_b=0 62 self.conectado=0 63 self.tecla=0 64 self.tecla_presionada=0 65 self.modificable=mod 66 self.valor_cadena_no_mod=val_no_mod 67 self.tipo=tipo 68 if self.tipo==6: 69 self.imagenintermedia=img 70 self.img=sys.path[0] +"/imagenes/componentes/"+ img 71 self.imagen=pygame.image.load(self.img) 72 self.img_rect=self.imagen.get_rect()
73 - def dibujar(self):
74 #tomo el valor del texto para agrandar el tamaño del 75 # cuerpo del componente. 76 # si es una imagen le pongo un valor fijo 77 TamaComp=0 78 if self.tipo==7: 79 TamaComp=len(self.texto) 80 else: 81 TamaComp=3 82 #cubos que representan el conector hembra 83 pygame.draw.rect( 84 self.fondo.screen, 85 self.color, 86 ( 87 self.posicion[0]+30+(7*TamaComp), 88 self.posicion[1]-10, 89 10, 90 10 91 ), 92 0 93 ) 94 pygame.draw.rect( 95 self.fondo.screen, 96 self.color, 97 ( 98 self.posicion[0]+30+(7*TamaComp)+3, 99 self.posicion[1], 100 4, 101 4 102 ), 103 0 104 ) 105 pygame.draw.rect( 106 self.fondo.screen, 107 self.color, 108 ( 109 self.posicion[0]+30+(7*TamaComp), 110 self.posicion[1]+20, 111 10, 112 10 113 ), 114 0 115 ) 116 pygame.draw.rect( 117 self.fondo.screen, 118 self.color, 119 ( 120 self.posicion[0]+30+(7*TamaComp)+3, 121 self.posicion[1]+20-4, 122 4, 123 4 124 ), 125 0 126 ) 127 self.conector_h[0]=self.rectan[0]+30+(7*TamaComp) 128 self.conector_h[1]=self.rectan[1] 129 # conector macho 130 pygame.draw.rect( 131 self.fondo.screen, 132 self.color, 133 ( 134 self.posicion[0], 135 self.posicion[1]+4, 136 10, 137 20-8 138 ), 139 0 140 ) 141 pygame.draw.rect( 142 self.fondo.screen, 143 self.color, 144 ( 145 self.posicion[0], 146 self.posicion[1], 147 3, 148 20 149 ), 150 0 151 ) 152 pygame.draw.rect( 153 self.fondo.screen, 154 self.color, 155 ( 156 self.posicion[0]+7, 157 self.posicion[1], 158 3, 159 20 160 ), 161 0 162 ) 163 # cuerpo del componente 164 pygame.draw.rect( 165 self.fondo.screen, 166 self.color, 167 ( 168 self.posicion[0]+10, 169 self.posicion[1]-10, 170 7*TamaComp+20, 171 40 172 ), 173 0 174 ) 175 if self.tipo==7: 176 self.textorender.render( 177 str(self.texto), 178 self.color_texto, 179 ( 180 (self.posicion[0]+20), 181 (self.posicion[1]+5) 182 ) 183 ) 184 if self.tipo==6: 185 self.modificable=0 186 self.fondo.screen.blit( 187 self.imagen, 188 ( 189 self.posicion[0]+30-( 190 self.img_rect[2]/2 191 ), 192 self.posicion[1]-5 193 ) 194 )
195
196 - def update(self):
197 ban_a=0 198 cadena_auxiliar="" 199 posic_mouse= self.ventana.mousexy 200 botones_mouse = self.ventana.boton_mouse 201 # self.rectan es el rect 202 # que representa la totalidad de la figura 203 self.rectan[0]=self.posicion[0] 204 self.rectan[1]=self.posicion[1] 205 # self.conector_m es la ficha "macho" 206 self.conector_m[0]=self.rectan[0] 207 self.conector_m[1]=self.rectan[1] 208 209 210 if ( 211 botones_mouse[3] and 212 self.rectan.collidepoint(posic_mouse[0],posic_mouse[1]) and 213 self.modificable==1 214 ): 215 self.tecla=1 216 self.texto="" 217 self.ventana.seleccionado_datos_ed=self.ide 218 self.ventana.tecla=0 219 if ( 220 self.tecla==1 and 221 self.ventana.seleccionado_datos_ed==self.ide 222 ): 223 if self.valor_cadena_no_mod=="a": 224 if ( 225 self.tecla_presionada==1 and 226 self.ventana.tecla==1 227 ): 228 cadena_auxiliar= self.ventana.valor_tecla 229 self.tecla_presionada=0 230 if cadena_auxiliar!="": 231 self.texto = self.texto + cadena_auxiliar 232 if self.valor_cadena_no_mod=="0": 233 if ( 234 self.tecla_presionada==1 and 235 self.ventana.tecla==1 and 236 self.ventana.valor_tecla.isdigit() 237 ): 238 cadena_auxiliar= self.ventana.valor_tecla 239 self.tecla_presionada=0 240 if cadena_auxiliar!="": 241 self.texto = self.texto + cadena_auxiliar 242 if self.ventana.tecla==0: 243 244 self.tecla_presionada=1 245 if self.ventana.tecla_enter==1: 246 self.tecla=0 247 self.ventana.seleccionado_datos_ed=0 248 if self.modificable==1: 249 self.cadena_final=self.texto+self.cadena_intermedia 250 else: 251 self.cadena_final= ( 252 self.valor_cadena_no_mod 253 + 254 self.cadena_intermedia 255 ) 256 self.cadena_final=self.cadena_final.replace("\r", '') 257 if self.conectado==0: 258 if self.pegado==0: 259 for a in range(1,len(self.fondo.objetos)): 260 valor1=self.fondo.objetos[a].lista_conector_h_datos 261 for b in range(len(valor1)): 262 valor2=self.fondo.objetos[a] 263 valor3=valor2.lista_conector_h_datos[b] 264 if ( 265 self.conector_m.colliderect(valor3)): 266 self.pegado=1 267 self.conectado=1 268 self.pegado_a=a 269 self.pegado_b=b 270 if self.pegado==1: 271 valor1=self.fondo.objetos[self.pegado_a] 272 valor2=valor1.lista_conector_h_datos[self.pegado_b] 273 x,y,aa,bb=valor2 274 xx=x 275 yy=y 276 self.posicion=(xx,yy) 277 valor1.lista_valores[self.pegado_b]=self.cadena_final 278 if self.conectado==0: 279 if self.pegado2==0: 280 for z in range(1,len(self.fondo.objetos_datos)): 281 val=self.fondo.objetos_datos[z].conector_h 282 if self.conector_m.colliderect(val): 283 self.pegado_a2=z 284 self.pegado2=1 285 self.conectado=1 286 if self.pegado2==1: 287 val1=self.fondo.objetos_datos[self.pegado_a2].conector_h 288 x,y,aa,bb=val1 289 xx=x 290 yy=y 291 self.posicion=(xx,yy) 292 val2=self.fondo.objetos_datos[self.pegado_a2] 293 val2.cadena_intermedia=self.cadena_final 294 else: 295 self.cadena_intermedia="" 296 if ( 297 botones_mouse[1]==1 and 298 self.rectan.collidepoint(self.ventana.mousexy) and 299 self.pulsado==0 and 300 self.ventana.seleccionado_datos==0 301 ): 302 posic_mouse= self.ventana.mousexy 303 self.ventana.seleccionado_datos=self.ide 304 self.posic_rel_x=abs(self.posicion[0]-posic_mouse[0]) 305 self.posic_rel_y=abs(self.posicion[1]-posic_mouse[1]) 306 self.pulsado=1 307 if self.ventana.seleccionado_datos== self.ide: 308 self.posicion=( 309 posic_mouse[0]-self.posic_rel_x, 310 posic_mouse[1]-self.posic_rel_y 311 ) 312 self.conectado=0 313 self.pegado=0 314 self.pegado_a=0 315 self.pegado_b=0 316 self.pegado2=0 317 self.pegado_a2=0 318 if botones_mouse[1]==0: 319 self.pulsado=0 320 self.ventana.seleccionado_datos=0 321 if (botones_mouse[1]==1 322 and self.rectan.collidepoint(self.ventana.mousexy) 323 and self.ventana.seleccion_menu==3): 324 for i in range(1,len(self.fondo.objetos_datos)): 325 self.fondo.objetos_datos[i].conectado=0 326 self.fondo.objetos_datos[i].pegado=0 327 self.fondo.objetos_datos[i].pegado_a=0 328 self.fondo.objetos_datos[i].pegado_b=0 329 self.fondo.objetos_datos[i].pegado2=0 330 self.fondo.objetos_datos[i].pegado_a2=0 331 a=self.fondo.objetos_datos.index(self) 332 ident=self.fondo.objetos_datos[a].ide 333 334 del self.fondo.tipo_obj_datos[a] 335 self.kill() 336 self.fondo.objetos_datos.remove(self) 337 self.dibujar() 338 self.cadena_intermedia=""
339