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
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gtk, pygtk, os, math, gobject
import Globals as G
class Conjunto(gtk.Fixed):
__gsignals__ = {"CHANGE_CONJUNTO":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT,))}
def __init__(self, tipo, diametro):
gtk.Fixed.__init__(self)
self.imagen= Imagen(tipo, diametro)
self.opciones= gtk.ComboBox()
liststore = gtk.ListStore(gobject.TYPE_STRING)
self.opciones.set_model(liststore)
text= gtk.CellRendererText()
self.opciones.pack_start(text, True)
self.opciones.add_attribute(text, 'text', 0)
self.put(self.imagen, 0, 0)
self.put(self.opciones, diametro/2, 0)
self.show_all()
self.opciones.connect("changed", self.change)
def change(self, combo):
''' Cuando se selecciono un conjunto en el combo.'''
self.emit("CHANGE_CONJUNTO", combo.get_active_text())
def set_tipo(self, conjuntos):
''' Pone en el combo todos los conjuntos disponibles segĂșn el tipo
seleccionado en la barra lateral.'''
self.opciones.get_model().clear()
for i in conjuntos:
self.opciones.append_text(i)
self.opciones.set_active(0)
def realinear_combo(self):
''' un simple detalle estético.'''
x, y, w, h= self.get_allocation()
xx, yy, ww, hh= self.opciones.get_allocation()
if x > -1:
xx= w/2 - ww/2
self.move(self.opciones, xx, yy)
def vaciar(self):
'''Elimina todos los objetos dentro del conjunto.'''
objetos= []
for child in self.get_children():
if child != self.imagen and child != self.opciones:
objetos.append(child)
return objetos
class Imagen(gtk.Image):
def __init__(self, n, diametro):
gtk.Image.__init__(self)
archivo= "Conjunto%s.png" % (n)
self.pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(G.Imagenes, archivo), diametro, diametro)
self.set_from_pixbuf(self.pixbuf)
self.show()
|