#!/usr/bin/env python # -*- coding: utf-8 -*- # Widgets.py por: # Flavio Danesse # CeibalJAM! - Uruguay # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import gtk import gobject import os import Globals as G class Button(gtk.EventBox): __gsignals__ = {"clicked":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))} def __init__(self): gtk.EventBox.__init__(self) self.set_visible_window(True) self.set_border_width(1) # http://developer.gnome.org/pygtk/stable/gdk-constants.html#gdk-event-mask-constants self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.ENTER_NOTIFY_MASK | gtk.gdk.LEAVE_NOTIFY_MASK) self.connect("button_press_event", self.button_press) self.connect("button_release_event", self.button_release) self.connect("enter-notify-event", self.enter_notify_event) self.connect("leave-notify-event", self.leave_notify_event) self.tamanio = (0,0) self.normalcolor = G.AMARILLO self.selectlocor = G.BLANCO self.clickedcolor = G.NARANJA self.modify_bg(gtk.STATE_NORMAL, self.normalcolor) self.show_all() def button_release(self, widget, event): self.modify_bg(gtk.STATE_NORMAL, self.selectlocor) def leave_notify_event(self, widget, event): self.modify_bg(gtk.STATE_NORMAL, self.normalcolor) def enter_notify_event(self, widget, event): self.modify_bg(gtk.STATE_NORMAL, self.selectlocor) def button_press(self, widget, event): if event.button == 1: self.modify_bg(gtk.STATE_NORMAL, self.clickedcolor) self.emit("clicked", event) def set_tooltip(self, texto): tooltips = gtk.Tooltips() tooltips.set_tip(self, texto, tip_private=None) def set_tamanio(self, w, h): if self.tamanio != (w,h): self.tamanio = (w,h) self.set_size_request(w,h) class ButtonElemento(Button): def __init__(self, diccionario): Button.__init__(self) self.elementoquimico = diccionario self.add(gtk.Label(self.elementoquimico["simbolo"])) texto = "" for key in self.elementoquimico.keys(): texto += "%s = %s%s" % (key, self.elementoquimico[key], "\n") self.set_tooltip(texto) self.show_all() ''' class ElementoenJuego(ButtonElemento): def __init__(self, diccionario): ButtonElemento.__init__(self, diccionario) self.pregunta = None self.opciones = [] self.respuesta = None preguntas = G.PREGUNTAS[self.elementoquimico["Z"]] if preguntas: self.pregunta = preguntas["pregunta"] for opcion in preguntas["opciones"]: self.opciones.append( opcion ) self.respuesta = preguntas["opciones"][preguntas["respuesta"]] #if self.pregunta: # print self.pregunta # for opcion in self.opciones: # print opcion # print "Respuesta:", self.respuesta''' class TablaPeriodica(gtk.EventBox): def __init__(self): gtk.EventBox.__init__(self) self.set_visible_window(True) self.modify_bg(gtk.STATE_NORMAL, G.FONDO3) self.tabla = None self.filasdeelementos = None self.set_layout() self.show_all() def set_layout(self): self.tabla = Tabla() # Cabecera for x in range(1,19): button = Button() button.normalcolor = G.BLANCO button.selectlocor = G.BLANCO button.clickedcolor = G.BLANCO button.modify_bg(gtk.STATE_NORMAL, button.normalcolor) button.add(gtk.Label(x)) self.tabla.attach(button, x, x+1, 0, 1, xoptions=gtk.EXPAND|gtk.FILL, yoptions=gtk.EXPAND|gtk.FILL, xpadding=0, ypadding=0) for x in range(1,10): button = Button() button.normalcolor = G.BLANCO button.selectlocor = G.BLANCO button.clickedcolor = G.BLANCO button.modify_bg(gtk.STATE_NORMAL, button.normalcolor) button.add(gtk.Label(x)) self.tabla.attach(button, 0, 1, x, x+1, xoptions=gtk.EXPAND|gtk.FILL, yoptions=gtk.EXPAND|gtk.FILL, xpadding=0, ypadding=0) self.add(self.tabla) estructura = G.INDICEELEMENTOS elementos = G.ELEMENTOS # Elementos self.filasdeelementos = [] for linea in estructura: fila = [] for index in linea: if index: boton = ButtonElemento(elementos[index-1]) self.set_colores(boton) boton.show_all() fila.append(boton) else: fila.append(None) self.filasdeelementos.append(fila) for line in self.filasdeelementos: row = self.filasdeelementos.index(line)+1 for boton in line: col = line.index(boton)+1 if boton != None: self.tabla.attach(boton, col, col+1, row, row+1, xoptions=gtk.EXPAND|gtk.FILL, yoptions=gtk.EXPAND|gtk.FILL, xpadding=0, ypadding=0) def set_colores(self, boton): for elemen in G.COLORS: color, indices = elemen if boton.elementoquimico["Z"] in indices: boton.normalcolor = color boton.modify_bg(gtk.STATE_NORMAL, boton.normalcolor) class Tabla(gtk.Table): def __init__(self): gtk.Table.__init__(self, rows = 10, columns = 19, homogeneous = True) self.set_row_spacing(7, 5) self.show_all() class Toolbar1(gtk.Toolbar): def __init__(self): gtk.Toolbar.__init__(self) self.modify_bg(gtk.STATE_NORMAL, G.NEGRO) ''' separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(5, -1) separator.set_expand(False) self.insert(separator, -1)''' boton = gtk.ToolButton() imagen = gtk.Image() pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(G.ICONOS, "atomo.png"), 32, 32) imagen.set_from_pixbuf(pixbuf) boton.set_icon_widget(imagen) imagen.show() self.insert(boton, -1) boton.show() #tooltips = gtk.Tooltips() #tooltips.set_tip(boton, _("Detener Grabación."), tip_private=None) #boton.connect("clicked", self.ok_callback) ''' separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(5, -1) separator.set_expand(False) self.insert(separator, -1)''' boton = gtk.ToolButton() imagen = gtk.Image() pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(G.ICONOS, "caminoalaplata-ico.png"), 32, 32) imagen.set_from_pixbuf(pixbuf) boton.set_icon_widget(imagen) imagen.show() self.insert(boton, -1) boton.show() #tooltips = gtk.Tooltips() #tooltips.set_tip(boton, _("Detener Grabación."), tip_private=None) #boton.connect("clicked", self.ok_callback) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) self.insert(separator, -1) imagen = gtk.Image() pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(G.ICONOS, 'ceibaljam.png')) imagen.set_from_pixbuf(pixbuf) imagen.show() item = gtk.ToolItem() item.add(imagen) self.insert(item, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(5, -1) separator.set_expand(False) self.insert(separator, -1) imagen = gtk.Image() pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(G.ICONOS, 'uruguay.png')) imagen.set_from_pixbuf(pixbuf) imagen.show() item = gtk.ToolItem() item.add(imagen) self.insert(item, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(5, -1) separator.set_expand(False) self.insert(separator, -1) imagen = gtk.Image() pixbuf = gtk.gdk.pixbuf_new_from_file(os.path.join(G.ICONOS, 'licencia.png')) imagen.set_from_pixbuf(pixbuf) imagen.show() item = gtk.ToolItem() item.add(imagen) self.insert(item, -1) separator = gtk.SeparatorToolItem() separator.props.draw = False separator.set_size_request(0, -1) separator.set_expand(True) self.insert(separator, -1) boton = gtk.ToolButton() imagen = gtk.Image() pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(G.ICONOS, "salir.png"), 32, 32) imagen.set_from_pixbuf(pixbuf) boton.set_icon_widget(imagen) imagen.show() self.insert(boton, -1) boton.show() #tooltips = gtk.Tooltips() #tooltips.set_tip(boton, _("Detener Grabación."), tip_private=None) #boton.connect("clicked", self.ok_callback) self.show_all() class Pregunta(gtk.EventBox): def __init__(self, pregunta): super(Pregunta, self).__init__() self._pregunta = gtk.Label() self._pregunta.set_markup("" + pregunta + "") self.add(self._pregunta) self.show_all()