Skip to content

Commit

Permalink
Port to GTK3, Sugar-Toolkit3
Browse files Browse the repository at this point in the history
Also,
 - Upgrade sugargame to v1.2
 - Add ToolbarBox
 - Minor fixes
  • Loading branch information
Pro-Panda authored and quozl committed Feb 27, 2018
1 parent 62457f7 commit 5de78ba
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 194 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
iknowMadagascar
===============

A sugar game about he geography of Madagascar
A sugar game about the geography of Madagascar
48 changes: 39 additions & 9 deletions activity.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sugargame
import sugargame.canvas
from sugar.activity import activity
from gettext import gettext as _

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk


from sugar3.activity import activity
from sugar3.graphics.toolbarbox import ToolbarBox
from sugar3.activity.widgets import ActivityToolbarButton, StopButton

import pygame
import sugargame.canvas
import conozco

class Activity(activity.Activity):

def __init__(self, handle):
activity.Activity.__init__(self, handle)

self.max_participants = 1
self.actividad = conozco.Conozco(self)
self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
self.set_canvas(self._pygamecanvas)
self._pygamecanvas.grab_focus()
self._pygamecanvas.run_pygame(self.actividad.principal)

toolbox = ToolbarBox()

activity_button = ActivityToolbarButton(self)
toolbox.toolbar.insert(activity_button, 0)
activity_button.show()

separator = Gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbox.toolbar.insert(separator, -1)
separator.show()

stop_button = StopButton(self)
stop_button.props.accelerator = _('<Ctrl>Q')
toolbox.toolbar.insert(stop_button, -1)
stop_button.show()

toolbox.show()
self.set_toolbar_box(toolbox)
self.show_all()

self.game = conozco.Conozco(self)
self.game.canvas = sugargame.canvas.PygameCanvas(self,
main=self.game.run,
modules=[pygame.display, pygame.font, pygame.mixer])
self.set_canvas(self.game.canvas)
self.game.canvas.grab_focus()
3 changes: 2 additions & 1 deletion activity/activity.info
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ activity_version = 4
bundle_id = org.ceibaljam.conozcomadagascar
icon = madagascar
exec = sugar-activity activity.Activity
license = GPLv3
license = GPL-3.0+
summary = Game about the geography of Madagascar
repository = https://github.com/sugarlabs/iknowMadagascar.git
94 changes: 46 additions & 48 deletions conozco.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,19 @@
# Ceibal Jam http://ceibaljam.org

import os
import sys
import random
import pygame
import time
import imp
import gettext
import logging
import ConfigParser
import gettext
from gettext import gettext as _

gtk_present = True
try:
import gtk
except:
gtk_present = False
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from sugar3.graphics.style import GRID_CELL_SIZE

# constantes
RADIO = 10
Expand Down Expand Up @@ -260,7 +259,7 @@ def loadInfo(self):
try:
f = imp.load_source(self.directorio, a_path)
except:
print _('Cannot open %s') % self.directorio
logging.debug(_('Cannot open %s') % self.directorio)

if f:
lugares = []
Expand Down Expand Up @@ -370,7 +369,7 @@ def cargarListaDirectorios(self):
try:
f = imp.load_source(d, a_path)
except:
print _('Cannot open %s') % d
logging.debug( _('Cannot open %s') % d)

if hasattr(f, 'NAME'):
name = unicode(f.NAME, 'UTF-8')
Expand All @@ -395,7 +394,7 @@ def loadCommons(self):
try:
f = imp.load_source('commons', a_path)
except:
print _('Cannot open %s') % 'commons'
logging.debug( _('Cannot open %s') % 'commons')

if f:
if hasattr(f, 'ACTIVITY_NAME'):
Expand Down Expand Up @@ -451,7 +450,7 @@ def cargarNiveles(self):
try:
f = imp.load_source(ARCHIVONIVELES, a_path)
except:
print _('Cannot open %s') % ARCHIVONIVELES
logging.debug( _('Cannot open %s') % ARCHIVONIVELES)

if hasattr(f, 'LEVELS'):
for ln in f.LEVELS:
Expand Down Expand Up @@ -532,7 +531,7 @@ def cargarExploraciones(self):
try:
f = imp.load_source(ARCHIVOEXPLORACIONES, a_path)
except:
print _('Cannot open %s') % ARCHIVOEXPLORACIONES
logging.debug( _('Cannot open %s') % ARCHIVOEXPLORACIONES)

if hasattr(f, 'EXPLORATIONS'):
for e in f.EXPLORATIONS:
Expand Down Expand Up @@ -587,10 +586,9 @@ def pantallaAcercaDe(self):
int(800*scale+shift_y)),
COLOR_SKIP)
pygame.display.flip()
while 1:
if gtk_present:
while gtk.events_pending():
gtk.main_iteration()
while True:
while Gtk.events_pending():
Gtk.main_iteration()

for event in wait_events():
if event.type == pygame.KEYDOWN or \
Expand Down Expand Up @@ -664,10 +662,9 @@ def pantallaStats(self):
COLOR_SKIP)

pygame.display.flip()
while 1:
if gtk_present:
while gtk.events_pending():
gtk.main_iteration()
while True:
while Gtk.events_pending():
Gtk.main_iteration()

