Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
melody.Gcompris_melody Class Reference

List of all members.

Public Member Functions

def __init__
def start
def end
def ok
def cleanup
def display_current_level
def tried
def ready
def show_bang_stop
def show_bang
def repeat
def repeat_it
def config
def populate
def key_press
def pause
def set_level
def increment_level
def sound_item_event
def sound_play
def switch_item_event
def sound_played
def intro_cb

Public Attributes

 gcomprisBoard
 board_paused
 gamewon
 saved_policy
 timers
 solution
 kidstry
 in_repeat
 theme
 melodylist
 maxtheme
 rootitem
 switch_item
 sound_list
 sound_item
 bang_item
 hitofset_x
 hitofset_y

Detailed Description

The melody activity

Definition at line 33 of file melody.py.


Constructor & Destructor Documentation

def melody.Gcompris_melody.__init__ (   self,
  gcomprisBoard 
)

Definition at line 37 of file melody.py.

00037 
00038   def __init__(self, gcomprisBoard):
00039     self.gcomprisBoard = gcomprisBoard
00040 
00041     self.gcomprisBoard.disable_im_context = True
00042 
00043     #print("Gcompris_melody __init__.")
00044 
00045     # These are used to let us restart only after the bonux is displayed.
00046     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00047     self.board_paused  = 0;
00048     self.gamewon       = 0;
00049 


Member Function Documentation

Definition at line 131 of file melody.py.

00131 
00132   def cleanup(self):
00133 
00134     # Clear all timer
00135     for i in self.timers :
00136       gtk.timeout_remove(i)
00137 
00138     self.timers = []
00139 
00140     self.in_repeat = 0;
00141 
00142     # Remove the root item removes all the others inside it
00143     self.rootitem.destroy()
00144     self.rootitem = None

Here is the caller graph for this function:

Definition at line 273 of file melody.py.

00273 
00274   def config(self):
00275     #print("Gcompris_melody config.")
00276     pass

Definition at line 145 of file melody.py.

00145 
00146   def display_current_level(self):
00147 
00148     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00149                             self.melodylist[self.theme][0]['background'])
00150     gcompris.bar_set_level(self.gcomprisBoard)
00151 
00152     gcompris.sound.policy_set(gcompris.sound.PLAY_AND_INTERRUPT)
00153 
00154     # Create our rootitem. We put each canvas item in it so at the end we
00155     # only have to kill it. The canvas deletes all the items it contains automaticaly.
00156     self.rootitem = self.gcomprisBoard.canvas.root().add(
00157       gnomecanvas.CanvasGroup,
00158       x=0.0,
00159       y=0.0
00160       )
00161 
00162     # Put the theme switcher button
00163     self.switch_item = self.rootitem.add(
00164         gnomecanvas.CanvasPixbuf,
00165         pixbuf = gcompris.utils.load_pixmap("melody/switch.png"),
00166         x=10,
00167         y=10
00168         )
00169     self.switch_item.connect("event", self.switch_item_event)
00170     # This item is clickeable and it must be seen
00171     self.switch_item.connect("event", gcompris.utils.item_event_focus)
00172 
00173 
00174     # Put the sound buttons
00175     self.sound_list = self.melodylist[self.theme][1]
00176 
00177     for i in self.sound_list:
00178       self.sound_item = self.rootitem.add(
00179         gnomecanvas.CanvasPixbuf,
00180         pixbuf = gcompris.utils.load_pixmap(i['image']),
00181         x=i['x'],
00182         y=i['y']
00183         )
00184       self.sound_item.connect("event", self.sound_item_event, i)
00185       # This item is clickeable and it must be seen
00186       self.sound_item.connect("event", gcompris.utils.item_event_focus)
00187 
00188 
00189     self.bang_item = self.rootitem.add(
00190       gnomecanvas.CanvasPixbuf,
00191       pixbuf = gcompris.utils.load_pixmap(self.melodylist[self.theme][0]['hittool']),
00192       x=0,
00193       y=0
00194       )
00195     self.bang_item.hide()
00196 
00197     self.hitofset_x = self.melodylist[self.theme][0]['hitofset_x']
00198     self.hitofset_y = self.melodylist[self.theme][0]['hitofset_y']
00199 
00200     self.populate(self.sound_list)
00201 

Here is the caller graph for this function:

Definition at line 120 of file melody.py.

00120 
00121   def end(self):
00122     self.cleanup()
00123     #print("Gcompris_melody end.")
00124     gcompris.sound.policy_set(self.saved_policy)
00125     gcompris.sound.resume()
00126 

