[gnome-devel-docs] Ran through Guitar Tuner in Python



commit b4986544b2ead0109927aca40635da7671aec6e0
Author: P. F. Chimento <philip chimento gmail com>
Date:   Tue Mar 22 18:42:42 2011 +0100

    Ran through Guitar Tuner in Python

 platform-demos/C/guitar-tuner.py.page         |    6 ++--
 platform-demos/C/guitar-tuner/guitar-tuner.py |   44 ++++++++----------------
 2 files changed, 18 insertions(+), 32 deletions(-)
---
diff --git a/platform-demos/C/guitar-tuner.py.page b/platform-demos/C/guitar-tuner.py.page
index 64d8884..afec19a 100644
--- a/platform-demos/C/guitar-tuner.py.page
+++ b/platform-demos/C/guitar-tuner.py.page
@@ -116,10 +116,10 @@ six strings) and the orientation to vertical.</p>
 <p>To do this, open <file>guitar_tuner.py</file> while the user interface file is still open. Switch to the <gui>Signals</gui> tab, which you already used to set the signal name. Now take the row where you set the 
 <gui>clicked</gui> signal and drag it into to the source file inside the main class. The following code will be added to your source file:</p>
 <code mime="text/x-csrc"><![CDATA[
-	def on_button_clicked (button, self):
+def on_button_clicked (self, button):
 ]]></code>
 
-  <p>This signal handler has two arguments: the <code>GtkButton</code> that called the function, and the usual Python class pointer.</p>
+  <p>This signal handler has two arguments: the usual Python class pointer, and the <code>Gtk.Button</code> that called the function.</p>
   <p>For now, we'll leave the signal handler empty while we work on writing the code to produce sounds.</p>
 </section>
 
@@ -219,7 +219,7 @@ def on_button_clicked(self, button):
 
 <section>
   <title>Run the application</title>
-  <p>All of the code should now be ready to go. Click <guiseq><gui>Run</gui><gui>Run</gui></guiseq> to start the application. Enjoy!</p>
+  <p>All of the code should now be ready to go. Click <guiseq><gui>Run</gui><gui>Execute</gui></guiseq> to start the application. Enjoy!</p>
 </section>
 
 <section>
diff --git a/platform-demos/C/guitar-tuner/guitar-tuner.py b/platform-demos/C/guitar-tuner/guitar-tuner.py
index 1e8903f..a313f1b 100644
--- a/platform-demos/C/guitar-tuner/guitar-tuner.py
+++ b/platform-demos/C/guitar-tuner/guitar-tuner.py
@@ -5,18 +5,20 @@ import os, sys
 
 #Comment the first line and uncomment the second before installing
 #or making the tarball (alternatively, use project variables)
-UI_FILE = "guitar_tuner_py.ui"
+UI_FILE = "src/guitar_tuner_py.ui"
 #UI_FILE = "/usr/local/share/guitar_tuner_py/ui/guitar_tuner_py.ui"
 
 class GUI:
 	LENGTH = 500
 	# Frequencies of the strings
-	NOTE_E = 369.23
-	NOTE_A = 440
-	NOTE_D = 587.33
-	NOTE_G = 783.99
-	NOTE_B = 987.77
-	NOTE_e = 1318.5
+	frequencies = {
+		'E': 369.23,
+		'A': 440,
+		'D': 587.33,
+		'G': 783.99,
+		'B': 987.77,
+		'e': 1318.5
+	}
 	
 	def __init__(self):
 		self.builder = Gtk.Builder()
@@ -26,27 +28,18 @@ class GUI:
 		window = self.builder.get_object('window')
 		window.show_all()
 
-
 	def on_button_clicked (self, button):
 		label = button.get_child()
 		text = label.get_label()
-		
-		if text == "E":
-			self.play_sound (self.NOTE_E)
-		elif text == "A":
-			self.play_sound (self.NOTE_A)
-		elif text == "G":
-			self.play_sound (self.NOTE_G)
-		elif text == "D":
-			self.play_sound (self.NOTE_D)
-		elif text == "B":
-			self.play_sound (self.NOTE_B)
-		elif text == "e":
-			self.play_sound (self.NOTE_e)
-			
+		self.play_sound (self.frequencies[text])
+
 	def destroy(window, self):
 		Gtk.main_quit()
 
+	def pipeline_stop(self, pipeline):
+		pipeline.set_state(Gst.State.PAUSED)
+		return False
+
 	def play_sound(self, frequency):
 		pipeline = Gst.Pipeline(name='note')
 		source = Gst.ElementFactory.make('audiotestsrc', 'src')
@@ -61,13 +54,6 @@ class GUI:
 		pipeline.set_state(Gst.State.PLAYING)
 
 		GObject.timeout_add(self.LENGTH, self.pipeline_stop, pipeline)
-
-	def pipeline_stop(self, pipeline):
-		pipeline.set_state(Gst.State.PAUSED)
-		return False
-
-	
-
 		
 def main():
 	Gst.init_check(sys.argv)



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