-
Notifications
You must be signed in to change notification settings - Fork 0
/
rawtemplate.py
205 lines (175 loc) · 7.58 KB
/
rawtemplate.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
TemplateString = \
'''
# -*- coding: utf-8 -*-
# Copyright (c) %(year)s %(dev_name)s %(dev_email)s
#
# %(name)s.py
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 3 of the GNU General Public License
# as published by the Free Software Foundation. A copy of this license should
# be included in the file GPL-3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#create logger, logger was setup in SPLogging
import logging
# In your Activity class ->
# self.logger = logging.getLogger("schoolsplay.%(name)s.Activity")
# self.logger.error("I don't understand logger")
# See SP manual for more info
module_logger = logging.getLogger("schoolsplay.%(name)s")
# standard modules you probably need
import os,sys
import pygame
from pygame.constants import *
import utils
from SPConstants import *
import SPSpriteUtils
class Activity:
""" Base class mandatory for any SP activty.
The activity is started by instancing this class by the core.
This class must at least provide the following methods.
start (self) called by the core before calling 'next_level'.
post_next_level (self) called once by the core after 'next_level' *and* after the 321 count.
next_level (self,level) called by the core when the user changes levels.
loop (self,events) called 40 times a second by the core and should be your
main eventloop.
get_helptitle (self) must return the title of the game can be localized.
get_help (self) must return a list of strings describing the activty.
get_helptip (self) must return a list of strings or an empty list
get_name (self) must provide the activty name in english, not localized in lowercase.
stop_timer (self) must stop any timers if any.
"""
def __init__(self,SPGoodies):
"""SPGoodies is a class object that SP sets up and will contain references
to objects, callback methods and observers
TODO: add more explaination"""
self.logger = logging.getLogger("schoolsplay.%(name)s.Activity")
self.logger.info("Activity started")
self.SPG = SPGoodies
self.lang = self.SPG.get_localesetting()[0][:2]
self.scoredisplay = self.SPG.get_scoredisplay()
self.theme = self.SPG.get_theme()
self.screen = self.SPG.get_screen()
self.screenclip = self.SPG.get_screenclip()
self.blit_pos = self.screenclip.left, self.screenclip.top
self.orgscreen = pygame.Surface(self.screenclip.size) # we use this to restore the screen
self.orgscreen.blit(self.screen, (0, 0), self.screenclip)
self.backgr = self.SPG.get_background()
# The location of the activities Data dir
self.my_datadir = os.path.join(self.SPG.get_libdir_path(),'CPData','%(datadirname)s')
# Location of the CPData dir which holds some stuff used by multiple activities
self.CPdatadir = os.path.join(self.SPG.get_libdir_path(),'CPData')
# Location of the alphabet sounds dir
self.absdir = self.SPG.get_absdir_path()# alphabet sounds dir
self.rchash = utils.read_rcfile(os.path.join(self.my_datadir, '%(name)s.rc'))
self.logger.debug("rchash: " + str(self.rchash))
# You MUST call SPInit BEFORE using any of the SpriteUtils stuff
# it returns a reference to the special CPGroup
self.actives = SPSpriteUtils.SPInit(self.screen,self.backgr)
# Remove these four lines
text = "Template activity for " + self.get_helptitle()
surf = utils.char2surf(text,24,RED)
self.screen.blit(surf,(20,200))
pygame.display.flip()
def clear_screen(self):
self.screen.blit(self.orgscreen,self.blit_pos)
self.backgr.blit(self.orgscreen,self.blit_pos)
pygame.display.update()
def refresh_sprites(self):
"""Mandatory method, called by the core when the screen is used for blitting
and the possibility exists that your sprites are affected by it."""
self.actives.refresh()
def get_helptitle(self):
"""Mandatory method"""
return _("%(Name)s")
def get_name(self):
"""Mandatory method, returnt string must be in lowercase."""
return "%(name)s"
def get_help(self):
"""Mandatory methods"""
text = [_("The aim of this activity:"),
" ",
_("Number of levels : 5"),
" "]
return text
def get_helptip(self):
"""Mandatory method, when no tips available returns an empty list"""
return []
def get_helptype(self):
"""Mandatory method, you must set an type"""
# Possible types are: Memory, Math, Puzzle, Keyboardtraining, Mousetraining
# Language, Alphabet, Fun, Miscellaneous
return _("Miscellaneous")
def start(self):
"""Mandatory method."""
pass
@splitpoint@
def dailytraining_pre_level(self, level):
"""Mandatory method"""
pass
def dailytraining_next_level(self, level, dbmapper):
"""Mandatory method.
This should handle the DT logic"""
pass
return True
def post_next_level(self):
"""Mandatory method.
This is called once by the core after 'next_level' *and* after the 321 count.
You should place stuff in here that run in a seperate thread like sound play."""
pass
def get_score(self,timespend):
"""Mandatory method.
@timespend is the time spend inside the level as it's calculated
by the core.
returns the score value for the past level.
return None if no score value is used"""
m,s = timespend.split(':')
seconds = int(m)*60 + int(s)
def stop_timer(self):
"""You *must* provide a method to stop timers if you use them.
The SPC will call this just in case and catch the exception in case
there's no 'stop_timer' method"""
try:
self.timer.stop()
except:
pass
def loop(self,events):
"""Mandatory method.
This is the main eventloop called by the core 30 times a minute."""
for event in events:
if event.type is MOUSEBUTTONDOWN:
pass
# call your objects
return
'''
KludgeString =\
'''
def get_helplevels(self):
"""Mandatory method, must return a string with the number of levels
in the follwing format:
_("This level has %s levels") % number-of-levels"""
return _("This activity has %s levels") % 6
def pre_level(self,level):
"""Mandatory method.
Return True to call the eventloop after this method is called."""
self.logger.debug("pre_level called with: %s" % level)
pass
def next_level(self,level,dbmapper):
"""Mandatory method.
Return True if there levels left.
False when no more levels left."""
self.logger.debug("nextlevel called with: %s" % level)
# Your top blit position, this depends on the menubar position
if self.blit_pos[1] == 0:
y = 10
else:
y = 110
return True
'''