Here is the call graph for this function:

Definition at line 333 of file melody.py.

00333 
00334   def increment_level(self):
00335     self.gcomprisBoard.sublevel += 1
00336 
00337     if(self.gcomprisBoard.sublevel>self.gcomprisBoard.number_of_sublevel):
00338       # Try the next level
00339       self.gcomprisBoard.sublevel=1
00340       self.gcomprisBoard.level += 1
00341       if(self.gcomprisBoard.level>self.gcomprisBoard.maxlevel):
00342         # the current board is finished : bail out
00343         gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
00344         return 0
00345 
00346     return 1
00347 

Here is the caller graph for this function:

def melody.Gcompris_melody.intro_cb (   self,
  file 
)

Definition at line 390 of file melody.py.

00390 
00391   def intro_cb(self, file):
00392     #print "intro passed. go play"
00393     self.pause(0)
00394     self.populate(self.sound_list)

Here is the call graph for this function:

def melody.Gcompris_melody.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 287 of file melody.py.

00287 
00288   def key_press(self, keyval, commit_str, preedit_str):
00289     #print("got key %i" % keyval)
00290     # Play sounds with the keys
00291     if ((keyval == gtk.keysyms.KP_1) or (keyval == gtk.keysyms._1)):
00292       #print "son1"
00293       self.sound_play(self.melodylist[self.theme][1][0])
00294       return True
00295     if ((keyval == gtk.keysyms.KP_2) or (keyval == gtk.keysyms._2)):
00296       #print "son2"
00297       self.sound_play(self.melodylist[self.theme][1][1])
00298       return True
00299     if ((keyval == gtk.keysyms.KP_3) or (keyval == gtk.keysyms._3)):
00300       #print "son3"
00301       self.sound_play(self.melodylist[self.theme][1][2])
00302       return True
00303     if ((keyval == gtk.keysyms.KP_4) or (keyval == gtk.keysyms._4)):
00304       #print "son4"
00305       self.sound_play(self.melodylist[self.theme][1][3])
00306       return True
00307 
00308     return False
00309 

Here is the call graph for this function:

def melody.Gcompris_melody.ok (   self)

Definition at line 127 of file melody.py.

00127 
00128   def ok(self):
00129     #print("Gcompris_melody ok.")
00130     pass

def melody.Gcompris_melody.pause (   self,
  pause 
)

Definition at line 310 of file melody.py.

00310 
00311   def pause(self, pause):
00312     self.board_paused = pause
00313 
00314     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00315     # the game is won
00316     if(self.gamewon == 1 and pause == 0):
00317       self.cleanup()
00318       self.display_current_level()
00319       self.gamewon = 0
00320 
00321     return
00322 

Here is the call graph for this function:

Here is the caller graph for this function:

def melody.Gcompris_melody.populate (   self,
  sound_struct 
)

Definition at line 278 of file melody.py.

00278 
00279   def populate(self, sound_struct):
00280     #print("Gcompris_melody populate.")
00281     self.solution = []
00282 
00283     for i in range(self.gcomprisBoard.level+2):
00284       self.solution.append(sound_struct[random.randint(0,len(sound_struct)-1)])
00285 
00286     self.timers.append(gtk.timeout_add(1300, self.repeat_it))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 216 of file melody.py.

00216 
00217   def ready(self):
00218 
00219     self.in_repeat = 0
00220     self.timers.pop(0)
00221 

Here is the caller graph for this function:

Definition at line 245 of file melody.py.

00245 
00246   def repeat(self):
00247     #print("Gcompris_melody repeat.")
00248     # Important to use a timer here to keep self.timers up todate
00249     self.timers.append(gtk.timeout_add(50, self.repeat_it))

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 250 of file melody.py.

00250 
00251   def repeat_it(self):
00252     #print("Gcompris_melody repeat it.")
00253     if self.in_repeat:
00254       return
00255 
00256     # We are like paused until the last sound is played
00257     self.in_repeat = 1;
00258 
00259     if self.timers :
00260       self.timers.pop(0)
00261 
00262     self.kidstry = []
00263     timer = 0
00264 
00265     for i in self.solution:
00266       self.timers.append(gtk.timeout_add(timer, self.show_bang, i))
00267       timer = timer + 1000
00268       self.timers.append(gtk.timeout_add(timer, self.show_bang_stop, i))
00269       timer = timer + 500
00270 
00271     self.timers.append(gtk.timeout_add(timer, self.ready))
00272 

Here is the call graph for this function:

Here is the caller graph for this function:

