Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Gtk3 #5

Merged
merged 3 commits into from
Nov 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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