Skip to content

Commit

Permalink
Port to Gtk3
Browse files Browse the repository at this point in the history
  • Loading branch information
tonadev authored and rhl-bthr committed Nov 4, 2018
1 parent 905de66 commit becbbe1
Show file tree
Hide file tree
Showing 20 changed files with 489 additions and 449 deletions.
71 changes: 39 additions & 32 deletions CantaBichos/CantaBichos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(),
Expand All @@ -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)
Expand All @@ -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.__draw_cb)
boton.connect("clicked", self.__clicked)

self.add(boton)
Expand All @@ -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(),
Expand All @@ -116,41 +122,42 @@ 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):
def __draw_cb(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.set_transient_for(parent)
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)
37 changes: 20 additions & 17 deletions CantaBichos/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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:
Expand Down
Loading

0 comments on commit becbbe1

Please sign in to comment.