def melody.Gcompris_melody.set_level (   self,
  level 
)

Definition at line 323 of file melody.py.

00323 
00324   def set_level(self, level):
00325     #print("Gcompris_melody set level. %i" % level)
00326     self.gcomprisBoard.level=level;
00327     self.gcomprisBoard.sublevel=1;
00328     self.cleanup()
00329     self.display_current_level()

Here is the call graph for this function:

def melody.Gcompris_melody.show_bang (   self,
  a 
)

Definition at line 232 of file melody.py.

00232 
00233   def show_bang(self, a):
00234 
00235     if self.board_paused or self.rootitem == None:
00236       return
00237 
00238     self.bang_item.set(x=a['x'] + self.hitofset_x, y=a['y'] + self.hitofset_y)
00239 
00240     self.bang_item.show()
00241 
00242     gcompris.sound.play_ogg_cb(a['sound'], self.sound_played)
00243     self.timers.pop(0)
00244 

Here is the call graph for this function:

Here is the caller graph for this function:

def melody.Gcompris_melody.show_bang_stop (   self,
  a 
)

Definition at line 223 of file melody.py.

00223 
00224   def show_bang_stop(self, a):
00225 
00226     if self.board_paused or self.rootitem == None:
00227       return
00228 
00229     self.bang_item.hide()
00230     self.timers.pop(0)

Here is the caller graph for this function:

def melody.Gcompris_melody.sound_item_event (   self,
  widget,
  event,
  sound_struct 
)

Definition at line 349 of file melody.py.

00349 
00350   def sound_item_event(self, widget, event, sound_struct):
00351 
00352     if self.board_paused or self.in_repeat:
00353       return
00354 
00355     if event.type == gtk.gdk.BUTTON_PRESS:
00356       if event.button == 1:
00357           self.sound_play(sound_struct)
00358     return False

Here is the call graph for this function:

def melody.Gcompris_melody.sound_play (   self,
  sound_struct 
)

Definition at line 360 of file melody.py.

00360 
00361   def sound_play(self, sound_struct):
00362     gcompris.sound.play_ogg_cb(sound_struct['sound'], self.sound_played)
00363     self.tried(sound_struct)
00364     return

Here is the call graph for this function:

Here is the caller graph for this function:

def melody.Gcompris_melody.sound_played (   self,
  file 
)

Definition at line 386 of file melody.py.

00386 
00387   def sound_played(self, file):
00388     #print "python sound played :", file
00389     pass

Here is the caller graph for this function:

Definition at line 50 of file melody.py.

