[gcompris] music activities, removed all ready() code



commit c46b7c44bceaa8f954d84b0b65799c30fe5d84de
Author: Bruno Coudoin <bruno coudoin free fr>
Date:   Sun Sep 9 22:23:36 2012 +0200

    music activities, removed all ready() code
    
    There is no reason to have code to avoid children's double click.
    The operating system takes care of double click for us.

 src/note_names-activity/note_names.py              |   21 +++-----
 src/piano_composition-activity/gcomprismusic.py    |   51 +++----------------
 .../piano_composition.py                           |    9 ----
 src/play_piano-activity/play_piano.py              |    8 ---
 src/play_rhythm-activity/play_rhythm.py            |    8 ---
 5 files changed, 15 insertions(+), 82 deletions(-)
---
diff --git a/src/note_names-activity/note_names.py b/src/note_names-activity/note_names.py
index 93698af..42fc4c3 100644
--- a/src/note_names-activity/note_names.py
+++ b/src/note_names-activity/note_names.py
@@ -50,12 +50,10 @@ class Gcompris_note_names:
 
         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 
+        self.pitchSoundEnabled = True # toggle to choose whether or not to
         # play the pitch sounds
         self.master_is_not_ready = False # boolean to prepare sound timing
 
-        self._okayToRepeat = False
-
         self.remainingNotesToIdentify = []
 
         self.repeatThisNoteLaterPlease = False
@@ -216,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._okayToRepeat = True
         self.drawRandomNote(self.staff.staffName)
 
     def updateGameLevel(self, levelNum):
@@ -284,17 +281,15 @@ They also form the C Major Scale. Notice that the note positions are different t
         draw a random note, selected from the pitchPossibilities, and save as self.currentNote
         '''
 
-        if not self._okayToRepeat:
-            if not ready(self):
-                return
-
-        newNoteID = self.remainingNotesToIdentify[randint(0, len(self.pitchPossibilities) - 1)]
+        newNoteID = \
+            self.remainingNotesToIdentify[randint(0, len(self.pitchPossibilities) - 1)]
 
-        if hasattr(self, 'currentNote') and self.currentNote.numID == newNoteID and len(self.remainingNotesToIdentify) > 1: #don't repeat the same note twice
-            self._okayToRepeat = True
+        # don't repeat the same note twice
+        if hasattr(self, 'currentNote') \
+                and self.currentNote.numID == newNoteID \
+                and len(self.remainingNotesToIdentify) > 1:
             self.drawRandomNote(staffType)
             return
-        self._okayToRepeat = False
 
         note = QuarterNote(newNoteID, staffType, self.staff.rootitem, self.sharpNotation)
 
@@ -383,8 +378,6 @@ They also form the C Major Scale. Notice that the note positions are different t
         self.selectedNoteObject = widget
 
         if self.pitchSoundEnabled:
-            if not ready(self) or self.master_is_not_ready:
-                return
             if self.currentNote.numID == 8:
                 numID = 8
             HalfNote(numID, self.staff.staffName, self.staff.rootitem).play()
diff --git a/src/piano_composition-activity/gcomprismusic.py b/src/piano_composition-activity/gcomprismusic.py
index 97ed3fe..4a185a2 100644
--- a/src/piano_composition-activity/gcomprismusic.py
+++ b/src/piano_composition-activity/gcomprismusic.py
@@ -400,17 +400,14 @@ class Staff():
             pass
 
         if len(self.noteList) > 1:
-            if not ready(self):
-              return
-            else:
-              self.currentNoteXCoordinate = self.noteList[-2].x
-              remainingNoteY = self.noteList[-2].y
-              self.currentLineNum = self.getLineNum(remainingNoteY)
-              if len(self.noteList) >= 2:
-                  if self.noteList[-1].noteType == 8 and self.noteList[-1].isTupleBound and self.noteList[-2].noteType == 8:
-                      self.drawTwoSingleEighthNotes(self.noteList[-2], self.noteList[-1])
-              self.noteList[-1].remove()
-              self.noteList.pop()
+            self.currentNoteXCoordinate = self.noteList[-2].x
+            remainingNoteY = self.noteList[-2].y
+            self.currentLineNum = self.getLineNum(remainingNoteY)
+            if len(self.noteList) >= 2:
+                if self.noteList[-1].noteType == 8 and self.noteList[-1].isTupleBound and self.noteList[-2].noteType == 8:
+                    self.drawTwoSingleEighthNotes(self.noteList[-2], self.noteList[-1])
+            self.noteList[-1].remove()
+            self.noteList.pop()
         else:
             self.eraseAllNotes()
 
@@ -422,9 +419,6 @@ class Staff():
 
         >>> self.newStaff.eraseAllNotes()
         '''
-        #if not ready(self):
-        #    return False
-
         for o in self._beatNumLabels:
             o.remove()
         for n in self.noteList:
@@ -510,8 +504,6 @@ class Staff():
         #if not self.noteList or self.notReadyToPlay:
         #    return
         self.notReadyToPlay = True
-        #if not ready(self):
-        #    return False
 
         self.timers = []
         self.currentNoteIndex = 0
