From b7977543dd108375cd589fafad4766e0d17ce3d5 Mon Sep 17 00:00:00 2001 From: tonadev Date: Tue, 30 Oct 2018 21:50:36 -0600 Subject: [PATCH 1/3] Port to Gtk3 --- CantaBichos/CantaBichos.py | 68 ++++---- CantaBichos/player.py | 37 +++-- CucaraSims/CucaraSims.py | 79 ++++----- CucaraSims/Cucaracha.py | 24 +-- CucaraSims/Huevos.py | 12 +- CucaraSims/JAMediaImagenes/ImagePlayer.py | 50 +++--- CucaraSims/JAMediaReproductor/JAMediaBins.py | 34 ++-- .../JAMediaReproductor/JAMediaReproductor.py | 90 +++++------ CucaraSims/Juego.py | 34 ++-- CucaraSims/Timer.py | 14 +- CucaraSims/Widgets.py | 152 +++++++++--------- EventTraductor/EventTraductor.py | 15 +- Intro/Intro.py | 24 +-- Main.py | 52 +++--- OjosCompuestos/JAMediaImagenes/ImagePlayer.py | 50 +++--- OjosCompuestos/OjosCompuestos.py | 27 ++-- OjosCompuestos/PlayerList.py | 72 +++++---- SugarBichos.py | 54 ++++--- Widgets.py | 39 +++-- setup.py | 2 +- 20 files changed, 484 insertions(+), 445 deletions(-) diff --git a/CantaBichos/CantaBichos.py b/CantaBichos/CantaBichos.py index e129f44..32c02ee 100644 --- a/CantaBichos/CantaBichos.py +++ b/CantaBichos/CantaBichos.py @@ -2,23 +2,29 @@ # -*- coding: utf-8 -*- import os -import gtk -import gobject +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf +from gi.repository import GObject from player import Player BASE_PATH = os.path.dirname(__file__) +def color_parser(color): + rgba = Gdk.RGBA() + rgba.parse(color) + return rgba -class CantaBichos(gtk.Table): +class CantaBichos(Gtk.Table): def __init__(self): - gtk.Table.__init__(self, rows=5, columns=6, homogeneous=True) + GObject.GObject.__init__(self, n_rows=5, n_columns=6, homogeneous=True) print "Corriendo Canta Bichos . . ." - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.set_property("column-spacing", 2) self.set_property("row-spacing", 2) self.set_border_width(2) @@ -39,7 +45,7 @@ def __init__(self): self.show_all() def __realize(self, widget): - gobject.idle_add(self.__dialog_run) + GObject.idle_add(self.__dialog_run) def __dialog_run(self): dialog = Dialog(parent=self.get_toplevel(), @@ -59,13 +65,13 @@ def salir(self): child.salir() -class Button(gtk.EventBox): +class Button(Gtk.EventBox): def __init__(self, image_path): - gtk.EventBox.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#778899")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#778899")) audio = "%s.%s" % (os.path.basename(image_path).split(".")[0], "ogg") self.sonido = os.path.join(BASE_PATH, "Sonidos", audio) @@ -76,15 +82,15 @@ def __init__(self, image_path): self.nombre = os.path.basename(self.image_path).split(".")[0] self.active = False - boton = gtk.ToolButton() - boton.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#778899")) + boton = Gtk.ToolButton() + boton.override_background_color(Gtk.StateType.NORMAL, color_parser("#778899")) - self.imagen = gtk.Image() - self.imagen.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#778899")) + self.imagen = Gtk.Image() + self.imagen.override_background_color(Gtk.StateType.NORMAL, color_parser("#778899")) boton.set_icon_widget(self.imagen) boton.connect("size-allocate", self.__size_request) - boton.connect("expose-event", self.__redraw) + boton.connect("draw", self.__redraw) boton.connect("clicked", self.__clicked) self.add(boton) @@ -104,10 +110,10 @@ def __clicked(self, widget): if self.active == False: if self.get_parent().get_sounds() < 8: self.active = True - self.modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse("#e9b96e")) - self.imagen.modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse("#e9b96e")) + self.override_background_color( + Gtk.StateType.NORMAL, color_parser("#e9b96e")) + self.imagen.override_background_color( + Gtk.StateType.NORMAL, color_parser("#e9b96e")) self.player.load(self.sonido) else: dialog = Dialog(parent=self.get_toplevel(), @@ -116,41 +122,41 @@ def __clicked(self, widget): elif self.active == True: self.active = False - self.modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse("#778899")) - self.imagen.modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse("#778899")) + self.override_background_color( + Gtk.StateType.NORMAL, color_parser("#778899")) + self.imagen.override_background_color( + Gtk.StateType.NORMAL, color_parser("#778899")) self.player.stop() def __size_request(self, widget, event): rect = self.get_allocation() - gobject.idle_add(self.imagen.set_from_pixbuf, - gtk.gdk.pixbuf_new_from_file_at_size( + GObject.idle_add(self.imagen.set_from_pixbuf, + GdkPixbuf.Pixbuf.new_from_file_at_size( self.image_path, rect.width, -1)) def __redraw(self, widget, event): rect = self.get_allocation() - gobject.idle_add(self.imagen.set_from_pixbuf, - gtk.gdk.pixbuf_new_from_file_at_size( + GObject.idle_add(self.imagen.set_from_pixbuf, + GdkPixbuf.Pixbuf.new_from_file_at_size( self.image_path, rect.width, -1)) def salir(self): self.player.stop() -class Dialog(gtk.Dialog): +class Dialog(Gtk.Dialog): def __init__(self, parent=None, text=""): - gtk.Dialog.__init__(self, parent=parent) + GObject.GObject.__init__(self, parent=parent) self.set_decorated(False) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.set_border_width(15) - label = gtk.Label(text) + label = Gtk.Label(label=text) self.vbox.pack_start(label, True, True, 0) self.vbox.show_all() - gobject.timeout_add(3000, self.destroy) + GObject.timeout_add(3000, self.destroy) diff --git a/CantaBichos/player.py b/CantaBichos/player.py index 637098f..6d30e05 100644 --- a/CantaBichos/player.py +++ b/CantaBichos/player.py @@ -6,29 +6,32 @@ # Uruguay import os -import gobject -import gst +import gi +gi.require_version('Gst', '1.0') +from gi.repository import GObject +from gi.repository import Gst -gobject.threads_init() +GObject.threads_init() +Gst.init(None) -class Player(gobject.GObject): +class Player(GObject.GObject): __gsignals__ = { - "endfile": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, [])} + "endfile": (GObject.SignalFlags.RUN_LAST, + None, [])} def __init__(self): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.player = None self.bus = None - self.player = gst.element_factory_make("playbin2", "player") + self.player = Gst.ElementFactory.make("playbin", "player") - fakesink = gst.element_factory_make("fakesink", "fakesink") - autoaudio = gst.element_factory_make("autoaudiosink", "autoaudio") + fakesink = Gst.ElementFactory.make("fakesink", "fakesink") + autoaudio = Gst.ElementFactory.make("autoaudiosink", "autoaudio") self.player.set_property('video-sink', fakesink) self.player.set_property('audio-sink', autoaudio) @@ -39,29 +42,29 @@ def __init__(self): self.bus.connect('sync-message', self.__sync_message) def __sync_message(self, bus, message): - if message.type == gst.MESSAGE_LATENCY: + if message.type == Gst.MessageType.LATENCY: self.player.recalculate_latency() - elif message.type == gst.MESSAGE_ERROR: + elif message.type == Gst.MessageType.ERROR: err, debug = message.parse_error() pass def __on_mensaje(self, bus, message): - if message.type == gst.MESSAGE_EOS: + if message.type == Gst.MessageType.EOS: self.emit("endfile") - elif message.type == gst.MESSAGE_ERROR: + elif message.type == Gst.MessageType.ERROR: err, debug = message.parse_error() pass def __play(self): - self.player.set_state(gst.STATE_PLAYING) + self.player.set_state(Gst.State.PLAYING) def __pause(self): - self.player.set_state(gst.STATE_PAUSED) + self.player.set_state(Gst.State.PAUSED) def stop(self): - self.player.set_state(gst.STATE_NULL) + self.player.set_state(Gst.State.NULL) def load(self, uri): if not uri: diff --git a/CucaraSims/CucaraSims.py b/CucaraSims/CucaraSims.py index e5cc2ae..4ae7678 100644 --- a/CucaraSims/CucaraSims.py +++ b/CucaraSims/CucaraSims.py @@ -6,36 +6,39 @@ # Uruguay import os -import gtk -import gobject +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf +from gi.repository import GObject from Widgets import Widget_Leccion +from Widgets import color_parser from Widgets import Toolbar from Widgets import ToolbarEstado BASE_PATH = os.path.dirname(__file__) -class CucaraSimsWidget(gtk.HPaned): +class CucaraSimsWidget(Gtk.HPaned): __gsignals__ = { - "exit": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, []), - "set-cursor": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )), - "volumen": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_FLOAT, ))} + "exit": (GObject.SignalFlags.RUN_LAST, + None, []), + "set-cursor": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, )), + "volumen": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_FLOAT, ))} def __init__(self, escenario): - gtk.HPaned.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.lecciones = [] self.toolbar = Toolbar() - vbox = gtk.VBox() + vbox = Gtk.VBox() vbox.pack_start(self.toolbar, False, False, 0) vbox.pack_start(escenario, True, True, 0) self.toolbarestado = ToolbarEstado() @@ -56,21 +59,21 @@ def __init__(self, escenario): self.cursor_root = False self.cursor_tipo = False - gobject.idle_add(self.__config_cursors) + GObject.idle_add(self.__config_cursors) def __volumen_changed(self, widget, valor): self.emit('volumen', valor) def __config_cursors(self): icono = os.path.join(BASE_PATH, "Imagenes", "jarra.png") - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, -1, 24) - self.agua_cursor = gtk.gdk.Cursor( - gtk.gdk.display_get_default(), pixbuf, 0, 0) + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icono, -1, 24) + self.agua_cursor = Gdk.Cursor.new_from_pixbuf( + Gdk.Display.get_default(), pixbuf, 0, 0) icono = os.path.join(BASE_PATH, "Imagenes", "pan.png") - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, -1, 24) - self.alimento_cursor = gtk.gdk.Cursor( - gtk.gdk.display_get_default(), pixbuf, 0, 0) + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icono, -1, 24) + self.alimento_cursor = Gdk.Cursor.new_from_pixbuf( + Gdk.Display.get_default(), pixbuf, 0, 0) self.cursor_root = self.get_toplevel().get_property( "window").get_cursor() @@ -126,7 +129,7 @@ def __run_lectura(self, derecha, lectura): def update(self, juego, _dict): """ - El juego pygame actualiza información en la interfaz gtk. + El juego pygame actualiza información en la interfaz Gtk. """ infocucas = " %sH + %sM = %s" % (_dict["hembras"], _dict["machos"], _dict["cucas"]) @@ -191,28 +194,28 @@ def puntos(self, juego, puntos): self.derecha.set_puntos(puntos) -class Derecha(gtk.EventBox): +class Derecha(Gtk.EventBox): __gsignals__ = { - "lectura": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_STRING, )), - "select": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))} + "lectura": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_STRING, )), + "select": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, ))} def __init__(self): - gtk.EventBox.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.set_border_width(4) - box = gtk.VBox() + box = Gtk.VBox() l = ["Ciclo Vital", "Muda de Exoesqueleto", "Reproducción", "Plaga", "Muerte", "Lectura General"] for leccion in l: - button = gtk.Button(leccion) + button = Gtk.Button(leccion) box.pack_start(button, False, False, 5) button.connect("clicked", self.__emit_lectura) @@ -224,13 +227,13 @@ def __init__(self): button.connect("select", self.__select_imagen) box.pack_start(button, False, False, 5) - frame = gtk.Frame(" Migraciones: ") + frame = Gtk.Frame(label=" Migraciones: ") frame.set_label_align(0.5, 0.5) - self.puntos = gtk.Label("0") + self.puntos = Gtk.Label(label="0") frame.add(self.puntos) box.pack_start(frame, False, False, 5) - button = gtk.Button("Salir") + button = Gtk.Button("Salir") box.pack_end(button, False, False, 5) button.connect("clicked", self.__emit_lectura) @@ -250,17 +253,17 @@ def set_puntos(self, puntos): self.puntos.set_text(str(puntos)) -class ButtonImagen(gtk.EventBox): +class ButtonImagen(Gtk.EventBox): __gsignals__ = { - "select": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_STRING, ))} + "select": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_STRING, ))} def __init__(self, tipo): - gtk.EventBox.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.set_border_width(4) self.tipo = tipo @@ -271,7 +274,7 @@ def __init__(self, tipo): elif self.tipo == "alimento": archivo = "pan.png" - imagen = gtk.Image() + imagen = Gtk.Image() path = os.path.join(BASE_PATH, "Imagenes", archivo) imagen.set_from_file(path) diff --git a/CucaraSims/Cucaracha.py b/CucaraSims/Cucaracha.py index fa96531..493ec4c 100644 --- a/CucaraSims/Cucaracha.py +++ b/CucaraSims/Cucaracha.py @@ -6,7 +6,7 @@ # Uruguay import os -import gobject +from gi.repository import GObject import pygame from pygame.sprite import Sprite import random @@ -23,23 +23,23 @@ INDICE_ROTACION = 5 -class Cucaracha(Sprite, gobject.GObject): +class Cucaracha(Sprite, GObject.GObject): __gsignals__ = { - #"new-edad": (gobject.SIGNAL_RUN_LAST, - # gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )), - "muere": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, - gobject.TYPE_PYOBJECT)), - "muda": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, []), - "reproduce": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))} + #"new-edad": (GObject.SignalFlags.RUN_LAST, + # None, (GObject.TYPE_PYOBJECT, )), + "muere": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, + GObject.TYPE_PYOBJECT)), + "muda": (GObject.SignalFlags.RUN_LAST, + None, []), + "reproduce": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, ))} def __init__(self, sexo, ancho, alto, TIME): Sprite.__init__(self) - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.acciones = ["camina", "gira", "quieto"] self.sexo = sexo diff --git a/CucaraSims/Huevos.py b/CucaraSims/Huevos.py index b3e9b9d..58541c8 100644 --- a/CucaraSims/Huevos.py +++ b/CucaraSims/Huevos.py @@ -6,7 +6,7 @@ # Uruguay import os -import gobject +from gi.repository import GObject import pygame from pygame.sprite import Sprite import random @@ -16,17 +16,17 @@ BASE_PATH = os.path.dirname(__file__) -class Huevo(Sprite, gobject.GObject): +class Huevo(Sprite, GObject.GObject): __gsignals__ = { - "nacer": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, - gobject.TYPE_PYOBJECT))} + "nacer": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, + GObject.TYPE_PYOBJECT))} def __init__(self, pos, TIME): Sprite.__init__(self) - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) path = os.path.join(BASE_PATH, "Imagenes", "huevos.png") self.imagen = pygame.image.load(path) diff --git a/CucaraSims/JAMediaImagenes/ImagePlayer.py b/CucaraSims/JAMediaImagenes/ImagePlayer.py index 2f0337b..9b8621f 100644 --- a/CucaraSims/JAMediaImagenes/ImagePlayer.py +++ b/CucaraSims/JAMediaImagenes/ImagePlayer.py @@ -6,17 +6,17 @@ # Uruguay import os -import gobject -import gst +from gi.repository import GObject +from gi.repository import Gst PR = False -class ImagePlayer(gobject.GObject): +class ImagePlayer(GObject.GObject): def __init__(self, ventana): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.ventana = ventana self.src_path = "" @@ -25,10 +25,10 @@ def __init__(self, ventana): self.width = rect.width self.height = rect.height - self.xid = self.ventana.get_property('window').xid + self.xid = self.ventana.get_property('window').get_xid() self.player = PlayerBin(self.xid, self.width, self.height) - self.ventana.connect("expose-event", self.__set_size) + self.ventana.connect("draw", self.__set_size) def __set_size(self, widget, event): rect = self.ventana.get_allocation() @@ -63,17 +63,17 @@ def stop(self): pass -class PlayerBin(gobject.GObject): +class PlayerBin(GObject.GObject): def __init__(self, ventana_id, width, height): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.ventana_id = ventana_id self.player = None self.bus = None - self.player = gst.element_factory_make("playbin2", "player") + self.player = Gst.ElementFactory.make("playbin", "player") self.video_bin = Video_Out(width, height) self.player.set_property('video-sink', self.video_bin) @@ -83,11 +83,11 @@ def __init__(self, ventana_id, width, height): self.bus.connect('sync-message', self.__sync_message) def __sync_message(self, bus, message): - if message.type == gst.MESSAGE_ELEMENT: - if message.structure.get_name() == 'prepare-xwindow-id': + if message.type == Gst.MessageType.ELEMENT: + if message.get_structure().get_name() == 'prepare-xwindow-id': message.src.set_xwindow_id(self.ventana_id) - elif message.type == gst.MESSAGE_ERROR: + elif message.type == Gst.MessageType.ERROR: err, debug = message.parse_error() if PR: print "ImagePlayer ERROR:" @@ -95,7 +95,7 @@ def __sync_message(self, bus, message): print "\t%s" % debug def __play(self): - self.player.set_state(gst.STATE_PLAYING) + self.player.set_state(Gst.State.PLAYING) def rotar(self, valor): self.stop() @@ -109,7 +109,7 @@ def force_rotation(self, rot): self.video_bin.force_rotation(rot) def stop(self): - self.player.set_state(gst.STATE_NULL) + self.player.set_state(Gst.State.NULL) def load(self, uri): self.stop() @@ -124,26 +124,26 @@ def load(self, uri): return False -class Video_Out(gst.Pipeline): +class Video_Out(Gst.Pipeline): def __init__(self, width, height): - gst.Pipeline.__init__(self) + Gst.Pipeline.__init__(self) self.set_name('video_out') - imagefreeze = gst.element_factory_make('imagefreeze', "imagefreeze") - videoconvert = gst.element_factory_make( - 'ffmpegcolorspace', 'ffmpegcolorspace') + imagefreeze = Gst.ElementFactory.make('imagefreeze', "imagefreeze") + videoconvert = Gst.ElementFactory.make( + 'videoconvert', 'videoconvert') - videoflip = gst.element_factory_make('videoflip', "videoflip") - caps = gst.Caps( - 'video/x-raw-rgb,framerate=30/1,width=%s,height=%s' % ( + videoflip = Gst.ElementFactory.make('videoflip', "videoflip") + caps = Gst.Caps( + 'video/x-raw,format=RGB,framerate=30/1,width=%s,height=%s' % ( width, height)) - filtro = gst.element_factory_make("capsfilter", "filtro") + filtro = Gst.ElementFactory.make("capsfilter", "filtro") filtro.set_property("caps", caps) - ximagesink = gst.element_factory_make('ximagesink', "ximagesink") + ximagesink = Gst.ElementFactory.make('ximagesink', "ximagesink") ximagesink.set_property("force-aspect-ratio", True) self.add(imagefreeze) @@ -157,7 +157,7 @@ def __init__(self, width, height): videoflip.link(filtro) filtro.link(ximagesink) - self.ghost_pad = gst.GhostPad( + self.ghost_pad = Gst.GhostPad.new( "sink", imagefreeze.get_static_pad("sink")) self.ghost_pad.set_target(imagefreeze.get_static_pad("sink")) diff --git a/CucaraSims/JAMediaReproductor/JAMediaBins.py b/CucaraSims/JAMediaReproductor/JAMediaBins.py index acdbb77..2bed922 100644 --- a/CucaraSims/JAMediaReproductor/JAMediaBins.py +++ b/CucaraSims/JAMediaReproductor/JAMediaBins.py @@ -5,36 +5,36 @@ # Flavio Danesse # Uruguay -import gst -import gobject +from gi.repository import Gst +from gi.repository import GObject -gobject.threads_init() +GObject.threads_init() -class JAMedia_Audio_Pipeline(gst.Pipeline): +class JAMedia_Audio_Pipeline(Gst.Pipeline): def __init__(self): - gst.Pipeline.__init__(self) + Gst.Pipeline.__init__(self) self.set_name('jamedia_audio_pipeline') - convert = gst.element_factory_make("audioconvert", "convert") - sink = gst.element_factory_make("autoaudiosink", "sink") + convert = Gst.ElementFactory.make("audioconvert", "convert") + sink = Gst.ElementFactory.make("autoaudiosink", "sink") self.add(convert) self.add(sink) convert.link(sink) - self.add_pad(gst.GhostPad("sink", convert.get_static_pad("sink"))) + self.add_pad(Gst.GhostPad.new("sink", convert.get_static_pad("sink"))) -class JAMedia_Video_Pipeline(gst.Pipeline): +class JAMedia_Video_Pipeline(Gst.Pipeline): def __init__(self): - gst.Pipeline.__init__(self) + Gst.Pipeline.__init__(self) self.set_name('jamedia_video_pipeline') @@ -46,12 +46,12 @@ def __init__(self): 'gamma': 10.0, 'rotacion': 0} - convert = gst.element_factory_make('ffmpegcolorspace', 'convert') - rate = gst.element_factory_make('videorate', 'rate') - videobalance = gst.element_factory_make('videobalance', "videobalance") - gamma = gst.element_factory_make('gamma', "gamma") - videoflip = gst.element_factory_make('videoflip', "videoflip") - pantalla = gst.element_factory_make('xvimagesink', "pantalla") + convert = Gst.ElementFactory.make('ffmpegcolorspace', 'convert') + rate = Gst.ElementFactory.make('videorate', 'rate') + videobalance = Gst.ElementFactory.make('videobalance', "videobalance") + gamma = Gst.ElementFactory.make('gamma', "gamma") + videoflip = Gst.ElementFactory.make('videoflip', "videoflip") + pantalla = Gst.ElementFactory.make('xvimagesink', "pantalla") pantalla.set_property("force-aspect-ratio", True) try: # FIXME: xo no posee esta propiedad @@ -73,7 +73,7 @@ def __init__(self): gamma.link(videoflip) videoflip.link(pantalla) - self.ghost_pad = gst.GhostPad("sink", convert.get_static_pad("sink")) + self.ghost_pad = Gst.GhostPad.new("sink", convert.get_static_pad("sink")) self.ghost_pad.set_target(convert.get_static_pad("sink")) self.add_pad(self.ghost_pad) diff --git a/CucaraSims/JAMediaReproductor/JAMediaReproductor.py b/CucaraSims/JAMediaReproductor/JAMediaReproductor.py index 3429556..3169a8f 100644 --- a/CucaraSims/JAMediaReproductor/JAMediaReproductor.py +++ b/CucaraSims/JAMediaReproductor/JAMediaReproductor.py @@ -6,35 +6,35 @@ # Uruguay import os -import gobject -import gst +from gi.repository import GObject +from gi.repository import Gst from JAMediaBins import JAMedia_Audio_Pipeline from JAMediaBins import JAMedia_Video_Pipeline PR = False -gobject.threads_init() +GObject.threads_init() -class JAMediaReproductor(gobject.GObject): +class JAMediaReproductor(GObject.GObject): __gsignals__ = { - "endfile": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, []), - "estado": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_STRING,)), - "newposicion": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_INT,)), - "video": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_BOOLEAN,)), - "loading-buffer": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_INT, )), + "endfile": (GObject.SignalFlags.RUN_LAST, + None, []), + "estado": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_STRING,)), + "newposicion": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_INT,)), + "video": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_BOOLEAN,)), + "loading-buffer": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_INT, )), } def __init__(self, ventana_id): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.nombre = "JAMediaReproductor" @@ -48,7 +48,7 @@ def __init__(self, ventana_id): self.player = None self.bus = None - self.player = gst.element_factory_make("playbin2", "player") + self.player = Gst.ElementFactory.make("playbin2", "player") self.player.set_property("buffer-size", 50000) self.audio_bin = JAMedia_Audio_Pipeline() @@ -64,25 +64,25 @@ def __init__(self, ventana_id): self.bus.connect('sync-message', self.__sync_message) def __sync_message(self, bus, message): - if message.type == gst.MESSAGE_ELEMENT: + if message.type == Gst.MessageType.ELEMENT: if message.structure.get_name() == 'prepare-xwindow-id': message.src.set_xwindow_id(self.ventana_id) - elif message.type == gst.MESSAGE_STATE_CHANGED: + elif message.type == Gst.MessageType.STATE_CHANGED: old, new, pending = message.parse_state_changed() if self.estado != new: self.estado = new - if new == gst.STATE_PLAYING: + if new == Gst.State.PLAYING: self.emit("estado", "playing") self.__new_handle(True) - elif new == gst.STATE_PAUSED: + elif new == Gst.State.PAUSED: self.emit("estado", "paused") self.__new_handle(False) - elif new == gst.STATE_NULL: + elif new == Gst.State.NULL: self.emit("estado", "None") self.__new_handle(False) @@ -90,7 +90,7 @@ def __sync_message(self, bus, message): self.emit("estado", "paused") self.__new_handle(False) - elif message.type == gst.MESSAGE_TAG: + elif message.type == Gst.MessageType.TAG: taglist = message.parse_tag() datos = taglist.keys() if 'video-codec' in datos: @@ -98,10 +98,10 @@ def __sync_message(self, bus, message): self.video = True self.emit("video", self.video) - elif message.type == gst.MESSAGE_LATENCY: + elif message.type == Gst.MessageType.LATENCY: self.player.recalculate_latency() - elif message.type == gst.MESSAGE_ERROR: + elif message.type == Gst.MessageType.ERROR: err, debug = message.parse_error() if PR: print "JAMediaReproductor ERROR:" @@ -110,11 +110,11 @@ def __sync_message(self, bus, message): self.__new_handle(False) def __on_mensaje(self, bus, message): - if message.type == gst.MESSAGE_EOS: + if message.type == Gst.MessageType.EOS: self.__new_handle(False) self.emit("endfile") - elif message.type == gst.MESSAGE_ERROR: + elif message.type == Gst.MessageType.ERROR: err, debug = message.parse_error() if PR: print "JAMediaReproductor ERROR:" @@ -122,36 +122,36 @@ def __on_mensaje(self, bus, message): print "\t%s" % debug self.__new_handle(False) - elif message.type == gst.MESSAGE_BUFFERING: + elif message.type == Gst.MessageType.BUFFERING: buf = int(message.structure["buffer-percent"]) - if buf < 100 and self.estado == gst.STATE_PLAYING: + if buf < 100 and self.estado == Gst.State.PLAYING: self.emit("loading-buffer", buf) self.__pause() - elif buf > 99 and self.estado != gst.STATE_PLAYING: + elif buf > 99 and self.estado != Gst.State.PLAYING: self.emit("loading-buffer", buf) self.__play() def __play(self): - self.player.set_state(gst.STATE_PLAYING) + self.player.set_state(Gst.State.PLAYING) def __pause(self): - self.player.set_state(gst.STATE_PAUSED) + self.player.set_state(Gst.State.PAUSED) def __new_handle(self, reset): if self.actualizador: - gobject.source_remove(self.actualizador) + GObject.source_remove(self.actualizador) self.actualizador = False if reset: - self.actualizador = gobject.timeout_add(500, self.__handle) + self.actualizador = GObject.timeout_add(500, self.__handle) def __handle(self): if not self.progressbar: return True - duracion = self.player.query_duration(gst.FORMAT_TIME)[0] / gst.SECOND - posicion = self.player.query_position(gst.FORMAT_TIME)[0] / gst.SECOND + duracion = self.player.query_duration(Gst.Format.TIME)[0] / Gst.SECOND + posicion = self.player.query_position(Gst.Format.TIME)[0] / Gst.SECOND pos = posicion * 100 / duracion @@ -165,11 +165,11 @@ def __handle(self): return True def pause_play(self): - if self.estado == gst.STATE_PAUSED or self.estado == gst.STATE_NULL \ - or self.estado == gst.STATE_READY: + if self.estado == Gst.State.PAUSED or self.estado == Gst.State.NULL \ + or self.estado == Gst.State.READY: self.__play() - elif self.estado == gst.STATE_PLAYING: + elif self.estado == Gst.State.PLAYING: self.__pause() def rotar(self, valor): @@ -185,7 +185,7 @@ def get_balance(self): def stop(self): self.__new_handle(False) - self.player.set_state(gst.STATE_NULL) + self.player.set_state(Gst.State.NULL) self.emit("newposicion", 0) def load(self, uri): @@ -204,7 +204,7 @@ def load(self, uri): self.__play() else: - if gst.uri_is_valid(uri): + if Gst.uri_is_valid(uri): self.player.set_property("uri", uri) self.progressbar = False self.__play() @@ -223,11 +223,11 @@ def set_position(self, posicion): posicion = self.duracion * posicion / 100 - event = gst.event_new_seek( - 1.0, gst.FORMAT_TIME, - gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE, - gst.SEEK_TYPE_SET, posicion * 1000000000, - gst.SEEK_TYPE_NONE, self.duracion * 1000000000) + event = Gst.Event.new_seek( + 1.0, Gst.Format.TIME, + Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, + Gst.SeekType.SET, posicion * 1000000000, + Gst.SeekType.NONE, self.duracion * 1000000000) self.player.send_event(event) diff --git a/CucaraSims/Juego.py b/CucaraSims/Juego.py index bf01d33..30d3fcf 100644 --- a/CucaraSims/Juego.py +++ b/CucaraSims/Juego.py @@ -6,9 +6,9 @@ # Uruguay import os -import gobject +from gi.repository import GObject import pygame -import gtk +from gi.repository import Gtk import random import platform @@ -27,26 +27,26 @@ BASE_PATH = os.path.dirname(BASE_PATH) OLPC = 'olpc' in platform.platform() -gobject.threads_init() +GObject.threads_init() -class CucaraSims(gobject.GObject): +class CucaraSims(GObject.GObject): __gsignals__ = { - "exit": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, []), - "lectura": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_STRING, )), - "clear-cursor-gtk": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, []), - "update": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )), - "puntos": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_INT, ))} + "exit": (GObject.SignalFlags.RUN_LAST, + None, []), + "lectura": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_STRING, )), + "clear-cursor-gtk": (GObject.SignalFlags.RUN_LAST, + None, []), + "update": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, )), + "puntos": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_INT, ))} def __init__(self): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.RESOLUCION_INICIAL = RESOLUCION_INICIAL self.resolucionreal = RESOLUCION_INICIAL @@ -285,8 +285,8 @@ def run(self): if not OLPC: self.reloj.tick(35) self.__control_de_poblacion() - while gtk.events_pending(): - gtk.main_iteration() + while Gtk.events_pending(): + Gtk.main_iteration() self.huevos.clear(self.ventana, self.escenario) self.alimentos.clear(self.ventana, self.escenario) self.muertas.clear(self.ventana, self.escenario) diff --git a/CucaraSims/Timer.py b/CucaraSims/Timer.py index f51ff97..173ecca 100644 --- a/CucaraSims/Timer.py +++ b/CucaraSims/Timer.py @@ -6,18 +6,18 @@ # Uruguay import time -import gobject +from gi.repository import GObject -class Timer(gobject.GObject): +class Timer(GObject.GObject): __gsignals__ = { - "new-time": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))} + "new-time": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, ))} def __init__(self, demora): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.actualizador = False self.init = int(time.time()) @@ -49,10 +49,10 @@ def __handle(self): def new_handle(self, reset): if self.actualizador: - gobject.source_remove(self.actualizador) + GObject.source_remove(self.actualizador) self.actualizador = False if reset: - self.actualizador = gobject.timeout_add(1000, self.__handle) + self.actualizador = GObject.timeout_add(1000, self.__handle) def salir(self): self.new_handle(False) diff --git a/CucaraSims/Widgets.py b/CucaraSims/Widgets.py index 69632e0..875b22f 100644 --- a/CucaraSims/Widgets.py +++ b/CucaraSims/Widgets.py @@ -6,8 +6,10 @@ # Uruguay import os -import gtk -import gobject +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GObject +from gi.repository import GdkPixbuf import pygame from pygame.sprite import Sprite from JAMediaImagenes.ImagePlayer import ImagePlayer @@ -15,9 +17,13 @@ BASE_PATH = os.path.dirname(__file__) +def color_parser(color): + rgba = Gdk.RGBA() + rgba.parse(color) + return rgba def get_separador(draw=False, ancho=0, expand=False): - separador = gtk.SeparatorToolItem() + separador = Gtk.SeparatorToolItem() separador.props.draw = draw separador.set_size_request(ancho, -1) separador.set_expand(expand) @@ -33,15 +39,15 @@ def describe_archivo(archivo): return retorno -class Widget_Leccion(gtk.Dialog): +class Widget_Leccion(Gtk.Dialog): def __init__(self, parent=None, lectura=""): - gtk.Dialog.__init__(self, parent=parent, - buttons=("Cerrar", gtk.RESPONSE_ACCEPT)) + GObject.GObject.__init__(self, parent=parent) + self.add_button(button_text="Cerrar", response_id=Gtk.ResponseType.ACCEPT) self.set_decorated(False) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.set_border_width(15) self.panel = Panel(lectura) @@ -62,13 +68,13 @@ def stop(self): visor.player.stop() -class Panel(gtk.HPaned): +class Panel(Gtk.HPaned): def __init__(self, lectura): - gtk.HPaned.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) dirpath = False if lectura == "ciclo vital": @@ -87,7 +93,7 @@ def __init__(self, lectura): dirpath = os.path.join(BASE_PATH, "Lecturas", "Extincion") self.players = [] - vbox = gtk.VBox() + vbox = Gtk.VBox() for archivo in sorted(os.listdir(dirpath)): tipo = describe_archivo(os.path.join(dirpath, archivo)) if 'video' in tipo or 'application/ogg' in tipo or "image" in tipo: @@ -97,10 +103,10 @@ def __init__(self, lectura): self.pack1(vbox, resize=True, shrink=True) - self.lectura = gtk.TextView() + self.lectura = Gtk.TextView() self.lectura.set_editable(False) - scroll = gtk.ScrolledWindow() - scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + scroll = Gtk.ScrolledWindow() + scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) scroll.add(self.lectura) self.pack2(scroll, resize=False, shrink=False) @@ -113,13 +119,13 @@ def __init__(self, lectura): self.show_all() -class Visor(gtk.DrawingArea): +class Visor(Gtk.DrawingArea): def __init__(self, archivo): - gtk.DrawingArea.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.archivo = archivo self.player = False @@ -133,8 +139,8 @@ def __realize(self, widget): if "image" in tipo: self.player = ImagePlayer(self) elif 'video' in tipo or 'application/ogg': - self.player = JAMediaReproductor(self.get_property('window').xid) - gobject.idle_add(self.player.load, self.archivo) + self.player = JAMediaReproductor(self.get_property('window').get_xid()) + GObject.idle_add(self.player.load, self.archivo) class Cursor(Sprite): @@ -184,99 +190,99 @@ def update(self): self.kill() -class Toolbar(gtk.EventBox): +class Toolbar(Gtk.EventBox): def __init__(self): - gtk.EventBox.__init__(self) + GObject.GObject.__init__(self) - toolbar = gtk.Toolbar() + toolbar = Gtk.Toolbar() - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) - toolbar.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) + toolbar.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) toolbar.insert(get_separador(draw=False, ancho=3, expand=False), -1) - imagen = gtk.Image() + imagen = Gtk.Image() icono = os.path.join(BASE_PATH, "Imagenes", "cucaracha2.png") - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icono, -1, 24) imagen.set_from_pixbuf(pixbuf) imagen.show() - item = gtk.ToolItem() + item = Gtk.ToolItem() item.add(imagen) toolbar.insert(item, -1) - item = gtk.ToolItem() - self.labelcucas = gtk.Label(" 0H + 0M = 0") - self.labelcucas.modify_fg(gtk.STATE_NORMAL, - gtk.gdk.color_parse("#000000")) + item = Gtk.ToolItem() + self.labelcucas = Gtk.Label(label=" 0H + 0M = 0") + self.labelcucas.override_color(Gtk.StateType.NORMAL, + color_parser("#000000")) self.labelcucas.show() item.add(self.labelcucas) toolbar.insert(item, -1) toolbar.insert(get_separador(draw=False, ancho=3, expand=False), -1) - imagen = gtk.Image() + imagen = Gtk.Image() icono = os.path.join(BASE_PATH, "Imagenes", "huevos.png") - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icono, -1, 24) imagen.set_from_pixbuf(pixbuf) imagen.show() - item = gtk.ToolItem() + item = Gtk.ToolItem() item.add(imagen) toolbar.insert(item, -1) - item = gtk.ToolItem() - self.labelootecas = gtk.Label(" = 0") - self.labelootecas.modify_fg(gtk.STATE_NORMAL, - gtk.gdk.color_parse("#000000")) + item = Gtk.ToolItem() + self.labelootecas = Gtk.Label(label=" = 0") + self.labelootecas.override_color(Gtk.StateType.NORMAL, + color_parser("#000000")) self.labelootecas.show() item.add(self.labelootecas) toolbar.insert(item, -1) - imagen = gtk.Image() + imagen = Gtk.Image() icono = os.path.join(BASE_PATH, "Imagenes", "jarra.png") - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, -1, 24) + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icono, -1, 24) imagen.set_from_pixbuf(pixbuf) imagen.show() - item = gtk.ToolItem() + item = Gtk.ToolItem() item.add(imagen) toolbar.insert(item, -1) - item = gtk.ToolItem() - self.labelagua = gtk.Label(" = 0") - self.labelagua.modify_fg(gtk.STATE_NORMAL, - gtk.gdk.color_parse("#000000")) + item = Gtk.ToolItem() + self.labelagua = Gtk.Label(label=" = 0") + self.labelagua.override_color(Gtk.StateType.NORMAL, + color_parser("#000000")) self.labelagua.show() item.add(self.labelagua) toolbar.insert(item, -1) toolbar.insert(get_separador(draw=False, ancho=3, expand=False), -1) - imagen = gtk.Image() + imagen = Gtk.Image() icono = os.path.join(BASE_PATH, "Imagenes", "pan.png") - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(icono, -1, 24) + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(icono, -1, 24) imagen.set_from_pixbuf(pixbuf) imagen.show() - item = gtk.ToolItem() + item = Gtk.ToolItem() item.add(imagen) toolbar.insert(item, -1) - item = gtk.ToolItem() - self.labelalimento = gtk.Label(" = 0") - self.labelalimento.modify_fg(gtk.STATE_NORMAL, - gtk.gdk.color_parse("#000000")) + item = Gtk.ToolItem() + self.labelalimento = Gtk.Label(label=" = 0") + self.labelalimento.override_color(Gtk.StateType.NORMAL, + color_parser("#000000")) self.labelalimento.show() item.add(self.labelalimento) toolbar.insert(item, -1) toolbar.insert(get_separador(draw=False, ancho=3, expand=False), -1) - item = gtk.ToolItem() - self.labeltiempo = gtk.Label(" Años: 0 Dias: 0 Horas: 0") - self.labeltiempo.modify_fg(gtk.STATE_NORMAL, - gtk.gdk.color_parse("#000000")) + item = Gtk.ToolItem() + self.labeltiempo = Gtk.Label(label=" Años: 0 Dias: 0 Horas: 0") + self.labeltiempo.override_color(Gtk.StateType.NORMAL, + color_parser("#000000")) self.labeltiempo.show() item.add(self.labeltiempo) toolbar.insert(item, -1) @@ -294,34 +300,34 @@ def set_info(self, infocucas, infoootecas, infoagua, infoalimento, tiempo): self.labeltiempo.set_text(tiempo) -class ToolbarEstado(gtk.EventBox): +class ToolbarEstado(Gtk.EventBox): __gsignals__ = { - "volumen": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_FLOAT, ))} + "volumen": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_FLOAT, ))} def __init__(self): - gtk.EventBox.__init__(self) + GObject.GObject.__init__(self) - toolbar = gtk.Toolbar() + toolbar = Gtk.Toolbar() - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) - toolbar.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) + toolbar.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) toolbar.insert(get_separador(draw=False, ancho=3, expand=False), -1) - item = gtk.ToolItem() - self.label = gtk.Label() - self.label.modify_fg(gtk.STATE_NORMAL, - gtk.gdk.color_parse("#000000")) + item = Gtk.ToolItem() + self.label = Gtk.Label() + self.label.override_color(Gtk.StateType.NORMAL, + color_parser("#000000")) self.label.show() item.add(self.label) toolbar.insert(item, -1) toolbar.insert(get_separador(draw=False, ancho=0, expand=True), -1) - item = gtk.ToolItem() + item = Gtk.ToolItem() self.volumen = ControlVolumen() self.volumen.connect("value-changed", self.__value_changed) self.volumen.show() @@ -340,17 +346,17 @@ def set_info(self, info): self.label.set_text(info) -class ControlVolumen(gtk.VolumeButton): +class ControlVolumen(Gtk.VolumeButton): __gsignals__ = { - "volumen": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_FLOAT, ))} + "volumen": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_FLOAT, ))} def __init__(self): - gtk.VolumeButton.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.connect("value-changed", self.__value_changed) self.show_all() diff --git a/EventTraductor/EventTraductor.py b/EventTraductor/EventTraductor.py index 05c403b..2773827 100644 --- a/EventTraductor/EventTraductor.py +++ b/EventTraductor/EventTraductor.py @@ -1,4 +1,5 @@ -import gtk +from gi.repository import Gtk +from gi.repository import Gdk import pygame keys = { @@ -19,7 +20,7 @@ def KeyPressTraduce(event): - nombre = gtk.gdk.keyval_name(event.keyval) + nombre = Gdk.keyval_name(event.keyval) unic = str.lower(nombre) if nombre in keys.keys(): evt = pygame.event.Event(pygame.KEYDOWN, @@ -28,7 +29,7 @@ def KeyPressTraduce(event): def KeyReleaseTraduce(event): - nombre = gtk.gdk.keyval_name(event.keyval) + nombre = Gdk.keyval_name(event.keyval) unic = str.lower(nombre) if nombre in keys.keys(): evt = pygame.event.Event(pygame.KEYUP, @@ -37,12 +38,12 @@ def KeyReleaseTraduce(event): def MousemotionTraduce(event, rect, res): - x, y, state = event.window.get_pointer() + win, x, y, state = event.window.get_pointer() rel = (x, y) button_state = [ - state & gtk.gdk.BUTTON1_MASK and 1 or 0, - state & gtk.gdk.BUTTON2_MASK and 1 or 0, - state & gtk.gdk.BUTTON3_MASK and 1 or 0, + state & Gdk.ModifierType.BUTTON1_MASK and 1 or 0, + state & Gdk.ModifierType.BUTTON2_MASK and 1 or 0, + state & Gdk.ModifierType.BUTTON3_MASK and 1 or 0, ] px = float(x) * 100.0 / float(rect.width) diff --git a/Intro/Intro.py b/Intro/Intro.py index e2cd3e1..910565a 100644 --- a/Intro/Intro.py +++ b/Intro/Intro.py @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- import os -import gobject +from gi.repository import GObject import pygame -import gtk +from gi.repository import Gtk import platform from pygame.locals import HWSURFACE @@ -17,20 +17,20 @@ BASE_PATH = os.path.dirname(BASE_PATH) OLPC = 'olpc' in platform.platform() -gobject.threads_init() +GObject.threads_init() -class Intro(gobject.GObject): +class Intro(GObject.GObject): __gsignals__ = { - "exit": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, []), - "go": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_STRING, ))} + "exit": (GObject.SignalFlags.RUN_LAST, + None, []), + "go": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_STRING, ))} def __init__(self): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.RESOLUCION_INICIAL = RESOLUCION_INICIAL self.resolucionreal = RESOLUCION_INICIAL @@ -75,10 +75,10 @@ def run(self): while self.estado: if not OLPC: self.reloj.tick(35) - while gtk.events_pending(): - gtk.main_iteration() + while Gtk.events_pending(): + Gtk.main_iteration() if len(self.sprites.sprites()) < 5: - gobject.idle_add(self.sprites.add, + GObject.idle_add(self.sprites.add, Bicho(RESOLUCION_INICIAL[0], RESOLUCION_INICIAL[1])) self.sprites.clear(self.ventana, self.escenario) diff --git a/Main.py b/Main.py index 6b149ad..a2fc222 100644 --- a/Main.py +++ b/Main.py @@ -7,8 +7,8 @@ import os import sys -import gtk -import gobject +from gi.repository import Gtk +from gi.repository import GObject from EventTraductor.EventTraductor import KeyPressTraduce from EventTraductor.EventTraductor import KeyReleaseTraduce @@ -21,18 +21,18 @@ from OjosCompuestos.OjosCompuestos import OjosCompuestos -class Bichos(gtk.Window): +class Bichos(Gtk.Window): def __init__(self): - gtk.Window.__init__(self) + GObject.GObject.__init__(self) self.set_title("Bichos") - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) + self.override_background_color(Gtk.StateType.NORMAL, Gdk.color_parse("#000000")) #self.set_icon_from_file(os.path.join(BASE, "Iconos", "bichos.svg")) self.set_resizable(True) self.set_size_request(640, 480) - self.set_position(gtk.WIN_POS_CENTER) + self.set_position(Gtk.WindowPosition.CENTER) self.juego = False self.widgetjuego = False @@ -50,7 +50,7 @@ def __key_press_even(self, widget, event): if self.juego: KeyPressTraduce(event) else: - if gtk.gdk.keyval_name(event.keyval) == "Escape": + if Gdk.keyval_name(event.keyval) == "Escape": self.widgetjuego.salir() self.switch(False, 1) return False @@ -71,7 +71,7 @@ def __redraw(self, widget, size): self.juego.escalar(size) def __run_intro(self, escenario): - xid = escenario.get_property('window').xid + xid = escenario.get_property('window').get_xid os.putenv('SDL_WINDOWID', str(xid)) self.juego = Intro() self.juego.connect("exit", self.__salir) @@ -81,7 +81,7 @@ def __run_intro(self, escenario): return False def __run_cucarasims(self, escenario): - xid = escenario.get_property('window').xid + xid = escenario.get_property('window').get_xid os.putenv('SDL_WINDOWID', str(xid)) self.juego = CucaraSims() self.widgetjuego.connect("set-cursor", self.juego.set_cursor) @@ -98,17 +98,17 @@ def __run_cucarasims(self, escenario): def __dialog_exit_game(self, widget, juego_name): self.juego.pause() - dialog = gtk.Dialog(parent=self, - buttons=("Salir", gtk.RESPONSE_ACCEPT, - "Cancelar", gtk.RESPONSE_CANCEL)) - dialog.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) - label = gtk.Label("Salir de %s" % juego_name) + dialog = Gtk.Dialog(parent=self, + buttons=("Salir", Gtk.ResponseType.ACCEPT, + "Cancelar", Gtk.ResponseType.CANCEL)) + dialog.override_background_color(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff")) + label = Gtk.Label(label="Salir de %s" % juego_name) label.show() dialog.set_border_width(10) dialog.vbox.pack_start(label, True, True, 0) resp = dialog.run() dialog.destroy() - if resp == gtk.RESPONSE_ACCEPT: + if resp == Gtk.ResponseType.ACCEPT: self.__run_games(False, "menu") return self.juego.unpause() @@ -142,39 +142,39 @@ def switch(self, widget, valor): for child in self.get_children(): self.remove(child) child.destroy() - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) + self.override_background_color(Gtk.StateType.NORMAL, Gdk.color_parse("#000000")) if valor == 1: self.widgetjuego = Escenario() self.widgetjuego.connect("new-size", self.__redraw) self.add(self.widgetjuego) - gobject.idle_add(self.__run_intro, self.widgetjuego) + GObject.idle_add(self.__run_intro, self.widgetjuego) elif valor == 2: - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color3(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff")) escenario = Escenario() - escenario.modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) + escenario.override_background_color( + Gtk.StateType.NORMAL, Gdk.color_parse("#000000")) escenario.connect("new-size", self.__redraw) escenario.connect("mouse-enter", self.__mouse_enter) self.widgetjuego = CucaraSimsWidget(escenario) self.add(self.widgetjuego) - gobject.idle_add(self.__run_cucarasims, escenario) + GObject.idle_add(self.__run_cucarasims, escenario) elif valor == 3: - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff")) self.widgetjuego = CantaBichos() self.add(self.widgetjuego) elif valor == 4: - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff")) escenario = Escenario() - escenario.modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) + escenario.override_background_color( + Gtk.StateType.NORMAL, Gdk.color_parse("#000000")) self.widgetjuego = OjosCompuestos(escenario) self.add(self.widgetjuego) if __name__ == "__main__": Bichos() - gtk.main() + Gtk.main() diff --git a/OjosCompuestos/JAMediaImagenes/ImagePlayer.py b/OjosCompuestos/JAMediaImagenes/ImagePlayer.py index 2f0337b..a1edc9b 100644 --- a/OjosCompuestos/JAMediaImagenes/ImagePlayer.py +++ b/OjosCompuestos/JAMediaImagenes/ImagePlayer.py @@ -6,17 +6,17 @@ # Uruguay import os -import gobject -import gst +from gi.repository import GObject +from gi.repository import Gst PR = False -class ImagePlayer(gobject.GObject): +class ImagePlayer(GObject.GObject): def __init__(self, ventana): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.ventana = ventana self.src_path = "" @@ -25,10 +25,10 @@ def __init__(self, ventana): self.width = rect.width self.height = rect.height - self.xid = self.ventana.get_property('window').xid + self.xid = self.ventana.get_property('window').get_xid self.player = PlayerBin(self.xid, self.width, self.height) - self.ventana.connect("expose-event", self.__set_size) + self.ventana.connect("draw", self.__set_size) def __set_size(self, widget, event): rect = self.ventana.get_allocation() @@ -63,17 +63,17 @@ def stop(self): pass -class PlayerBin(gobject.GObject): +class PlayerBin(GObject.GObject): def __init__(self, ventana_id, width, height): - gobject.GObject.__init__(self) + GObject.GObject.__init__(self) self.ventana_id = ventana_id self.player = None self.bus = None - self.player = gst.element_factory_make("playbin2", "player") + self.player = Gst.ElementFactory.make("playbin", "player") self.video_bin = Video_Out(width, height) self.player.set_property('video-sink', self.video_bin) @@ -83,11 +83,11 @@ def __init__(self, ventana_id, width, height): self.bus.connect('sync-message', self.__sync_message) def __sync_message(self, bus, message): - if message.type == gst.MESSAGE_ELEMENT: - if message.structure.get_name() == 'prepare-xwindow-id': + if message.type == Gst.MessageType.ELEMENT: + if message.get_structure().get_name() == 'prepare-xwindow-id': message.src.set_xwindow_id(self.ventana_id) - elif message.type == gst.MESSAGE_ERROR: + elif message.type == Gst.MessageType.ERROR: err, debug = message.parse_error() if PR: print "ImagePlayer ERROR:" @@ -95,7 +95,7 @@ def __sync_message(self, bus, message): print "\t%s" % debug def __play(self): - self.player.set_state(gst.STATE_PLAYING) + self.player.set_state(Gst.State.PLAYING) def rotar(self, valor): self.stop() @@ -109,7 +109,7 @@ def force_rotation(self, rot): self.video_bin.force_rotation(rot) def stop(self): - self.player.set_state(gst.STATE_NULL) + self.player.set_state(Gst.State.NULL) def load(self, uri): self.stop() @@ -124,26 +124,26 @@ def load(self, uri): return False -class Video_Out(gst.Pipeline): +class Video_Out(Gst.Pipeline): def __init__(self, width, height): - gst.Pipeline.__init__(self) + Gst.Pipeline.__init__(self) self.set_name('video_out') - imagefreeze = gst.element_factory_make('imagefreeze', "imagefreeze") - videoconvert = gst.element_factory_make( - 'ffmpegcolorspace', 'ffmpegcolorspace') + imagefreeze = Gst.ElementFactory.make('imagefreeze', "imagefreeze") + videoconvert = Gst.ElementFactory.make( + 'videoconvert', 'videoconvert') - videoflip = gst.element_factory_make('videoflip', "videoflip") - caps = gst.Caps( - 'video/x-raw-rgb,framerate=30/1,width=%s,height=%s' % ( + videoflip = Gst.ElementFactory.make('videoflip', "videoflip") + caps = Gst.Caps( + 'video/x-raw,format=RGB,framerate=30/1,width=%s,height=%s' % ( width, height)) - filtro = gst.element_factory_make("capsfilter", "filtro") + filtro = Gst.ElementFactory.make("capsfilter", "filtro") filtro.set_property("caps", caps) - ximagesink = gst.element_factory_make('ximagesink', "ximagesink") + ximagesink = Gst.ElementFactory.make('ximagesink', "ximagesink") ximagesink.set_property("force-aspect-ratio", True) self.add(imagefreeze) @@ -157,7 +157,7 @@ def __init__(self, width, height): videoflip.link(filtro) filtro.link(ximagesink) - self.ghost_pad = gst.GhostPad( + self.ghost_pad = Gst.GhostPad.new( "sink", imagefreeze.get_static_pad("sink")) self.ghost_pad.set_target(imagefreeze.get_static_pad("sink")) diff --git a/OjosCompuestos/OjosCompuestos.py b/OjosCompuestos/OjosCompuestos.py index d4354bd..9d32f83 100644 --- a/OjosCompuestos/OjosCompuestos.py +++ b/OjosCompuestos/OjosCompuestos.py @@ -6,23 +6,28 @@ # Uruguay import os -import gtk -import gobject +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GObject from PlayerList import PlayerList from JAMediaImagenes.ImagePlayer import ImagePlayer BASE_PATH = os.path.dirname(__file__) +def color_parser(color): + rgba = Gdk.RGBA() + rgba.parse(color) + return rgba -class OjosCompuestos(gtk.HPaned): +class OjosCompuestos(Gtk.HPaned): def __init__(self, pantalla): - gtk.HPaned.__init__(self) + GObject.GObject.__init__(self) print "Corriendo Ojos Compuestos . . ." - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.player = False self.pantalla = pantalla @@ -37,7 +42,7 @@ def __init__(self, pantalla): self.show_all() def __load_imagenes(self, widget): - gobject.idle_add(self.__run) + GObject.idle_add(self.__run) def __run(self): self.player = ImagePlayer(self.pantalla) @@ -59,19 +64,19 @@ def salir(self): self.player.stop() -class Dialog(gtk.Dialog): +class Dialog(Gtk.Dialog): def __init__(self, parent=None, text=""): - gtk.Dialog.__init__(self, parent=parent) + GObject.GObject.__init__(self, parent=parent) self.set_decorated(False) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.set_border_width(15) - label = gtk.Label(text) + label = Gtk.Label(label=text) self.vbox.pack_start(label, True, True, 0) self.vbox.show_all() - gobject.timeout_add(3000, self.destroy) + GObject.timeout_add(3000, self.destroy) diff --git a/OjosCompuestos/PlayerList.py b/OjosCompuestos/PlayerList.py index 8a071ac..856d913 100644 --- a/OjosCompuestos/PlayerList.py +++ b/OjosCompuestos/PlayerList.py @@ -5,27 +5,34 @@ # Flavio Danesse # Uruguay -import gtk -import gobject +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GdkPixbuf +from gi.repository import GObject +def color_parser(color): + rgba = Gdk.RGBA() + rgba.parse(color) + return rgba -class PlayerList(gtk.Frame): + +class PlayerList(Gtk.Frame): __gsignals__ = { - "nueva-seleccion": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))} + "nueva-seleccion": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, ))} def __init__(self): - gtk.Frame.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) - vbox = gtk.VBox() + vbox = Gtk.VBox() self.lista = Lista() - scroll = gtk.ScrolledWindow() - scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + scroll = Gtk.ScrolledWindow() + scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) scroll.add(self.lista) vbox.pack_start(scroll, True, True, 0) @@ -94,20 +101,20 @@ def get_items_paths(self): return filepaths -class Lista(gtk.TreeView): +class Lista(Gtk.TreeView): __gsignals__ = { - "nueva-seleccion": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))} + "nueva-seleccion": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, ))} def __init__(self): - gtk.TreeView.__init__(self, gtk.ListStore( - gtk.gdk.Pixbuf, - gobject.TYPE_STRING, - gobject.TYPE_STRING)) + GObject.GObject.__init__(self, model=Gtk.ListStore( + GdkPixbuf.Pixbuf, + GObject.TYPE_STRING, + GObject.TYPE_STRING)) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.set_property("rules-hint", True) self.set_headers_clickable(False) self.set_headers_visible(False) @@ -123,11 +130,10 @@ def __init__(self): self.show_all() - def __selecciones(self, path, column): + def __selecciones(self, selection, model, path, is_selected, user_data): """ Cuando se selecciona un item en la lista. """ - if not self.permitir_select: return True @@ -137,7 +143,7 @@ def __selecciones(self, path, column): if self.valor_select != valor: self.valor_select = valor - gobject.timeout_add(3, self.__select, + GObject.timeout_add(3, self.__select, self.get_model().get_path(_iter)) return True @@ -156,25 +162,25 @@ def __setear_columnas(self): self.append_column(self.__construir_columa('', 2, False)) def __construir_columa(self, text, index, visible): - render = gtk.CellRendererText() - render.set_property("background", gtk.gdk.color_parse("#ffffff")) - render.set_property("foreground", gtk.gdk.color_parse("#000000")) + render = Gtk.CellRendererText() + render.set_property("background", "#ffffff") + render.set_property("foreground", "#000000") - columna = gtk.TreeViewColumn(text, render, text=index) + columna = Gtk.TreeViewColumn(text, render, text=index) columna.set_sort_column_id(index) columna.set_property('visible', visible) columna.set_property('resizable', False) - columna.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE) + columna.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) return columna def __construir_columa_icono(self, text, index, visible): - render = gtk.CellRendererPixbuf() - render.set_property("cell-background", gtk.gdk.color_parse("#ffffff")) + render = Gtk.CellRendererPixbuf() + render.set_property("cell-background", "#ffffff") - columna = gtk.TreeViewColumn(text, render, pixbuf=index) + columna = Gtk.TreeViewColumn(text, render, pixbuf=index) columna.set_property('visible', visible) columna.set_property('resizable', False) - columna.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE) + columna.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) return columna def __ejecutar_agregar_elemento(self, elementos): @@ -185,11 +191,11 @@ def __ejecutar_agregar_elemento(self, elementos): return False texto, path = elementos[0] - pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(path, 140, -1) + pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(path, 140, -1) self.get_model().append([pixbuf, texto, path]) elementos.remove(elementos[0]) - gobject.idle_add(self.__ejecutar_agregar_elemento, elementos) + GObject.idle_add(self.__ejecutar_agregar_elemento, elementos) return False def limpiar(self): @@ -206,7 +212,7 @@ def agregar_items(self, elementos): """ self.get_toplevel().set_sensitive(False) self.permitir_select = False - gobject.idle_add(self.__ejecutar_agregar_elemento, elementos) + GObject.idle_add(self.__ejecutar_agregar_elemento, elementos) def seleccionar_siguiente(self, widget=None): modelo, _iter = self.get_selection().get_selected() diff --git a/SugarBichos.py b/SugarBichos.py index 977c49b..5d9339b 100644 --- a/SugarBichos.py +++ b/SugarBichos.py @@ -7,20 +7,24 @@ import os import sys -import gtk -import gobject +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk +from gi.repository import GObject +from gi.repository import Gdk from EventTraductor.EventTraductor import KeyPressTraduce from EventTraductor.EventTraductor import KeyReleaseTraduce from Intro.Intro import Intro +from Widgets import color_parser from Widgets import Escenario from CantaBichos.CantaBichos import CantaBichos from CucaraSims.CucaraSims import CucaraSimsWidget from CucaraSims.Juego import CucaraSims from OjosCompuestos.OjosCompuestos import OjosCompuestos -from sugar.activity.activity import Activity +from sugar3.activity.activity import Activity class Bichos(Activity): @@ -28,7 +32,7 @@ class Bichos(Activity): def __init__(self, handle): Activity.__init__(self, handle, False) - self.socket = gtk.Socket() + self.socket = Gtk.Socket() self.set_canvas(self.socket) self.interfaz = Interfaz() self.socket.add_id(self.interfaz.get_id()) @@ -44,11 +48,11 @@ def write_file(self, file_path): pass -class Interfaz(gtk.Plug): +class Interfaz(Gtk.Plug): def __init__(self): - gtk.Plug.__init__(self, 0L) + GObject.GObject.__init__(self) #GObject.GObject.__init__(self, 0l) self.juego = False self.widgetjuego = False @@ -62,7 +66,7 @@ def key_press_even(self, widget, event): if self.juego: KeyPressTraduce(event) else: - if gtk.gdk.keyval_name(event.keyval) == "Escape": + if Gdk.keyval_name(event.keyval) == "Escape": self.widgetjuego.salir() self.switch(False, 1) return False @@ -83,7 +87,7 @@ def __redraw(self, widget, size): self.juego.escalar(size) def __run_intro(self, escenario): - xid = escenario.get_property('window').xid + xid = escenario.get_property('window').get_xid() os.putenv('SDL_WINDOWID', str(xid)) self.juego = Intro() self.juego.connect("exit", self.__salir) @@ -93,7 +97,7 @@ def __run_intro(self, escenario): return False def __run_cucarasims(self, escenario): - xid = escenario.get_property('window').xid + xid = escenario.get_property('window').get_xid() os.putenv('SDL_WINDOWID', str(xid)) self.juego = CucaraSims() self.widgetjuego.connect("set-cursor", self.juego.set_cursor) @@ -110,17 +114,17 @@ def __run_cucarasims(self, escenario): def __dialog_exit_game(self, widget, juego_name): self.juego.pause() - dialog = gtk.Dialog(parent=self, - buttons=("Salir", gtk.RESPONSE_ACCEPT, - "Cancelar", gtk.RESPONSE_CANCEL)) - dialog.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) - label = gtk.Label("Salir de %s" % juego_name) + dialog = Gtk.Dialog(parent=self, + buttons=("Salir", Gtk.ResponseType.ACCEPT, + "Cancelar", Gtk.ResponseType.CANCEL)) + dialog.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) + label = Gtk.Label(label="Salir de %s" % juego_name) label.show() dialog.set_border_width(10) dialog.vbox.pack_start(label, True, True, 0) resp = dialog.run() dialog.destroy() - if resp == gtk.RESPONSE_ACCEPT: + if resp == Gtk.ResponseType.ACCEPT: self.__run_games(False, "menu") return self.juego.unpause() @@ -154,34 +158,34 @@ def switch(self, widget, valor): for child in self.get_children(): self.remove(child) child.destroy() - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#000000")) if valor == 1: self.widgetjuego = Escenario() self.widgetjuego.connect("new-size", self.__redraw) self.add(self.widgetjuego) - gobject.idle_add(self.__run_intro, self.widgetjuego) + GObject.idle_add(self.__run_intro, self.widgetjuego) elif valor == 2: - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) escenario = Escenario() - escenario.modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) + escenario.override_background_color( + Gtk.StateType.NORMAL, color_parser("#000000")) escenario.connect("new-size", self.__redraw) escenario.connect("mouse-enter", self.__mouse_enter) self.widgetjuego = CucaraSimsWidget(escenario) self.add(self.widgetjuego) - gobject.idle_add(self.__run_cucarasims, escenario) + GObject.idle_add(self.__run_cucarasims, escenario) elif valor == 3: - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.widgetjuego = CantaBichos() self.add(self.widgetjuego) elif valor == 4: - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#ffffff")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) escenario = Escenario() - escenario.modify_bg( - gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) + escenario.override_background_color( + Gtk.StateType.NORMAL, color_parser("#000000")) self.widgetjuego = OjosCompuestos(escenario) self.add(self.widgetjuego) diff --git a/Widgets.py b/Widgets.py index 0abe6b0..527c8d3 100644 --- a/Widgets.py +++ b/Widgets.py @@ -1,38 +1,43 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -import gtk -import gobject +from gi.repository import Gtk +from gi.repository import Gdk +from gi.repository import GObject from EventTraductor.EventTraductor import MousemotionTraduce from EventTraductor.EventTraductor import Traduce_button_press_event from EventTraductor.EventTraductor import Traduce_button_release_event +def color_parser(color): + rgba = Gdk.RGBA() + rgba.parse(color) + return rgba -class Escenario(gtk.DrawingArea): +class Escenario(Gtk.DrawingArea): __gsignals__ = { - "new-size": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )), - "mouse-enter": (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, (gobject.TYPE_BOOLEAN, ))} + "new-size": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_PYOBJECT, )), + "mouse-enter": (GObject.SignalFlags.RUN_LAST, + None, (GObject.TYPE_BOOLEAN, ))} def __init__(self): - gtk.DrawingArea.__init__(self) + GObject.GObject.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#000000")) + self.override_background_color(Gtk.StateType.NORMAL, color_parser("#000000")) - self.set_events(gtk.gdk.EXPOSE | - #gtk.gdk.KEY_PRESS | gtk.gdk.KEY_RELEASE | - #gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.KEY_PRESS_MASK | - gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.POINTER_MOTION_HINT_MASK | - gtk.gdk.BUTTON_MOTION_MASK | gtk.gdk.BUTTON_PRESS_MASK | - gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.LEAVE_NOTIFY_MASK - | gtk.gdk.ENTER_NOTIFY_MASK) + self.set_events(Gdk.EventType.EXPOSE | + #Gdk.KEY_PRESS | Gdk.KEY_RELEASE | + #Gdk.EventMask.KEY_RELEASE_MASK | Gdk.EventMask.KEY_PRESS_MASK | + Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK | + Gdk.EventMask.BUTTON_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | + Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK + | Gdk.EventMask.ENTER_NOTIFY_MASK) self.connect("size-allocate", self.__size_request) - self.connect("expose-event", self.__redraw) + self.connect("draw", self.__redraw) self.connect("button_press_event", self.__button_press_event) self.connect("button_release_event", self.__button_release_event) diff --git a/setup.py b/setup.py index fe56917..654c42d 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from sugar.activity import bundlebuilder +from sugar3.activity import bundlebuilder bundlebuilder.start() From 2fde972a990df08e92f1ea264a5f596e98261e5c Mon Sep 17 00:00:00 2001 From: tonadev Date: Thu, 1 Nov 2018 20:16:42 -0600 Subject: [PATCH 2/3] Change callback name of draw signal to _draw_cb to be consistent --- CantaBichos/CantaBichos.py | 5 +++-- CucaraSims/JAMediaImagenes/ImagePlayer.py | 4 ++-- OjosCompuestos/JAMediaImagenes/ImagePlayer.py | 4 ++-- Widgets.py | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CantaBichos/CantaBichos.py b/CantaBichos/CantaBichos.py index 32c02ee..662beae 100644 --- a/CantaBichos/CantaBichos.py +++ b/CantaBichos/CantaBichos.py @@ -90,7 +90,7 @@ def __init__(self, image_path): boton.set_icon_widget(self.imagen) boton.connect("size-allocate", self.__size_request) - boton.connect("draw", self.__redraw) + boton.connect("draw", self.__draw_cb) boton.connect("clicked", self.__clicked) self.add(boton) @@ -134,7 +134,7 @@ def __size_request(self, widget, event): GdkPixbuf.Pixbuf.new_from_file_at_size( self.image_path, rect.width, -1)) - def __redraw(self, widget, event): + def __draw_cb(self, widget, event): rect = self.get_allocation() GObject.idle_add(self.imagen.set_from_pixbuf, GdkPixbuf.Pixbuf.new_from_file_at_size( @@ -151,6 +151,7 @@ def __init__(self, parent=None, text=""): GObject.GObject.__init__(self, parent=parent) self.set_decorated(False) + self.set_transient_for(parent) self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff")) self.set_border_width(15) diff --git a/CucaraSims/JAMediaImagenes/ImagePlayer.py b/CucaraSims/JAMediaImagenes/ImagePlayer.py index 9b8621f..e15466d 100644 --- a/CucaraSims/JAMediaImagenes/ImagePlayer.py +++ b/CucaraSims/JAMediaImagenes/ImagePlayer.py @@ -28,9 +28,9 @@ def __init__(self, ventana): self.xid = self.ventana.get_property('window').get_xid() self.player = PlayerBin(self.xid, self.width, self.height) - self.ventana.connect("draw", self.__set_size) + self.ventana.connect("draw", self.__draw_cb) - def __set_size(self, widget, event): + def __draw_cb(self, widget, event): rect = self.ventana.get_allocation() self.width = rect.width self.height = rect.height diff --git a/OjosCompuestos/JAMediaImagenes/ImagePlayer.py b/OjosCompuestos/JAMediaImagenes/ImagePlayer.py index a1edc9b..bfb1cd3 100644 --- a/OjosCompuestos/JAMediaImagenes/ImagePlayer.py +++ b/OjosCompuestos/JAMediaImagenes/ImagePlayer.py @@ -28,9 +28,9 @@ def __init__(self, ventana): self.xid = self.ventana.get_property('window').get_xid self.player = PlayerBin(self.xid, self.width, self.height) - self.ventana.connect("draw", self.__set_size) + self.ventana.connect("draw", self.__draw_cb) - def __set_size(self, widget, event): + def __draw_cb(self, widget, event): rect = self.ventana.get_allocation() self.width = rect.width self.height = rect.height diff --git a/Widgets.py b/Widgets.py index 527c8d3..4b9eb6f 100644 --- a/Widgets.py +++ b/Widgets.py @@ -37,7 +37,7 @@ def __init__(self): | Gdk.EventMask.ENTER_NOTIFY_MASK) self.connect("size-allocate", self.__size_request) - self.connect("draw", self.__redraw) + self.connect("draw", self.__draw_cb) self.connect("button_press_event", self.__button_press_event) self.connect("button_release_event", self.__button_release_event) @@ -100,6 +100,6 @@ def __size_request(self, widget, event): rect = self.get_allocation() self.emit("new-size", (rect.width, rect.height)) - def __redraw(self, widget, event): + def __draw_cb(self, widget, event): rect = self.get_allocation() self.emit("new-size", (rect.width, rect.height)) From bbfd6befec0b0fb2ff2929668e4d49c1a204ee85 Mon Sep 17 00:00:00 2001 From: tonadev Date: Fri, 2 Nov 2018 16:25:57 -0600 Subject: [PATCH 3/3] Add missing parentheses when calling some get_xid() method --- Main.py | 4 ++-- OjosCompuestos/JAMediaImagenes/ImagePlayer.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Main.py b/Main.py index a2fc222..d2a44e3 100644 --- a/Main.py +++ b/Main.py @@ -71,7 +71,7 @@ def __redraw(self, widget, size): self.juego.escalar(size) def __run_intro(self, escenario): - xid = escenario.get_property('window').get_xid + xid = escenario.get_property('window').get_xid() os.putenv('SDL_WINDOWID', str(xid)) self.juego = Intro() self.juego.connect("exit", self.__salir) @@ -81,7 +81,7 @@ def __run_intro(self, escenario): return False def __run_cucarasims(self, escenario): - xid = escenario.get_property('window').get_xid + xid = escenario.get_property('window').get_xid() os.putenv('SDL_WINDOWID', str(xid)) self.juego = CucaraSims() self.widgetjuego.connect("set-cursor", self.juego.set_cursor) diff --git a/OjosCompuestos/JAMediaImagenes/ImagePlayer.py b/OjosCompuestos/JAMediaImagenes/ImagePlayer.py index bfb1cd3..e15466d 100644 --- a/OjosCompuestos/JAMediaImagenes/ImagePlayer.py +++ b/OjosCompuestos/JAMediaImagenes/ImagePlayer.py @@ -25,7 +25,7 @@ def __init__(self, ventana): self.width = rect.width self.height = rect.height - self.xid = self.ventana.get_property('window').get_xid + self.xid = self.ventana.get_property('window').get_xid() self.player = PlayerBin(self.xid, self.width, self.height) self.ventana.connect("draw", self.__draw_cb)