#!/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()