for event in wait_events():
if event.type == pygame.KEYDOWN or \
Expand Down Expand Up @@ -751,10 +748,9 @@ def pantallaInicial(self):
(int(1005*scale+shift_x),int(825*scale+shift_y)),
COLOR_BUTTON_T)
pygame.display.flip()
while 1:
if gtk_present:
while gtk.events_pending():
gtk.main_iteration()
while True:
while Gtk.events_pending():
Gtk.main_iteration()

for event in wait_events():
if event.type == pygame.KEYDOWN:
Expand Down Expand Up @@ -816,7 +812,7 @@ def pantallaDirectorios(self):
COLOR_OPTION_T)
nDirectorios = len(self.listaNombreDirectorios)
paginaDirectorios = self.paginaDir
while 1:
while True:
yLista = int(200*scale+shift_y)
self.pantalla.fill(COLOR_FONDO,
(int(shift_x),yLista-int(24*scale),
Expand Down Expand Up @@ -913,17 +909,16 @@ def pantallaDirectorios(self):
pygame.display.flip()
cambiarPagina = False
while not cambiarPagina:
if gtk_present:
while gtk.events_pending():
gtk.main_iteration()
while Gtk.events_pending():
Gtk.main_iteration()

for event in wait_events():
if event.type == pygame.KEYDOWN:
if event.key == 27: # escape: salir
if self.sound:
self.click.play()
self.save_stats()
sys.exit()
pygame.quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if self.sound:
self.click.play()
Expand Down Expand Up @@ -983,7 +978,7 @@ def pantallaDirectorios(self):
elif pos[0] > 820*scale+shift_x and \
pos[0] < 1190*scale+shift_x:
self.save_stats()
sys.exit() # exit
pygame.quit()
elif event.type == EVENTOREFRESCO:
pygame.display.flip()

Expand Down Expand Up @@ -1014,8 +1009,6 @@ def __init__(self, parent=None):
path = os.path.abspath('locale')
gettext.bindtextdomain(bundle_id, path)
gettext.textdomain(bundle_id)
global _
_ = gettext.gettext
# initial time
self._init_time = time.time()
# stats
Expand Down Expand Up @@ -1043,7 +1036,7 @@ def load_stats(self):
l[i] = int(val)
f.close()
except Exception, err:
print 'Cannot load stats', err
logging.debug( 'Cannot load stats' + str(err))
return
if self._validate_stats(l):
self._score = l[0]
Expand Down Expand Up @@ -1086,7 +1079,7 @@ def save_stats(self):
f.write(str(l[i]) + '\n')
f.close()
except Exception, err:
print 'Error saving stats', err
logging.debug( 'Error saving stats' + str(err))

def loadAll(self):
global scale, shift_x, shift_y, xo_resolution
Expand Down Expand Up @@ -1465,10 +1458,9 @@ def explorarNombres(self):
COLOR_SKIP)
pygame.display.flip()
# lazo principal de espera por acciones del usuario
while 1:
if gtk_present:
while gtk.events_pending():
gtk.main_iteration()
while True:
while Gtk.events_pending():
Gtk.main_iteration()

for event in wait_events():
if event.type == pygame.KEYDOWN:
Expand Down Expand Up @@ -1645,10 +1637,9 @@ def jugarNivel(self):
self.avanceNivel = 0
pygame.time.set_timer(EVENTORESPUESTA,0)
# leer eventos y ver si la respuesta es correcta
while 1:
if gtk_present:
while gtk.events_pending():
gtk.main_iteration()
while True:
while Gtk.events_pending():
Gtk.main_iteration()

for event in wait_events():
if event.type == pygame.KEYDOWN:
Expand Down Expand Up @@ -1854,25 +1845,32 @@ def jugarNivel(self):
pass
pygame.display.flip()

def principal(self):
def run(self):
"""Este es el loop principal del juego"""
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
elif event.type == pygame.VIDEORESIZE:
pygame.display.set_mode(
(event.size[0], event.size[1] - GRID_CELL_SIZE),
pygame.RESIZABLE)
break

pygame.time.set_timer(EVENTOREFRESCO,TIEMPOREFRESCO)

self.loadAll()

self.loadCommons()

self.load_stats()

self.paginaDir = 0
while 1:
while True:
self.pantallaDirectorios() # seleccion de mapa
pygame.mouse.set_cursor((32,32), (1,1), *self.cursor_espera)
self.directorio = self.listaDirectorios\
[self.indiceDirectorioActual]
self.cargarDirectorio()
pygame.mouse.set_cursor((32,32), (1,1), *self.cursor)
while 1:
while True:
# pantalla inicial de juego
self.elegir_directorio = False
self.pantallaInicial()
Expand Down Expand Up @@ -1914,7 +1912,7 @@ def principal(self):

def main():
juego = Conozco()
juego.principal()
juego.run()

if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-

from sugar.activity import bundlebuilder
from sugar3.activity import bundlebuilder
if __name__ == "__main__":
bundlebuilder.start()
2 changes: 1 addition & 1 deletion sugargame/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.1'
__version__ = '1.2'
Loading

0 comments on commit 5de78ba

Please sign in to comment.