Tqst DriIS

OK, so you're finally ready to start up your new custom widget code. This is what it looks like after you bring your code into IDLE and press F5:

tfr JV

The checkboxes and volume scales are now grouped together on the same widget within the GUI. From now on, you will know that the widgets on your GUI will always stay together as the SoundPanel () class has grouped them for you.

ijieret^re no

Dumb Questions

Q/ I don't get it. What's this "self" thing again?

A" "se'f" 's a variable that refers to the calling object.

The calling object? What does that mean?

A" Imagine you create a new method called bleep () in the SoundPanel class. An object called panel can use the bleep () method as needed, and when it does, it calls the SoundPanel class. The "self." bit ensures that the bleep () method associated with the panel object is called, not some other bleep () method associated with some other object.

So objects don't actually own their own methods?

A." In some languages, such as Ruby, they can, but in most languages, no, objects don't own their own methods. The methods all belong to the class that created the object.

But why do I need to add "self." to the start of the variables?

A." Because then you are changing data inside the current object referred to by "self.". You will be working with the object's own data, and not with data that belongs to the class.

Q/ Not all the variables had "self." at the beginning. Why is that?

A." If you look at the code, the volume_scale variable does not begin with "self.". That's because the object does not need to keep track of the volume_s cale variable once the initializer method has finished creating the object. volume_ scale is a variable that is local to the initializer.

add the tracks

The DJ has an entire directory of tracks

The DJ is so impressed by how usable your program is that he wants to try it out tonight for his complete set, prior to its official unveiling at the World Music Mixing Expo. The DJ needs to work with a lot more than two tracks. In fact, he has an entire directory full of loops.

piY-etW/

full of loops

stage6-read-all-filti& - File Man a tier file £dit ^iew so Help

["<" E^ banyp Iti Desktop | inucsiqn | HH'rag | chaptcriu | codc | |stage6-read-all-fiies

i IWftU

i(5i47_M_nrn_b ^4fi4_M_nrn_ i9fi07_H_Rrn_ 4m? M nm s 4i7??_M_nrn_ ccpjinc.wav _trQncc_mjrnpct _trumpct_dclay_ onar_Unc.wav _happy_frc;iq,wa

JlJUp.WdV loUfl.WdV v

f MIFHM

45414_M_RED_Tr 49119_M_FtED_H 5MS9_N_RED_N 50S43_M_RED_W 59264_M_RED_T ance_Train.wav ardBouncer.wav ephlimizer.wav ave Base Loop, wa heDreamDrums.

v tributton.txt hfinix.pyw m inihnri_pnr(ll.py

Now you could just change the code to add the extra files to the interface but the DJ wants to be able to manage which tracks the program uses. So you will have to find all of the WAV files in the current directory and then add them to the interface when the program starts.

Let's get this thing to work.

Poo] Puzzje

Your job is to take segments from the pool and place them into the blank lines in the code. You may not use the same segment more than once, and you won't need to use all the segments. Your goal is to complete the code in hfmix. pyw so that it reads all the tracks from the directory and then adds them to the GUI interface.

from tkinter import * from sound_panel import * import pygame.mixer import os app = Tk()

app.title("Head First Mix")

mixer = pygame.mixer mixer.init ()

Note: each thing from the pool can be used only once!

def shutdown():

track.stop()

app.destroy()

app.protocol("WM_DELETE_WINDOW", shutdown) app.mainloop()

for fname panel = SoundPanel(app, mixer, fname)

for fname panel = SoundPanel(app, mixer, fname)

■>50459 M RED Nephlimizer.wav"

if fname.endswith(".wav") :

tracks added

Poo] Puzzje Solution

Your job was to take segments from the pool and place them into the blank lines in the code. You could not use the same segment more than once, and you didn't need to use all the segments. Your goal was to complete the code in hfmix. pyw so that it reads all the tracks from the directory and then adds them to the GUI interface.

from tkinter import * from sound_panel import * import pygame.mixer import os

Vow need to "talk to the operating system, so ^ ^ import the V module.

app.title("Head First Mix")

¿jet the names ok all mixer = pygame.mixer the-files in the durvent mixer.init()

for fname in dirList:

if fname.endswith(".wav") :

panei = SoundPanei(app, mixer, fname)

panei.packO

def shutdown():

track.stop()

it to the app.destroy()

app.protocol("WM_DELETE_WINDOW", shutdown) app.mainloop()

Was this article helpful?

0 0

Post a comment