Skip to content

Commit

Permalink
Port GObject based methods to GLib
Browse files Browse the repository at this point in the history
  • Loading branch information
tonadev committed Nov 4, 2018
1 parent becbbe1 commit 18aa838
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 26 deletions.
9 changes: 5 additions & 4 deletions CantaBichos/CantaBichos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
from gi.repository import GLib
from gi.repository import GObject

from player import Player
Expand Down Expand Up @@ -45,7 +46,7 @@ def __init__(self):
self.show_all()

def __realize(self, widget):
GObject.idle_add(self.__dialog_run)
GLib.idle_add(self.__dialog_run)

def __dialog_run(self):
dialog = Dialog(parent=self.get_toplevel(),
Expand Down Expand Up @@ -130,13 +131,13 @@ def __clicked(self, widget):

def __size_request(self, widget, event):
rect = self.get_allocation()
GObject.idle_add(self.imagen.set_from_pixbuf,
GLib.idle_add(self.imagen.set_from_pixbuf,
GdkPixbuf.Pixbuf.new_from_file_at_size(
self.image_path, rect.width, -1))

def __draw_cb(self, widget, event):
rect = self.get_allocation()
GObject.idle_add(self.imagen.set_from_pixbuf,
GLib.idle_add(self.imagen.set_from_pixbuf,
GdkPixbuf.Pixbuf.new_from_file_at_size(
self.image_path, rect.width, -1))

Expand All @@ -160,4 +161,4 @@ def __init__(self, parent=None, text=""):
self.vbox.pack_start(label, True, True, 0)
self.vbox.show_all()

GObject.timeout_add(3000, self.destroy)
GLib.timeout_add(3000, self.destroy)
3 changes: 2 additions & 1 deletion CantaBichos/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import os
import gi
gi.require_version('Gst', '1.0')
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gst

GObject.threads_init()
GLib.threads_init()
Gst.init(None)


Expand Down
3 changes: 2 additions & 1 deletion CucaraSims/CucaraSims.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
from gi.repository import GLib
from gi.repository import GObject

from Widgets import Widget_Leccion
Expand Down Expand Up @@ -59,7 +60,7 @@ def __init__(self, escenario):
self.cursor_root = False
self.cursor_tipo = False

GObject.idle_add(self.__config_cursors)
GLib.idle_add(self.__config_cursors)

def __volumen_changed(self, widget, valor):
self.emit('volumen', valor)
Expand Down
4 changes: 2 additions & 2 deletions CucaraSims/JAMediaReproductor/JAMediaBins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# Uruguay

from gi.repository import Gst
from gi.repository import GObject
from gi.repository import GLib

GObject.threads_init()
GLib.threads_init()


class JAMedia_Audio_Pipeline(Gst.Pipeline):
Expand Down
7 changes: 4 additions & 3 deletions CucaraSims/JAMediaReproductor/JAMediaReproductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Uruguay

import os
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gst

Expand All @@ -14,7 +15,7 @@

PR = False

GObject.threads_init()
GLib.threads_init()


class JAMediaReproductor(GObject.GObject):
Expand Down Expand Up @@ -140,11 +141,11 @@ def __pause(self):

def __new_handle(self, reset):
if self.actualizador:
GObject.source_remove(self.actualizador)
GLib.source_remove(self.actualizador)
self.actualizador = False

if reset:
self.actualizador = GObject.timeout_add(500, self.__handle)
self.actualizador = GLib.timeout_add(500, self.__handle)

def __handle(self):
if not self.progressbar:
Expand Down
3 changes: 2 additions & 1 deletion CucaraSims/Juego.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Uruguay

import os
from gi.repository import GLib
from gi.repository import GObject
import pygame
from gi.repository import Gtk
Expand All @@ -27,7 +28,7 @@
BASE_PATH = os.path.dirname(BASE_PATH)
OLPC = 'olpc' in platform.platform()

GObject.threads_init()
GLib.threads_init()


class CucaraSims(GObject.GObject):
Expand Down
5 changes: 3 additions & 2 deletions CucaraSims/Timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Uruguay

import time
from gi.repository import GLib
from gi.repository import GObject


Expand Down Expand Up @@ -49,10 +50,10 @@ def __handle(self):

def new_handle(self, reset):
if self.actualizador:
GObject.source_remove(self.actualizador)
GLib.source_remove(self.actualizador)
self.actualizador = False
if reset:
self.actualizador = GObject.timeout_add(1000, self.__handle)
self.actualizador = GLib.timeout_add(1000, self.__handle)

def salir(self):
self.new_handle(False)
3 changes: 2 additions & 1 deletion CucaraSims/Widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import GdkPixbuf
import pygame
Expand Down Expand Up @@ -140,7 +141,7 @@ def __realize(self, widget):
self.player = ImagePlayer(self)
elif 'video' in tipo or 'application/ogg':
self.player = JAMediaReproductor(self.get_property('window').get_xid())
GObject.idle_add(self.player.load, self.archivo)
GLib.idle_add(self.player.load, self.archivo)


class Cursor(Sprite):
Expand Down
5 changes: 3 additions & 2 deletions Intro/Intro.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os
from gi.repository import GObject
from gi.repository import GLib
import pygame
from gi.repository import Gtk
import platform
Expand All @@ -17,7 +18,7 @@
BASE_PATH = os.path.dirname(BASE_PATH)
OLPC = 'olpc' in platform.platform()

GObject.threads_init()
GLib.threads_init()


class Intro(GObject.GObject):
Expand Down Expand Up @@ -78,7 +79,7 @@ def run(self):
while Gtk.events_pending():
Gtk.main_iteration()
if len(self.sprites.sprites()) < 5:
GObject.idle_add(self.sprites.add,
GLib.idle_add(self.sprites.add,
Bicho(RESOLUCION_INICIAL[0],
RESOLUCION_INICIAL[1]))
self.sprites.clear(self.ventana, self.escenario)
Expand Down
5 changes: 3 additions & 2 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import sys
from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import GObject

from EventTraductor.EventTraductor import KeyPressTraduce
Expand Down Expand Up @@ -148,7 +149,7 @@ def switch(self, widget, valor):
self.widgetjuego = Escenario()
self.widgetjuego.connect("new-size", self.__redraw)
self.add(self.widgetjuego)
GObject.idle_add(self.__run_intro, self.widgetjuego)
GLib.idle_add(self.__run_intro, self.widgetjuego)

elif valor == 2:
self.override_background_color3(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff"))
Expand All @@ -159,7 +160,7 @@ def switch(self, widget, valor):
escenario.connect("mouse-enter", self.__mouse_enter)
self.widgetjuego = CucaraSimsWidget(escenario)
self.add(self.widgetjuego)
GObject.idle_add(self.__run_cucarasims, escenario)
GLib.idle_add(self.__run_cucarasims, escenario)

elif valor == 3:
self.override_background_color(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff"))
Expand Down
5 changes: 3 additions & 2 deletions OjosCompuestos/OjosCompuestos.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import GObject
from PlayerList import PlayerList
from JAMediaImagenes.ImagePlayer import ImagePlayer
Expand Down Expand Up @@ -42,7 +43,7 @@ def __init__(self, pantalla):
self.show_all()

def __load_imagenes(self, widget):
GObject.idle_add(self.__run)
GLib.idle_add(self.__run)

def __run(self):
self.player = ImagePlayer(self.pantalla)
Expand Down Expand Up @@ -79,4 +80,4 @@ def __init__(self, parent=None, text=""):
self.vbox.pack_start(label, True, True, 0)
self.vbox.show_all()

GObject.timeout_add(3000, self.destroy)
GLib.timeout_add(3000, self.destroy)
7 changes: 4 additions & 3 deletions OjosCompuestos/PlayerList.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GdkPixbuf
from gi.repository import GLib
from gi.repository import GObject

def color_parser(color):
Expand Down Expand Up @@ -143,7 +144,7 @@ def __selecciones(self, selection, model, path, is_selected, user_data):
if self.valor_select != valor:
self.valor_select = valor

GObject.timeout_add(3, self.__select,
GLib.timeout_add(3, self.__select,
self.get_model().get_path(_iter))

return True
Expand Down Expand Up @@ -195,7 +196,7 @@ def __ejecutar_agregar_elemento(self, elementos):

self.get_model().append([pixbuf, texto, path])
elementos.remove(elementos[0])
GObject.idle_add(self.__ejecutar_agregar_elemento, elementos)
GLib.idle_add(self.__ejecutar_agregar_elemento, elementos)
return False

def limpiar(self):
Expand All @@ -212,7 +213,7 @@ def agregar_items(self, elementos):
"""
self.get_toplevel().set_sensitive(False)
self.permitir_select = False
GObject.idle_add(self.__ejecutar_agregar_elemento, elementos)
GLib.idle_add(self.__ejecutar_agregar_elemento, elementos)

def seleccionar_siguiente(self, widget=None):
modelo, _iter = self.get_selection().get_selected()
Expand Down
5 changes: 3 additions & 2 deletions SugarBichos.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GLib
from gi.repository import GObject
from gi.repository import Gdk

Expand Down Expand Up @@ -164,7 +165,7 @@ def switch(self, widget, valor):
self.widgetjuego = Escenario()
self.widgetjuego.connect("new-size", self.__redraw)
self.add(self.widgetjuego)
GObject.idle_add(self.__run_intro, self.widgetjuego)
GLib.idle_add(self.__run_intro, self.widgetjuego)

elif valor == 2:
self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff"))
Expand All @@ -175,7 +176,7 @@ def switch(self, widget, valor):
escenario.connect("mouse-enter", self.__mouse_enter)
self.widgetjuego = CucaraSimsWidget(escenario)
self.add(self.widgetjuego)
GObject.idle_add(self.__run_cucarasims, escenario)
GLib.idle_add(self.__run_cucarasims, escenario)

elif valor == 3:
self.override_background_color(Gtk.StateType.NORMAL, color_parser("#ffffff"))
Expand Down

0 comments on commit 18aa838

Please sign in to comment.