Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmpc <jumapico@gmail.com>2009-10-16 05:47:36 (GMT)
committer jmpc <jumapico@gmail.com>2009-10-16 05:47:36 (GMT)
commitd40e3889b3b4a4f97a3d688696da35d136a706b9 (patch)
tree55969d9d70291b907c0f2cf169948e17b3525894
parentd216d21aa594a3088df5ad0729a2bdb469b79674 (diff)
Agregamos el evento click al boton "Jugar" del estado inicio.
Agregamos los estados start y win para probar la transicion de estados; tambien agregamos los archivos .glade y los .png. Falta escalar las imagenes. Juntamos todos los estados en un archivo para evitar referencias circulares en los import.
-rw-r--r--application.py8
-rw-r--r--data/start.pngbin0 -> 16189 bytes
-rw-r--r--data/win.pngbin0 -> 45490 bytes
-rw-r--r--estados.py72
-rw-r--r--estados/__init__.py0
-rw-r--r--estados/inicio.py3
-rwxr-xr-xmain.py5
-rw-r--r--templates/inicio.glade3
-rw-r--r--templates/start.glade23
-rw-r--r--templates/win.glade23
-rw-r--r--util.py6
11 files changed, 136 insertions, 7 deletions
diff --git a/application.py b/application.py
index dfea187..4258c6e 100644
--- a/application.py
+++ b/application.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import gtk, pygtk
from util import reparent
-from estados.inicio import Inicio
+from estados import Inicio
pygtk.require("2.0")
@@ -23,12 +23,14 @@ class ApplicationManager(object):
window.set_title("Fracciones")
self.state_info = dict()
- self.change_state(Inicio)
+ self.change_state(Inicio(self))
window.show()
+
def change_state(self, state_class):
- reparent(state_class(), state_class.template, self.inner_container)
+ reparent(state_class, state_class.template, self.inner_container)
+
def gtk_main_quit(self, userdata=None):
gtk.main_quit()
diff --git a/data/start.png b/data/start.png
new file mode 100644
index 0000000..cc9d314
--- /dev/null
+++ b/data/start.png
Binary files differ
diff --git a/data/win.png b/data/win.png
new file mode 100644
index 0000000..18f6b8c
--- /dev/null
+++ b/data/win.png
Binary files differ
diff --git a/estados.py b/estados.py
new file mode 100644
index 0000000..dd4ad79
--- /dev/null
+++ b/estados.py
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+import logging
+import gtk
+import cairo
+
+
+log = logging.getLogger(__name__)
+
+
+class Inicio(object):
+ """
+ Clase de inicio.
+
+ """
+ template = "inicio.glade"
+
+
+ def __init__(self, state):
+ self._state = state
+
+
+ def on_buttonjugar_clicked(self, widget): #, event):
+ log.debug("-> cambiar estado a Start")
+ self._state.change_state(Start(self._state))
+
+
+class Start(object):
+ """
+ Clase para probar las transiciones.
+
+ """
+ template = "win.glade"
+
+
+ def __init__(self, state):
+ self._state = state
+ self.image = cairo.ImageSurface.create_from_png("data/start.png")
+
+
+ def on_drawingarea_button_press_event(self, widget, event):
+ log.debug("-> cambiar estado a Fin")
+ self._state.change_state(Fin(self._state))
+
+
+ def on_drawingarea_expose_event(self, widget, event):
+ cr = widget.window.cairo_create()
+ cr.set_source_surface(self.image, 0, 0)
+ cr.paint()
+
+
+class Fin(object):
+ """
+ Clase para probar las transiciones.
+
+ """
+ template = "win.glade"
+
+
+ def __init__(self, state):
+ self._state = state
+ self.image = cairo.ImageSurface.create_from_png("data/win.png")
+
+
+ def on_drawingarea_button_press_event(self, widget, event):
+ log.debug("-> cambiar estado a Start")
+ self._state.change_state(Start(self._state))
+
+
+ def on_drawingarea_expose_event(self, widget, event):
+ cr = widget.window.cairo_create()
+ cr.set_source_surface(self.image, 0, 0)
+ cr.paint()
diff --git a/estados/__init__.py b/estados/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/estados/__init__.py
+++ /dev/null
diff --git a/estados/inicio.py b/estados/inicio.py
deleted file mode 100644
index b802181..0000000
--- a/estados/inicio.py
+++ /dev/null
@@ -1,3 +0,0 @@
-# -*- coding: utf-8 -*-
-class Inicio(object):
- template = "inicio.glade"
diff --git a/main.py b/main.py
index 2c9d9d2..82f9767 100755
--- a/main.py
+++ b/main.py
@@ -1,8 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+import logging
import gtk
from fracciones_standalone import FraccionesStandalone
+
+logging.basicConfig(level=logging.DEBUG)
+
+
if __name__ == "__main__":
# crea ventana standalone
standalone = FraccionesStandalone()
diff --git a/templates/inicio.glade b/templates/inicio.glade
index 987bbc6..d20977a 100644
--- a/templates/inicio.glade
+++ b/templates/inicio.glade
@@ -31,11 +31,12 @@
<property name="xscale">0</property>
<property name="yscale">0</property>
<child>
- <object class="GtkButton" id="button1">
+ <object class="GtkButton" id="buttonjugar">
<property name="label" translatable="yes">jugar</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
+ <signal name="clicked" handler="on_buttonjugar_clicked"/>
</object>
</child>
</object>
diff --git a/templates/start.glade b/templates/start.glade
new file mode 100644
index 0000000..0fffd9a
--- /dev/null
+++ b/templates/start.glade
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkWindow" id="window">
+ <child>
+ <object class="GtkViewport" id="viewport">
+ <property name="visible">True</property>
+ <property name="resize_mode">queue</property>
+ <child>
+ <object class="GtkDrawingArea" id="drawingarea">
+ <property name="width_request">320</property>
+ <property name="height_request">240</property>
+ <property name="visible">True</property>
+ <property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property>
+ <signal name="button_press_event" handler="on_drawingarea_button_press_event"/>
+ <signal name="expose_event" handler="on_drawingarea_expose_event"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/templates/win.glade b/templates/win.glade
new file mode 100644
index 0000000..53fdc9d
--- /dev/null
+++ b/templates/win.glade
@@ -0,0 +1,23 @@
+<?xml version="1.0"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkWindow" id="window">
+ <child>
+ <object class="GtkViewport" id="viewport1">
+ <property name="visible">True</property>
+ <property name="resize_mode">queue</property>
+ <child>
+ <object class="GtkDrawingArea" id="drawingarea">
+ <property name="width_request">320</property>
+ <property name="height_request">240</property>
+ <property name="visible">True</property>
+ <property name="events">GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK</property>
+ <signal name="button_press_event" handler="on_drawingarea_button_press_event"/>
+ <signal name="expose_event" handler="on_drawingarea_expose_event"/>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/util.py b/util.py
index ce25feb..1c0bce9 100644
--- a/util.py
+++ b/util.py
@@ -1,8 +1,14 @@
# -*- coding: utf-8 -*-
+import logging
import gtk
from os import path
+
+log = logging.getLogger(__name__)
+
+
def reparent(manager, template, container):
+ log.info("load %s", template)
# construye en nuevo contenido a partir del template de Glade
builder = gtk.Builder()
builder.add_from_file(path.join("templates", template))