Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Mapa.py
blob: 12c7efe88c3e3719674829a8ceccac109e3735e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gtk, pygtk, os, gobject
from Conjunto import Conjunto
import Globals as G

class Mapa(gtk.Fixed):
	__gsignals__ = {"RESET":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))}
	def __init__(self):
		gtk.Fixed.__init__(self)
		self.conjunto1= None
		self.conjunto2= None

		self.show_all()

	def set_up(self):
		''' Estado inicial de la aplicacion.'''
		''' Se crean los 2 conjuntos en el mapa.'''
		x,y,w,h= self.get_allocation()
		diametro= h/4*3-10
		self.conjunto1= Conjunto(1, diametro)
		self.conjunto2= Conjunto(2, diametro)

		self.put(self.conjunto1, 0, 0)
		self.put(self.conjunto2, diametro/2, 0)

		self.conjunto1.connect("CHANGE_CONJUNTO", self.change_conjunto)
		self.conjunto2.connect("CHANGE_CONJUNTO", self.change_conjunto)

		self.show_all()

	def change_conjunto(self, conjunto, itemselect):
		''' Cuando se selecciona una categoría en un conjunto, se verifica que el otro no
		quede con la misma categoría y devuelven todos los objetos a la barra lateral. '''
		if self.conjunto1.opciones.get_active_text() == self.conjunto2.opciones.get_active_text():
			if conjunto == self.conjunto1:
				i = 0
				self.conjunto2.opciones.set_active(i)
				valor= self.conjunto2.opciones.get_active_text()
				while valor == itemselect:
					i+= 1
					self.conjunto2.opciones.set_active(i)
					valor= self.conjunto2.opciones.get_active_text()
			elif conjunto == self.conjunto2:
				i = 0
				self.conjunto1.opciones.set_active(i)
				valor= self.conjunto1.opciones.get_active_text()
				while valor == itemselect:
					i+= 1
					self.conjunto1.opciones.set_active(i)
					valor= self.conjunto1.opciones.get_active_text()
		self.conjunto1.realinear_combo()
		self.conjunto2.realinear_combo()
		self.vaciar()

	def set_opciones_conjuntos(self, tipo):
		''' Setea las opciones del combo de cada conjunto en el mapa.'''
		self.conjunto1.set_tipo(tipo)
		self.conjunto2.set_tipo(tipo)
		self.conjunto1.opciones.set_active(0)
		self.conjunto2.opciones.set_active(1)

	def vaciar(self):
		'''Elimina los objetos en el mapa y en los conjuntos del mapa.'''
		objetos= []
		for objeto in self.conjunto1.vaciar():
			objetos.append(objeto)
		for objeto in self.conjunto2.vaciar():
			objetos.append(objeto)
		for objeto in self.get_children():
			if objeto != self.conjunto1 and objeto != self.conjunto2:
				objetos.append(objeto)
		if objetos: self.emit("RESET", objetos)