[gcompris] music activities, use internal bonus API
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris] music activities, use internal bonus API
- Date: Sun, 9 Sep 2012 21:33:56 +0000 (UTC)
commit 0a0cb4b0ea54cab7ae3ba1febeedece24f8f3c8d
Author: Bruno Coudoin <bruno coudoin free fr>
Date: Sun Sep 9 23:29:18 2012 +0200
music activities, use internal bonus API
Removed displayHappyNote() and displaySadNote(). This is
replaced by the GCompris bonus API.
src/note_names-activity/note_names.py | 26 +++++-------
src/piano_composition-activity/gcomprismusic.py | 47 -----------------------
src/play_piano-activity/play_piano.py | 15 +++++--
src/play_rhythm-activity/play_rhythm.py | 24 ++++++++---
4 files changed, 39 insertions(+), 73 deletions(-)
---
diff --git a/src/note_names-activity/note_names.py b/src/note_names-activity/note_names.py
index 42fc4c3..510207c 100644
--- a/src/note_names-activity/note_names.py
+++ b/src/note_names-activity/note_names.py
@@ -58,6 +58,8 @@ class Gcompris_note_names:
self.repeatThisNoteLaterPlease = False
+ self.afterBonus = None
+
def start(self):
# Set the buttons we want in the bar
gcompris.bar_set(gcompris.BAR_LEVEL)
@@ -212,7 +214,6 @@ They also form the C Major Scale. Notice that the note positions are different t
)
def prepareGame(self):
- self.clearPic()
self.staff.eraseAllNotes()
self.drawRandomNote(self.staff.staffName)
@@ -400,8 +401,7 @@ They also form the C Major Scale. Notice that the note positions are different t
def ok_event(self, widget, target, event):
'''
called when the kid presses a notename. Checks to see if this is the correct
- note name. displays the appropriate (happy or sad) note picture, and
- resets the board if appropriate
+ note name. displays the appropriate bonus, and resets the board if appropriate
'''
self.master_is_not_ready = True
@@ -412,23 +412,17 @@ They also form the C Major Scale. Notice that the note positions are different t
if not self.repeatThisNoteLaterPlease:
self.remainingNotesToIdentify.remove(c)
if self.remainingNotesToIdentify == []:
- #gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.NOTE)
- displayHappyNote(self, lambda: self.set_level(self.gcomprisBoard.level + 1))
+ self.afterBonus = lambda: self.set_level(self.gcomprisBoard.level + 1)
+ gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.NOTE)
else:
- # gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.NOTE)
- displayHappyNote(self, self.prepareGame)
+ self.afterBonus = self.prepareGame
+ gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.NOTE)
self.repeatThisNoteLaterPlease = False
else:
+ gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.NOTE)
self.repeatThisNoteLaterPlease = True
- displaySadNote(self, self.clearPic)
- self.responsePic.raise_(None)
-
- def clearPic(self):
- if hasattr(self, 'responsePic'):
- self.responsePic.remove()
-
def end(self):
# Remove the root item removes all the others inside it
self.staff.eraseAllNotes()
@@ -467,7 +461,9 @@ They also form the C Major Scale. Notice that the note positions are different t
strn = u'%c' % utf8char
def pause(self, pause):
- pass
+ if not pause and self.afterBonus:
+ self.afterBonus()
+ self.afterBonus = None
def stop_board():
pass
diff --git a/src/piano_composition-activity/gcomprismusic.py b/src/piano_composition-activity/gcomprismusic.py
index 4a185a2..4e5a2f7 100644
--- a/src/piano_composition-activity/gcomprismusic.py
+++ b/src/piano_composition-activity/gcomprismusic.py
@@ -1348,53 +1348,6 @@ def textBox(text, x, y , self, width=10000, fill_color=None, stroke_color=None,
def clearResponsePic(self):
self.responsePic.remove()
-def displayHappyNote(self, nextMethod):
- '''
- displays the happy note for 900 milliseconds
- '''
-
- if hasattr(self, 'responsePic'):
- self.responsePic.remove()
- if not hasattr(self, 'timers'):
- self.timers = []
- gcompris.sound.play_ogg("/piano_composition/bonus.wav")
- self.responsePic = goocanvas.Image(
- parent=self.rootitem,
- pixbuf=gcompris.utils.load_pixmap('piano_composition/happyNote.png'),
- x=300,
- y=100,
- height=300,
- width=150
- )
-
- #self.responsePic.raise_(None)
- self.timers.append(gobject.timeout_add(900, clearResponsePic, self))
- self.timers.append(gobject.timeout_add(910, nextMethod))
-
-
-def displaySadNote(self, nextMethod):
- '''
- displays the sad note for 900 milliseconds
- '''
-
- if hasattr(self, 'responsePic'):
- self.responsePic.remove()
- if not hasattr(self, 'timers'):
- self.timers = []
- self.responsePic = goocanvas.Image(
- parent=self.rootitem,
- pixbuf=gcompris.utils.load_pixmap('piano_composition/sadNote.png'),
- x=300,
- y=100,
- height=300,
- width=150
- )
- gcompris.sound.play_ogg("/piano_composition/bleep.wav")
- self.responsePic.raise_(None)
- self.timers.append(gobject.timeout_add(900, clearResponsePic, self))
- self.timers.append(gobject.timeout_add(910, nextMethod))
-
-
def pianokeyBindings(keyval, self):
'''
nice key bindings for the piano keys
diff --git a/src/play_piano-activity/play_piano.py b/src/play_piano-activity/play_piano.py
index 5aec4b3..aaada81 100644
--- a/src/play_piano-activity/play_piano.py
+++ b/src/play_piano-activity/play_piano.py
@@ -47,6 +47,8 @@ class Gcompris_play_piano:
self.metronomePlaying = False
self.timers = []
+ self.afterBonus = None
+
def start(self):
self.recordedHits = []
self.saved_policy = gcompris.sound.policy_get()
@@ -162,15 +164,17 @@ class Gcompris_play_piano:
def ok_event(self, widget=None, target=None, event=None):
if self.kidsNoteList == self.givenOption:
- displayHappyNote(self, self.nextChallenge)
+ self.afterBonus = self.nextChallenge
+ gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.NOTE)
self.score += 1
else:
- displaySadNote(self, self.tryagain)
- self.timers.append(gobject.timeout_add(1500, self.staff.playComposition))
+ self.afterBonus = self.tryagain
+ gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.NOTE)
self.score -= 1
def tryagain(self):
self.kidsNoteList = []
+ self.staff.playComposition
def nextChallenge(self):
self.kidsNoteList = []
@@ -221,8 +225,11 @@ class Gcompris_play_piano:
else:
pianokeyBindings(keyval, self)
return True
+
def pause(self, pause):
- pass
+ if not pause and self.afterBonus:
+ self.afterBonus()
+ self.afterBonus = None
def set_level(self, level):
'''
diff --git a/src/play_rhythm-activity/play_rhythm.py b/src/play_rhythm-activity/play_rhythm.py
index 3127ae8..7366b5b 100644
--- a/src/play_rhythm-activity/play_rhythm.py
+++ b/src/play_rhythm-activity/play_rhythm.py
@@ -47,6 +47,7 @@ class Gcompris_play_rhythm:
self.metronomePlaying = False
self.timers = []
+ self.afterBonus = None
def start(self):
@@ -226,31 +227,37 @@ class Gcompris_play_rhythm:
correctedList = []
if len(self.netOffsets) != len(self.givenOption):
self.doNotRemoveFromList = True
- displaySadNote(self, self.tryagain)
+ self.afterBonus = self.tryagain
+ gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.NOTE)
return
for rhythmItem, recordedHit in zip(self.givenOption[:-1], self.netOffsets[1:]):
if rhythmItem == 8:
if not nearlyEqual(recordedHit, 0.25, 0.2):
self.doNotRemoveFromList = True
- displaySadNote(self, self.tryagain)
+ self.afterBonus = self.tryagain
+ gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.NOTE)
return
if rhythmItem == 4:
if not nearlyEqual(recordedHit, 0.5, 0.2):
self.doNotRemoveFromList = True
- displaySadNote(self, self.tryagain)
+ self.afterBonus = self.tryagain
+ gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.NOTE)
return
if rhythmItem == 2:
if not nearlyEqual(recordedHit, 1.0, 0.2):
self.doNotRemoveFromList = True
- displaySadNote(self, self.tryagain)
+ self.afterBonus = self.tryagain
+ gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.NOTE)
return
if rhythmItem == 1:
if not nearlyEqual(recordedHit, 2.0, 0.2):
self.doNotRemoveFromList = True
- displaySadNote(self, self.tryagain)
+ self.afterBonus = self.tryagain
+ gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.NOTE)
return
- displayHappyNote(self, self.nextChallenge)
+ self.afterBonus = self.nextChallenge
+ gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.NOTE)
if self.doNotRemoveFromList == False:
self.remainingOptions.remove(self.givenOption)
@@ -431,7 +438,10 @@ class Gcompris_play_rhythm:
self.staff.playComposition()
def pause(self, pause):
- pass
+ if not pause and self.afterBonus:
+ self.afterBonus()
+ self.afterBonus = None
+
def set_level(self, level):
'''
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]