Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'Widgets.py')
-rw-r--r--Widgets.py167
1 files changed, 167 insertions, 0 deletions
diff --git a/Widgets.py b/Widgets.py
new file mode 100644
index 0000000..2eca4b0
--- /dev/null
+++ b/Widgets.py
@@ -0,0 +1,167 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Widgets.py por:
+# Flavio Danesse <fdanesse@gmail.com>
+# 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 time
+import sys
+import gobject
+import os
+import Globals as G
+
+class ButtonElemento(gtk.EventBox):
+ __gsignals__ = {"clicked":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))}
+ def __init__(self, diccionario):
+ gtk.EventBox.__init__(self)
+ self.set_visible_window(True)
+ #self.modify_bg(gtk.STATE_NORMAL, G.BLANCO)
+ 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.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()
+
+ # --------------------------- EVENTOS --------------------------
+ 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)
+ # --------------------------- EVENTOS --------------------------
+
+ # --------------------------- SETEOS ---------------------------
+ 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)
+ # --------------------------- SETEOS ---------------------------
+
+'''
+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.FONDO)
+
+ self.fixed = None
+ self.filasdeelementos = None
+ self.tamanios = (0,0)
+
+ self.set_layout()
+ self.show_all()
+
+ self.connect("expose_event", self.repaint)
+
+ def set_layout(self):
+ self.fixed = gtk.Fixed()
+ estructura = G.INDICEELEMENTOS
+ elementos = G.ELEMENTOS
+ self.filasdeelementos = []
+ for linea in estructura:
+ fila = []
+ for index in linea:
+ if index:
+ boton = ButtonElemento(elementos[index-1])#ElementoenJuego(elementos[index-1])
+ self.set_colores(boton)
+ self.fixed.put(boton,0,0)
+ boton.show_all()
+ fila.append(boton)
+ else:
+ fila.append(None)
+ self.filasdeelementos.append(fila)
+ self.add(self.fixed)
+
+ 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)
+ '''
+ def get_elementos(self):
+ elementos = []
+ for fila in self.filasdeelementos:
+ for elemento in fila:
+ elementos.append(elemento)
+ return elementos'''
+
+ def repaint(self, widget= None, event= None):
+ x,y,w,h= self.get_allocation()
+ if self.tamanios == (w/18,h/10): return True
+ self.tamanios = (w/18,h/10)
+ x, y = (0,0)
+ for line in self.filasdeelementos:
+ for boton in line:
+ if boton != None:
+ boton.set_tamanio(self.tamanios[0], self.tamanios[1])
+ self.fixed.move(boton,x,y)
+ x += self.tamanios[0]
+ x = 0
+ y += self.tamanios[1]
+ return True