This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.py
executable file
·55 lines (46 loc) · 1.59 KB
/
activity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from gettext import gettext as _
import gtk
import pygame
from sugar.activity import activity
from sugar.graphics.toolbutton import ToolButton
import gobject
import sugargame.canvas
import Tessellations
class PeterActivity(activity.Activity):
def __init__(self, handle):
super(PeterActivity, self).__init__(handle)
# Build the activity toolbar.
toolbox = activity.ActivityToolbox(self)
activity_toolbar = toolbox.get_activity_toolbar()
activity_toolbar.keep.props.visible = False
activity_toolbar.share.props.visible = False
toolbox.show()
self.set_toolbox(toolbox)
# Create the game instance.
self.game = Tessellations.Tessellations()
# Build the Pygame canvas.
self._pygamecanvas = \
sugargame.canvas.PygameCanvas(self)
# Note that set_canvas implicitly calls
# read_file when resuming from the Journal.
self.set_canvas(self._pygamecanvas)
# Start the game running.
self._pygamecanvas.run_pygame(self.game.run)
def read_file(self, file_path):
try:
f = open(file_path, "r")
except:
return #****
try:
self.game.tess_n=int(f.readline())
self.game.max_n=int(f.readline())
except:
pass
f.close()
def write_file(self, file_path):
f = open(file_path, 'wb')
try:
f.write(str(self.game.tess_n)+'\n')
f.write(str(self.game.max_n)+'\n')
finally:
f.close()