Skip to content

Commit

Permalink
Stop the activity with stop button
Browse files Browse the repository at this point in the history
The activity does not stop running. Confirmed by executing it from terminal with sugar-activity3
To reproduce - Choose a game of 2 or 3 or 4 players from crazyeights box. Now click the stop button. The activity doen't stop execution.
  • Loading branch information
JuiP committed Jul 26, 2020
1 parent 8c6e74b commit 9ebc08d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def build_toolbar(self):
stop_button = StopButton(self)
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
stop_button.connect('clicked', self._stop_cb)

self.show_all()

Expand Down Expand Up @@ -94,3 +95,6 @@ def load_image_from_journal(self):
del chooser

return jobject

def _stop_cb(self, button):
self.game.running = False
10 changes: 8 additions & 2 deletions crazyeights.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import fiftytwo
from fiftytwo import card_width, card_height, UP, DOWN
import math, random
import sys
import pygame
from pygame.locals import *

Expand Down Expand Up @@ -252,6 +253,7 @@ def special_cards(deck, discard, players, whosturn, cardprocessed, choosesuitima
return cardprocessed, whosturn, currentsuit

def main(playertypes, screensize):
running = True
sw = screensize[0]
sh = screensize[1]

Expand Down Expand Up @@ -345,7 +347,7 @@ def main(playertypes, screensize):

screen.fill(BGCOL)

while 1:
while running:
fpslimiter.tick(20)

# Check for win
Expand Down Expand Up @@ -399,6 +401,9 @@ def main(playertypes, screensize):
while Gtk.events_pending():
Gtk.main_iteration()

if not running:
break

for event in pygame.event.get():

if event.type == KEYDOWN:
Expand Down Expand Up @@ -437,7 +442,8 @@ def main(playertypes, screensize):
whosturn = end_turn(players, whosturn)

elif event.type == QUIT:
return
running = False
return running

"""elif event.type == olpcgames.CONNECT:
print "Connect event."
Expand Down
17 changes: 12 additions & 5 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def __init__(self, parent):
pass

def run(self):
self.running = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
return
elif event.type == pygame.VIDEORESIZE:
pygame.display.set_mode(
Expand Down Expand Up @@ -116,31 +118,36 @@ def run(self):

fpslimiter = pygame.time.Clock()

while True:
while self.running:
fpslimiter.tick(20)

while Gtk.events_pending():
Gtk.main_iteration()
if not self.running:
break

for event in pygame.event.get():

if event.type == pygame.MOUSEMOTION:
if event.type == pygame.QUIT:
self.running = False
return
elif event.type == pygame.MOUSEMOTION:
mouseposition[0] = event.pos[0]
mouseposition[1] = event.pos[1]
elif event.type == pygame.MOUSEBUTTONDOWN:
mouseposition[2] = 1
elif event.type == pygame.MOUSEBUTTONUP:
mouseposition[2] = 0
if not decksel and c8s2p.detect_click(event.pos):
crazyeights.main((names[4], names[0]), screensize)
self.running = crazyeights.main((names[4], names[0]), screensize)
self.screen.fill(MMCOL)
pygame.event.set_allowed(pygame.MOUSEMOTION)
elif not decksel and c8s3p.detect_click(event.pos):
crazyeights.main((names[1], names[2], names[0]), screensize)
self.running = crazyeights.main((names[1], names[2], names[0]), screensize)
self.screen.fill(MMCOL)
pygame.event.set_allowed(pygame.MOUSEMOTION)
elif not decksel and c8s4p.detect_click(event.pos):
crazyeights.main((names[1], names[2], names[0], names[3]), screensize)
self.running = crazyeights.main((names[1], names[2], names[0], names[3]), screensize)
self.screen.fill(MMCOL)
pygame.event.set_allowed(pygame.MOUSEMOTION)
elif not decksel and maindeck.detect_click(event.pos):
Expand Down

0 comments on commit 9ebc08d

Please sign in to comment.