@@ -856,8 +848,6 @@ class Note():
         plays the note pitch. Each pitch is stored in the resources
         folder as an .ogg file (these are not synthesized)
         '''
-        if not ready(self, 700) or self.silent:
-            return False
         # sometimes this method is called without actually having fa note
         # printed on the page (we just want to hear the pitch). Thus, only
         # highlight a note if it exists!
@@ -1354,31 +1344,6 @@ def textBox(text, x, y , self, width=10000, fill_color=None, stroke_color=None,
         text.raise_(rect)
         return text, rect
     return text
-def ready(self, timeouttime=200):
-    '''
-    function to help prevent "double-clicks". If your function call is
-    suffering from accidental system double-clicks, import this module
-    and write these lines at the top of your method:
-
-        if not ready(self):
-            return False
-    '''
-
-    if not hasattr(self, 'clickTimers'):
-        self.clickTimers = []
-        self.readyForNextClick = True
-        return True
-
-    def clearClick():
-        self.readyForNextClick = True
-        return False
-
-    if self.readyForNextClick == False:
-        return
-    else:
-        self.clickTimers.append(gobject.timeout_add(timeouttime, clearClick))
-        self.readyForNextClick = False
-        return True
 
 def clearResponsePic(self):
     self.responsePic.remove()
diff --git a/src/piano_composition-activity/piano_composition.py b/src/piano_composition-activity/piano_composition.py
index 9981972..e14ea22 100644
--- a/src/piano_composition-activity/piano_composition.py
+++ b/src/piano_composition-activity/piano_composition.py
@@ -569,8 +569,6 @@ dialogue to\nenable the sound."), stop_board)
         eraseUserPrompt(None, None, None,self)
 
     def change_accidental_type(self, widget, target, event):
-        if not ready(self):
-            return False
         self.keyboard.sharpNotation = not self.keyboard.sharpNotation
         self.keyboard.draw(300, 200, self.keyboard_click)
         if self.keyboard.sharpNotation:
@@ -586,9 +584,6 @@ dialogue to\nenable the sound."), stop_board)
         with a note name, text is output to canvas, the note sound is generated,
         and the note is drawn on the staff
         '''
-        if not ready(self):
-            return False
-
         if hasattr(self.staff, 'locked') and self.staff.locked:
             return
         if not numID:
@@ -735,15 +730,11 @@ dialogue to\nenable the sound."), stop_board)
     def key_press(self, keyval, commit_str, preedit_str):
 
         utf8char = gtk.gdk.keyval_to_unicode(keyval)
-        #if not ready(self, timeouttime=100): return False
         if keyval == gtk.keysyms.BackSpace:
-            if not ready(self, timeouttime=100): return False
             self.staff.eraseOneNote()
         elif keyval == gtk.keysyms.Delete:
-            if not ready(self, timeouttime=100): return False
             self.askAndEraseStaff()
         elif keyval == gtk.keysyms.space:
-            if not ready(self, timeouttime=100): return False
             self.staff.playComposition()
         else:
             pianokeyBindings(keyval, self)
diff --git a/src/play_piano-activity/play_piano.py b/src/play_piano-activity/play_piano.py
index 5a18420..5aec4b3 100644
--- a/src/play_piano-activity/play_piano.py
+++ b/src/play_piano-activity/play_piano.py
@@ -161,9 +161,6 @@ class Gcompris_play_piano:
         self.timers.append(gobject.timeout_add(500, self.staff.playComposition))
 
     def ok_event(self, widget=None, target=None, event=None):
-        if not ready(self, 1000):
-            return False
-
         if self.kidsNoteList == self.givenOption:
             displayHappyNote(self, self.nextChallenge)
             self.score += 1
@@ -216,15 +213,12 @@ class Gcompris_play_piano:
 
             self.erase_entry()
         elif keyval == gtk.keysyms.Delete:
-            if not ready(self, timeouttime=100): return False
             self.erase_entry()
         elif keyval == gtk.keysyms.Return:
             self.ok_event()
         elif keyval == gtk.keysyms.space:
-            if not ready(self, timeouttime=50): return False
             self.staff.playComposition()
         else:
-            if not ready(self, timeouttime=50): return False
             pianokeyBindings(keyval, self)
         return True
     def pause(self, pause):
@@ -241,8 +235,6 @@ class Gcompris_play_piano:
 
 
     def color_code_notes(self, widget, target, event):
-        if not ready(self):
-            return False
         if self.staff.colorCodeNotes:
             self.staff.colorCodeNotes = False
             self.staff.colorAllNotes('black')
diff --git a/src/play_rhythm-activity/play_rhythm.py b/src/play_rhythm-activity/play_rhythm.py
index b4e8dde..3127ae8 100644
--- a/src/play_rhythm-activity/play_rhythm.py
+++ b/src/play_rhythm-activity/play_rhythm.py
@@ -216,8 +216,6 @@ class Gcompris_play_rhythm:
                                                self.updateBoard, 2))
 
     def ok_event(self, widget=None, target=None, event=None):
-        if not ready(self, 1000):
-            return False
 
         def nearlyEqual(inputNum, correctNum, amountOfError):
             return abs(inputNum - correctNum) <= amountOfError
@@ -368,9 +366,6 @@ class Gcompris_play_rhythm:
 
     def record_click(self, widget=None, target=None, event=None):
 
-        if not ready(self):
-            return
-
         if self.readyForFirstDrumBeat and self.playingLine:
             self.staff.playComposition(playingLineOnly=True)
 
@@ -424,17 +419,14 @@ class Gcompris_play_rhythm:
         utf8char = gtk.gdk.keyval_to_unicode(keyval)
 
         if keyval == gtk.keysyms.BackSpace:
-            if not ready(self, timeouttime=100): return False
             self.erase_entry()
         elif keyval == gtk.keysyms.Delete:
-            if not ready(self, timeouttime=100): return False
             self.erase_entry()
         elif keyval == gtk.keysyms.space:
             self.record_click()
         elif keyval == gtk.keysyms.Return:
             self.ok_event()
         elif keyval == gtk.keysyms.Tab:
-            if not ready(self, timeouttime=100): return False
             if self.gcomprisBoard.level in [1, 3, 5, 7, 9, 11]:
                 self.staff.playComposition()
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]