Module menu
[hide private]
[frames] | no frames]

Source Code for Module menu

  1  #!/usr/bin/env python 
  2  #-*- coding: iso-8859-15 -*- 
  3   
  4  """ 
  5  [menu.py] 
  6  Clase principal que ejecuta el programa en entorno gráfico. 
  7  """ 
  8   
  9  __author__ = "Victor Ramirez de la Corte" 
 10  __date__ = "23/04/2009" 
 11  __version__ = "PyRubik v0.6.5" 
 12   
 13   
 14  import pygame, sys, os 
 15  from language import * 
 16  from pygame.locals import * 
 17  from scramble import * 
 18  from timer import * 
 19  import capturar 
 20  import timer 
 21  import cam 
 22  import bd 
 23  #import cube3D 
 24   
 25   
26 -def load_image(folder, name):
27 fullname = os.path.join(folder, name) 28 image = pygame.image.load(fullname) 29 image = image.convert_alpha() 30 return image
31 32
33 -def insertStringInBackground(cadena, font, color, background, window, pos = (0,0), update = None):
34 """ 35 Insertar una cadena en pygame. 36 cadena: string que quieres insertar 37 font: font de pygame 38 color: rgb(r,g,b) 39 backgroung: imagen de fondo 40 window = ventana en la que quieres escribir 41 pos: posicion en la que quieres colocar el texto 42 update: tipo rect el cual es el que se actualiza 43 """ 44 fuente = font.render(cadena, True, color) 45 window.blit(background, (0,0)) 46 window.blit(fuente, pos) 47 pygame.display.update(update) 48 49
50 -def captureKeys(cadena, font, color, background, window, pos = (0,0),update = None):
51 """ 52 Capturamos keys desde pygame e insertamos la captura en pygame. 53 cadena: string que quieres insertar 54 font: font de pygame 55 color: rgb(r,g,b) 56 backgroung: imagen de fondo 57 window = ventana en la que quieres escribir 58 pos: posicion en la que quieres colocar el texto 59 update: tipo rect el cual es el que se actualiza 60 """ 61 pygame.event.clear() 62 string = "" 63 while 1: 64 insertStringInBackground(cadena + string, font, color, background, window, pos, update) 65 keys = pygame.event.wait() 66 if keys.type == KEYDOWN and keys.key == K_BACKSPACE: 67 string = string[:len(string)-1] 68 elif keys.type == KEYDOWN and keys.key == K_RETURN: 69 break 70 elif keys.type == KEYDOWN and keys.key == K_ESCAPE: 71 string = "" 72 break 73 elif keys.type == KEYDOWN and keys.key == K_SPACE: 74 string += " " 75 elif keys.type == KEYDOWN: 76 key = keys.key 77 string += pygame.key.name(key) 78 pygame.event.clear() 79 return string
80 81
82 -def pintarCubo(window, capas, numberOrColor = 1, colores = None):#TODO fallo de segmentacion
83 """pinta las capas de self.capas con pygame""" 84 #variables 85 m = (95, 95, 95, 190, 285, 0) 86 n = (0, 95, 190, 95, 95, 95) 87 a = (0, 30, 60) 88 89 #recorremos todos los colores captados para pintarlo en pantalla 90 for x in range(len(capas)): 91 for w in range(len(capas[x])): #TODO 92 if numberOrColor == 0: #pinta por num 93 pygame.draw.rect(window, colores[int(capas[x][w])][2],\ 94 (a[w%3]+m[x], a[w//3]+n[x], 30, 30)) 95 else: #pinta por colores 96 pygame.draw.rect(window, capas[x][w], (a[w%3]+m[x], a[w//3]+n[x], 30, 30)) 97 98 """ 99 def opcionesThemes(themes): 100 archivo = open("theme/%s/opt.txt" % themes, "r") 101 opc = archivo.readlines() 102 103 color = opc[0][opc[0].index("=")+1:opc[0].index("\n")] 104 colorSel = opc[1][opc[1].index("=")+1:opc[1].index("\n")] 105 sizeFont = opc[2][opc[2].index("=")+1:opc[2].index("\n")] 106 sizeFontScr = opc[3][opc[3].index("=")+1:opc[3].index("\n")] 107 sizeFontClock = opc[4][opc[4].index("=")+1:opc[4].index("\n")] 108 center = opc[5][opc[5].index("=")+1:opc[5].index("\n")] 109 pos = opc[5][opc[5].index("=")+1:opc[5].index("\n")] 110 return color, colorSel, sizeFont, sizeFontClock, center, pos 111 """ 112 568 569 #mmm = Menu() 570