4 from numpy
import float32
, float64
6 import reinteract
.custom_result
as custom_result
8 class PlayResult(custom_result
.CustomResult
):
9 def __init__(self
, data
):
12 def create_widget(self
):
13 widget
= gtk
.Button("Play")
14 widget
.connect('clicked', self
.play
)
16 widget
.connect('button_press_event', self
.on_button_press
)
17 widget
.connect('realize', self
.on_realize
)
21 def play(self
, *args
):
22 if self
.__data
.dtype
== float32
:
23 command
= "play -t raw -r 44100 -f -4 -L -q -"
25 command
= "play -t raw -r 44100 -f -8 -L -q -"
27 f
= os
.popen(command
, 'w')
31 def __save(self
, filename
):
32 escaped
= filename
.replace("'", r
"'\''")
34 if self
.__data
.dtype
== float32
:
35 command
= "sox -t raw -r 44100 -f -4 -L -q - '%s'" % escaped
37 command
= "sox -t raw -r 44100 -f -8 -L -q - '%s'" % escaped
39 f
= os
.popen(command
, 'w')
43 def on_button_press(self
, button
, event
):
45 custom_result
.show_menu(button
, event
, save_callback
=self
.__save
)
49 def on_realize(self
, button
):
50 # Hack to get the right cursor over the button, since the button
51 # doesn't set a cursor itself. button.window is the text view's
52 # window, we have to search to find button.event_window, since
54 for c
in button
.window
.get_children():
55 if c
.get_user_data() == button
:
56 cursor
= gtk
.gdk
.Cursor(gtk
.gdk
.LEFT_PTR
)
60 if data
.dtype
!= float32
and data
.dtype
!= float64
:
61 raise TypeError("Data must be float32 or float64, not %s", data
.dtype
)
63 return PlayResult(data
)