From c6bbce99a0394414c8c0c41b00e67e18d4c8d331 Mon Sep 17 00:00:00 2001 From: jmpc Date: Sun, 11 Oct 2009 05:45:06 +0000 Subject: * Movemos las imagenes y los archivos de glade al directorio data. * Comenzamos a refactorizar el código de la aplicacion segun el nuevo diseño. --- diff --git a/application.py b/application.py new file mode 100644 index 0000000..f023929 --- /dev/null +++ b/application.py @@ -0,0 +1,61 @@ +# -*- encoding: utf-8 +""" +Modulo que define la aplicación principal que carga el Frame de la ventana, +inicializa la informacion de la aplicación y permite cambiar entre los +estados que manejan el Content. + +""" +import logging +import gtk +from estados import Inicio + + +log = logging.getLogger(__name__) + + +class Application: + """ + Singleton correspondiente a la aplicación principal. + Contiene un diccionario que mantiene la información que sera utilizada por + los distintos estados del juego. + + """ + def __init__(self): + """ + Cargamos el xml que define la interfaz (el marco), asignamos los + eventos, creamos y asignamos el primer estado del juego. + + """ + builder = gtk.Builder() + builder.add_from_file("data/frame.glade") + window = builder.get_object("window") + self.content = builder.get_object("dummycontent") + builder.connect_signals(self) + + self.info = dict() + self.change_state(Inicio) + window.show() + + + def change_state(self, state_class): + """ + Cambiamos el estado de la aplicación, modificamos Content. + + """ + parent = self.content.parent + parent.remove(self.content) + new_state = state_class(self) + # del self.content + self.content = new_state + self.content.get_content().reparent(parent) + + + def on_FRAME_destroy(self, userdata): + gtk.main_quit() + + + def run(self): + gtk.main() + + +app = Application() diff --git a/background.png b/data/background.png index e4a8351..e4a8351 100644 --- a/background.png +++ b/data/background.png Binary files differ diff --git a/completed.png b/data/completed.png index c6d04c3..c6d04c3 100644 --- a/completed.png +++ b/data/completed.png Binary files differ diff --git a/failed.png b/data/failed.png index b5c1896..b5c1896 100644 --- a/failed.png +++ b/data/failed.png Binary files differ diff --git a/data/frame.glade b/data/frame.glade new file mode 100644 index 0000000..03fc067 --- /dev/null +++ b/data/frame.glade @@ -0,0 +1,180 @@ + + + + + + + + True + vertical + + + True + + + True + _File + True + + + True + + + gtk-new + True + True + True + + + + + gtk-open + True + True + True + + + + + gtk-save + True + True + True + + + + + gtk-save-as + True + True + True + + + + + True + + + + + gtk-quit + True + True + True + + + + + + + + + True + _Edit + True + + + True + + + gtk-cut + True + True + True + + + + + gtk-copy + True + True + True + + + + + gtk-paste + True + True + True + + + + + gtk-delete + True + True + True + + + + + + + + + True + _View + True + + + + + True + _Help + True + + + True + + + gtk-about + True + True + True + + + + + + + + + False + 0 + + + + + True + True + automatic + automatic + + + True + queue + + + + + + + + 1 + + + + + True + 2 + + + False + 2 + + + + + + diff --git a/gameover.png b/data/gameover.png index 085c038..085c038 100644 --- a/gameover.png +++ b/data/gameover.png Binary files differ diff --git a/start.png b/data/start.png index cc9d314..cc9d314 100644 --- a/start.png +++ b/data/start.png Binary files differ diff --git a/data/state_inicio.glade b/data/state_inicio.glade new file mode 100644 index 0000000..59aee52 --- /dev/null +++ b/data/state_inicio.glade @@ -0,0 +1,14 @@ + + + + + + + + True + + + + + + diff --git a/win.png b/data/win.png index 18f6b8c..18f6b8c 100644 --- a/win.png +++ b/data/win.png Binary files differ diff --git a/estados.py b/estados.py new file mode 100644 index 0000000..516e40c --- /dev/null +++ b/estados.py @@ -0,0 +1,87 @@ +# -*- encoding: utf-8 +""" +Mantenemos los distintos estados de la aplicación. + +class State: + def __init__(self): + debe retornar el contenido que se pondra en CONTENT. + +""" +import logging +import gtk +import cairo + + +log = logging.getLogger(__name__) +IMAGE = { + "start": cairo.ImageSurface.create_from_png("data/start.png"), + "background": cairo.ImageSurface.create_from_png("data/background.png"), + "completed": cairo.ImageSurface.create_from_png("data/completed.png"), + "failed": cairo.ImageSurface.create_from_png("data/failed.png"), + "win": cairo.ImageSurface.create_from_png("data/win.png"), + "gameover": cairo.ImageSurface.create_from_png("data/gameover.png"), +} + + +class Inicio: + def __init__(self, state): + builder = gtk.Builder() + builder.add_from_file("data/state_inicio.glade") + builder.connect_signals(self) + self.content = builder.get_object("window").child + self.state = state + + + def get_content(self): + """ + Devuelve el widget que colocaremos en content_container. + + """ + log.debug("gtk: %s", self.content) + return self.content + + + def dibujar(self): + cr = self.content.window.cairo_create() + cr.set_source_surface(IMAGE["start"], 0, 0) + cr.paint() + + + def on_drawingarea_button_press_event(self, widget, event): + #log.debug("-> cambiar estado a Jugar") + self.state.change_state(Fin) + + + def on_drawingarea_expose_event(self, widget, event): + self.dibujar() + + +class Fin: + def __init__(self, state): + builder = gtk.Builder() + builder.add_from_file("data/state_inicio.glade") + builder.connect_signals(self) + self.content = builder.get_object("window").child + + + def get_content(self): + """ + Devuelve el widget que colocaremos en content_container. + + """ + log.debug("gtk: %s", self.content) + return self.content + + + def dibujar(self): + cr = self.content.window.cairo_create() + cr.set_source_surface(IMAGE["win"], 0, 0) + cr.paint() + + + def on_drawingarea_button_press_event(self, widget, event): + log.debug("-> cambiar estado a Jugar") + + + def on_drawingarea_expose_event(self, widget, event): + self.dibujar() diff --git a/fracciones.xml b/fracciones.xml deleted file mode 100644 index 3109f42..0000000 --- a/fracciones.xml +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - GDK_POINTER_MOTION_MASK | GDK_STRUCTURE_MASK - all - False - center - - - - True - vertical - - - 320 - 240 - True - True - GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_STRUCTURE_MASK - all - - - - - False - False - 0 - - - - - True - - - True - 2 - - - 0 - - - - - True - 1 - 1 - 0 - 0 - - - CHECK! - True - True - True - - - - - - False - False - 1 - - - - - 1 - - - - - - -- cgit v0.9.1