00050 
00051   def start(self):
00052     self.saved_policy = gcompris.sound.policy_get()
00053     gcompris.sound.policy_set(gcompris.sound.PLAY_AND_INTERRUPT)
00054 
00055     self.gcomprisBoard.level=1
00056     self.gcomprisBoard.sublevel=1
00057     self.gcomprisBoard.number_of_sublevel=1
00058 
00059     # pause the bg music
00060     #print "pause sound"
00061     gcompris.sound.pause()
00062 
00063     self.timers = []
00064     self.solution = []
00065     self.kidstry = []
00066     self.in_repeat = 0
00067     self.theme = 0
00068 
00069     #
00070     # This list contains the 'theme' for each melody level.
00071     #
00072     self.melodylist = \
00073                       [
00074       # xylophon
00075       [
00076       {'theme': "xylofon", 'background': "melody/xylofon/background.png", 'hittool': "melody/xylofon/cursor.png", 'hitofset_x': 50, 'hitofset_y': 50},
00077       [ {'x': 150.0, 'y': 101.0,  'image': "melody/xylofon/son1.png", 'sound': "sounds/melody/xylofon/son1.ogg"},
00078         {'x': 284.0, 'y': 118.0,  'image': "melody/xylofon/son2.png", 'sound': "sounds/melody/xylofon/son2.ogg"},
00079         {'x': 412.0, 'y': 140.0, 'image': "melody/xylofon/son3.png", 'sound': "sounds/melody/xylofon/son3.ogg"},
00080         {'x': 546.0, 'y': 157.0, 'image': "melody/xylofon/son4.png", 'sound': "sounds/melody/xylofon/son4.ogg"} ] ],
00081 
00082       # guitar
00083       [
00084       {'theme': "guitar", 'background': "melody/guitar/background.jpg", 'hittool': "melody/guitar/cursor.png", 'hitofset_x': 400, 'hitofset_y': -5},
00085       [ {'x': 0, 'y': 170.0,  'image': "melody/guitar/son1.png", 'sound': "sounds/melody/guitar/son1.ogg"},
00086         {'x': 0, 'y': 230.0,  'image': "melody/guitar/son2.png", 'sound': "sounds/melody/guitar/son2.ogg"},
00087         {'x': 0, 'y': 290.0, 'image': "melody/guitar/son3.png", 'sound': "sounds/melody/guitar/son3.ogg"},
00088         {'x': 0, 'y': 350.0, 'image': "melody/guitar/son4.png", 'sound': "sounds/melody/guitar/son4.ogg"} ] ],
00089 
00090       # Kitchen
00091       [
00092       {'theme': "tachos", 'background': "melody/tachos/background.jpg", 'hittool': "melody/tachos/cursor.png", 'hitofset_x': 50, 'hitofset_y': 50},
00093       [ {'x': 150.0, 'y': 50.0,  'image': "melody/tachos/son1.png", 'sound': "sounds/melody/tachos/son1.ogg"},
00094         {'x': 550.0, 'y': 50.0,  'image': "melody/tachos/son2.png", 'sound': "sounds/melody/tachos/son2.ogg"},
00095         {'x': 150.0, 'y': 250.0, 'image': "melody/tachos/son3.png", 'sound': "sounds/melody/tachos/son3.ogg"},
00096         {'x': 550.0, 'y': 250.0, 'image': "melody/tachos/son4.png", 'sound': "sounds/melody/tachos/son4.ogg"} ] ] ]
00097 
00098     self.maxtheme = len(self.melodylist)-1
00099     self.gcomprisBoard.maxlevel = 9
00100 
00101     #
00102     pixmap = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("button_reload.png"))
00103     if(pixmap):
00104       gcompris.bar_set_repeat_icon(pixmap)
00105       gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_REPEAT_ICON)
00106     else:
00107       gcompris.bar_set(gcompris.BAR_LEVEL|gcompris.BAR_REPEAT)
00108 
00109 
00110     self.pause(1);
00111     self.display_current_level()
00112 
00113     # Play an intro sound
00114     gcompris.sound.play_ogg_cb("sounds/melody/" + self.melodylist[self.theme][0]['theme'] + "/melody.ogg", self.intro_cb)
00115 
00116     Prop = gcompris.get_properties()
00117 
00118     if(not Prop.fx):
00119       gcompris.utils.dialog(_("Error: this activity cannot be played with the\nsound effects disabled.\nGo to the configuration dialogue to\nenable the sound"), stop_board)

def melody.Gcompris_melody.switch_item_event (   self,
  widget,
  event 
)

Definition at line 366 of file melody.py.

00366 
00367   def switch_item_event(self, widget, event):
00368 
00369     if self.board_paused or self.in_repeat:
00370       return
00371     # switch the theme
00372     if event.type == gtk.gdk.BUTTON_PRESS:
00373       if event.button == 1:
00374        if self.theme < self.maxtheme:
00375          self.theme += 1
00376        else:
00377          self.theme = 0
00378 
00379        #print("New melody theme : " + self.melodylist[self.theme][0]['theme'] + ".")
00380     # Apply the changes
00381        self.cleanup()
00382        self.display_current_level()
00383 
00384 
00385     return False

Here is the call graph for this function:

def melody.Gcompris_melody.tried (   self,
  a 
)

Definition at line 203 of file melody.py.

00203 
00204   def tried(self, a):
00205     if len(self.kidstry) >= len(self.solution) :
00206       self.kidstry.pop(0)
00207     self.kidstry.append(a)
00208     #level finished?
00209     if self.kidstry == self.solution :
00210       if (self.increment_level() == 1):
00211         self.gamewon = 1
00212         gcompris.sound.policy_set(self.saved_policy)
00213         gcompris.bonus.display(1, gcompris.bonus.FLOWER)
00214 

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 188 of file melody.py.

Definition at line 46 of file melody.py.

Definition at line 47 of file melody.py.

Definition at line 38 of file melody.py.

Definition at line 196 of file melody.py.

Definition at line 197 of file melody.py.

Definition at line 65 of file melody.py.

Definition at line 64 of file melody.py.

Definition at line 97 of file melody.py.

Definition at line 71 of file melody.py.

Definition at line 143 of file melody.py.

Definition at line 51 of file melody.py.

Definition at line 63 of file melody.py.

Definition at line 177 of file melody.py.

Definition at line 174 of file melody.py.

Definition at line 162 of file melody.py.

Definition at line 66 of file melody.py.

Definition at line 62 of file melody.py.


The documentation for this class was generated from the following file: