[gcompris] music activities, removed useless timers variables
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris] music activities, removed useless timers variables
- Date: Sun, 30 Sep 2012 21:53:29 +0000 (UTC)
commit d30d09b3b9d1341315dbb873ae9e900f0ba24fca
Author: Bruno Coudoin <bruno coudoin free fr>
Date: Sun Sep 30 17:35:15 2012 +0200
music activities, removed useless timers variables
In several places in music activities each call to a timeout_add
was saved in a list named self.timers. This list was not used anymore.
This patch removes these variables when not needed and add a protection
against callcack being called after the end of the activity.
src/note_names-activity/note_names.py | 4 +---
src/piano_composition-activity/gcomprismusic.py | 16 +++++-----------
.../piano_composition.py | 13 ++++---------
src/play_rhythm-activity/play_rhythm.py | 6 ++++++
4 files changed, 16 insertions(+), 23 deletions(-)
---
diff --git a/src/note_names-activity/note_names.py b/src/note_names-activity/note_names.py
index 6d25d0f..0a276c9 100644
--- a/src/note_names-activity/note_names.py
+++ b/src/note_names-activity/note_names.py
@@ -46,8 +46,6 @@ class Gcompris_note_names:
self.gcomprisBoard.level = 1
self.gcomprisBoard.maxlevel = 20
- self.timers = []
-
self.colorButtons = True # toggle to choose whether or not to make the text
# note name buttons colored
self.pitchSoundEnabled = True # toggle to choose whether or not to
@@ -388,7 +386,7 @@ They also form the C Major Scale. Notice that the note positions are different t
'''
self.master_is_not_ready = True
- self.timers.append(gobject.timeout_add(1500, self.readyToSoundAgain))
+ append(gobject.timeout_add(1500, self.readyToSoundAgain))
g = self.selectedNoteObject.get_data('numID')
c = self.currentNote.numID
diff --git a/src/piano_composition-activity/gcomprismusic.py b/src/piano_composition-activity/gcomprismusic.py
index 09772c0..10bdc02 100644
--- a/src/piano_composition-activity/gcomprismusic.py
+++ b/src/piano_composition-activity/gcomprismusic.py
@@ -163,8 +163,6 @@ class Staff():
self.noteList = [] #list of note objects written to staff
- self.timers = [] #list of timers to use for playing, running pictures, etc.
-
# PRIVATE ATTRIBUTES
self._beatNumLabels = []
self._staffImages = [] # to keep references to all the staff clefs put onto the page so we can delete just these when needed
@@ -487,10 +485,8 @@ class Staff():
if not playingLineOnly:
note.play()
- self.timers.append(
- gobject.timeout_add(
- self.noteList[noteIndexToPlay].millisecs,
- self.play_it, noteIndexToPlay + 1, playingLineOnly))
+ gobject.timeout_add(self.noteList[noteIndexToPlay].millisecs,
+ self.play_it, noteIndexToPlay + 1, playingLineOnly)
def playComposition(self, widget=None, target=None, event=None, playingLineOnly=False):
@@ -506,11 +502,10 @@ class Staff():
self.notReadyToPlay = True
- self.timers = []
self.currentNoteIndex = 0
self.play_it(0, playingLineOnly)
- self.timers.append(gobject.timeout_add(self.noteList[self.currentNoteIndex].millisecs,
- self.play_it, (self.currentNoteIndex + 1), playingLineOnly))
+ gobject.timeout_add(self.noteList[self.currentNoteIndex].millisecs,
+ self.play_it, (self.currentNoteIndex + 1), playingLineOnly)
def file_to_staff(self, filename):
'''
@@ -840,7 +835,6 @@ class Note():
self.pitchDir = self._getPitchDir()
- self.timers = []
self.sharpNotation = sharpNotation # toggle to switch note between sharp notation
# and flat notation, if applicable
self.success = None
@@ -900,7 +894,7 @@ class Note():
highlight the note for 700 milliseconds, then revert
'''
self.playingLine.props.visibility = goocanvas.ITEM_VISIBLE
- self.timers.append(gobject.timeout_add(self.millisecs, self.stopHighLight))
+ gobject.timeout_add(self.millisecs, self.stopHighLight)
def stopHighLight(self): # not documented online
self.playingLine.props.visibility = goocanvas.ITEM_INVISIBLE
diff --git a/src/piano_composition-activity/piano_composition.py b/src/piano_composition-activity/piano_composition.py
index 5bb377d..74ae6b2 100644
--- a/src/piano_composition-activity/piano_composition.py
+++ b/src/piano_composition-activity/piano_composition.py
@@ -48,7 +48,6 @@ class Gcompris_piano_composition:
# Needed to get key_press
gcomprisBoard.disable_im_context = True
- self.timers = []
self._bachEasterEggDone = False
self._mozartEasterEggDone = False
self._bananaEasterEggGone = False
@@ -671,8 +670,7 @@ dialogue to\nenable the sound."), stop_board)
x=250,
y=50
)
- self.timers.append(gobject.timeout_add(2000,
- lambda: responsePic.remove() ) )
+ gobject.timeout_add(2000, lambda: responsePic.remove() )
self._bachEasterEggDone = True
if not self._mozartEasterEggDone and '523248685848383244284428' in r:
responsePic = goocanvas.Image(
@@ -681,8 +679,7 @@ dialogue to\nenable the sound."), stop_board)
x=160,
y=80
)
- self.timers.append(gobject.timeout_add(2000,
- lambda: responsePic.remove() ) )
+ gobject.timeout_add(2000, lambda: responsePic.remove() )
self._mozartEasterEggDone = True
if not self._bananaEasterEggGone and '7464-4464-4464' in r:
responsePic = goocanvas.Image(
@@ -694,8 +691,7 @@ dialogue to\nenable the sound."), stop_board)
responsePic.animate(5, 5, 3.0, 0.0, \
absolute=False, duration=800, step_time=100, type=goocanvas.ANIMATE_FREEZE)
- self.timers.append(gobject.timeout_add(800,
- lambda: responsePic.remove() ) )
+ gobject.timeout_add(800, lambda: responsePic.remove() )
self._bananaEasterEggGone = True
if not self._gsoc2012EasterEggGone and '14181814343838345458585481' in r:
@@ -708,8 +704,7 @@ dialogue to\nenable the sound."), stop_board)
self.responsePic.animate(0, 400, 1, 0, \
absolute=False, duration=1000, step_time=100, type=goocanvas.ANIMATE_FREEZE)
- self.timers.append(gobject.timeout_add(1000,
- lambda: responsePic.remove() ) )
+ gobject.timeout_add(1000, lambda: responsePic.remove() )
self._gsoc2012EasterEggGone = True
def end(self):
diff --git a/src/play_rhythm-activity/play_rhythm.py b/src/play_rhythm-activity/play_rhythm.py
index f2cb4ec..e6c8e30 100644
--- a/src/play_rhythm-activity/play_rhythm.py
+++ b/src/play_rhythm-activity/play_rhythm.py
@@ -51,6 +51,7 @@ class Gcompris_play_rhythm:
def start(self):
+ self.running = True
self.recordedHits = []
self.saved_policy = gcompris.sound.policy_get()
gcompris.sound.policy_set(gcompris.sound.PLAY_AND_INTERRUPT)
@@ -319,6 +320,10 @@ class Gcompris_play_rhythm:
self.updateBoard(2)
def updateBoard(self, currentStep):
+
+ if not self.running:
+ return
+
if self.gcomprisBoard.level in [2, 4, 6, 8, 10, 12] and currentStep == 1:
currentStep = 2
if currentStep == 1: # the rhythm is being played
@@ -442,6 +447,7 @@ class Gcompris_play_rhythm:
self.recordedHits.append(time.time() - self.startTime)
def end(self):
+ self.running = False
self.staff.eraseAllNotes()
# Remove the root item removes all the others inside it
self.rootitem.remove()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]