[Sugar-devel] KukuAnakula: handle quit event

Daniel Drake dsd at laptop.org
Tue Oct 15 14:43:30 EDT 2013


Hi,

We are looking at deploying Kuku Anakula in Nicaragua, thanks for writing
this activity.

One problem is that the stop button doesn't actually cause the process
to terminate. Notably, the music keeps playing and never stops, even though
the activity has disappeared.

Here's a hack patch to make this work. I think the more normal approach
is to write the app more like a state machine, with only one place that
handles and swallows pygame events, leading to just one place where this
event could be neatly handled.

--- kuku.py	2012-05-27 06:21:36.000000000 +0000
+++ /home/olpc/kuku.py	2013-10-15 18:34:17.174872806 +0000
@@ -595,7 +595,9 @@
                 gtk.main_iteration()
             events = pygame.event.get()
             for evt in events:
-                if evt.type == pygame.KEYDOWN:
+                if evt.type == pygame.QUIT:
+                    sys.exit(0)
+                elif evt.type == pygame.KEYDOWN:
                     qa,num_players,score,time_clock = self.game_start(screen,gridsize,font)
                     return (qa,num_players,score,time_clock)
 
@@ -616,7 +618,9 @@
                 gtk.main_iteration()
             events = pygame.event.get()
             for evt in events:
-                if evt.type == pygame.KEYDOWN:
+                if evt.type == pygame.QUIT:
+                    sys.exit(0)
+                elif evt.type == pygame.KEYDOWN:
                     qa,num_players,score,time_clock = self.game_start(screen,gridsize,font,started=1)
                     score.set(state.score)
                     return (qa,num_players,score,time_clock)
@@ -653,7 +657,9 @@
                     gtk.main_iteration()
                 events = pygame.event.get()
                 for evt in events:
-                    if evt.type == pygame.KEYDOWN:
+                    if evt.type == pygame.QUIT:
+                        sys.exit(0)
+                    elif evt.type == pygame.KEYDOWN:
                         qa,num_players,score,time_clock = self.reset_board(screen,gridsize,font)
                         return (qa,num_players,score,time_clock)
         else:
@@ -824,8 +830,9 @@
 
             events = pygame.event.get()
             for evt in events:
-
-                if evt.type == pygame.KEYDOWN:
+                if evt.type == pygame.QUIT:
+                    sys.exit(0)
+                elif evt.type == pygame.KEYDOWN:
                     # elif evt.key == pygame.K_SPACE:
                     if not evt.key in move_keys:
                         x = player.grid_position[0]


More information about the Sugar-devel mailing list