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

[pygame] Voice For Buttons



    For anyone who is interested on the list.

Hey!
    So it works and I have a lot of number sound files. But this works perfectly
and could even make up with my voice as well...anyone's. There is no delay, in fact
the voice is even faster than the screen reader voice reading the title bar. It will
be interesting to see what can be done from this point on. I did look at the reference
manual and it is perfect as well. The way I like to read them.
Program As it stands:
# Import the necessary ocempgui parts.
from ocempgui.widgets import *
from ocempgui.widgets.Constants import *
import pygame.mixer
mixer = pygame.mixer
# choose a desired audio format
# (freq, size, stereo, buffersize)
# 1=mono, 2=stereo and 1024 buf size, 2050 for 16 bit
mixer.init(21024) #raises exception on fail
# playsound function
def play_sound (file):
    sound = mixer.Sound(file)
    channel = sound.play() #(loops+1, max ms-time)
# object_focused will print a widget's text to the console.
def object_focused (gui_widget, SoundFile):
#    print "Element %s is focused" % gui_widget.text
    re.title = " %s focused" % gui_widget.text
#    re.title = "Two button demo"
    play_sound (SoundFile)
# Create the first button with no text and place it at screen offset 10,
# 10.
button_one = Button ()
button_one.topleft = 3, 3
# Create a red background color for the first button and assign it a red
# label with the text "Button number one".
label_one = Label ("Button one")
label_one.create_style()
label_one.style["bgcolor"][STATE_NORMAL] = (255, 0, 0)
button_one.create_style()
button_one.style["bgcolor"][STATE_NORMAL] = (255, 0, 0)
button_one.child = label_one
# Connect the focus event (for tab).
button_one.connect_signal (SIG_FOCUSED, object_focused, button_one,
"Button_One.wav")
# Connect the mouse enter event to the button to have some "hover"
# effect.
button_one.connect_signal (SIG_ENTER, object_focused, button_one,
"Button_One.wav")
#  Now when clicked assign sound file to button.
button_one.connect_signal (SIG_CLICKED, object_focused, button_one,
"button_one.wav")
# Create the second button with no text and place it 14 pixels to the right
# of the first one.
button_two = Button ()
button_two.topleft = button_one.left + 14, button_one.bottom
# Create a green background color for the second button and assign it a
# green label with the text "Button number two".
label_two = Label ("Button two")
label_two.create_style()
label_two.style["bgcolor"][STATE_NORMAL] = (0, 255, 0)
button_two.create_style()
button_two.style["bgcolor"][STATE_NORMAL] = (0, 255, 0)
button_two.child = label_two
# Connect the focus event (for tab or mouse "hover") of the second button.
button_two.connect_signal (SIG_FOCUSED, object_focused, button_two,
"Button_Two.wav")
# Connect the mouse movement event to the button to have some "hover"
# effect.
button_two.connect_signal (SIG_ENTER, object_focused, button_two,
"Button_Two.wav")
#  Now when clicked assign sound file to button.
button_two.connect_signal (SIG_CLICKED, object_focused, button_two,
"button_two.wav")
# Create the renderer object.
re = Renderer ()
# Let the renderer create a pygame screen with 200 pixels width and 200
# pixels height.
re.create_screen (200, 200)
# Set the window title to "Two button demo".
re.title = "Two button demo"
# Set the screen background color to a grey RGB value.
re.color = (200, 200, 200)
# Add the both buttons.
re.add_widget (button_one, button_two)
# Start the main loop for drawing and event processing.
re.start ()