[tuxdroid-svn] r751 - in software/gadgets/sound_monitor/trunk: . audio_monitor audio_monitor/Pictur
Status: Beta
Brought to you by:
ks156
Author: Paul_R Date: 2007-12-05 17:28:39 +0100 (Wed, 05 Dec 2007) New Revision: 751 Removed: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/Sound_class.py Modified: software/gadgets/sound_monitor/trunk/audio_monitor.tgf software/gadgets/sound_monitor/trunk/audio_monitor/Pictures/Icons/gadget.png software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/conf/other.glade software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/widget/other.glade software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/widget/other.pyp software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/init.pyp software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/main.pyp software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/notify.pyp software/gadgets/sound_monitor/trunk/audio_monitor/Strings/fr_ALL.xml software/gadgets/sound_monitor/trunk/audio_monitor/settings.xml software/gadgets/sound_monitor/trunk/audio_monitor/strings.xml Log: * Changed the gadget icon's * Moved the widget part into the main * Finished the spy and guard dog mode. * Moved the Sound_classes (measure and graph) in the widget file (other.pyp). Modified: software/gadgets/sound_monitor/trunk/audio_monitor/Pictures/Icons/gadget.png =================================================================== (Binary files differ) Property changes on: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/conf/other.glade ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/widget/other.glade =================================================================== (Binary files differ) Property changes on: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/widget/other.glade ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/widget/other.pyp =================================================================== --- software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/widget/other.pyp 2007-12-05 16:14:55 UTC (rev 750) +++ software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/GUI/widget/other.pyp 2007-12-05 16:28:39 UTC (rev 751) @@ -1,9 +1,15 @@ bindtextdomain("params", "") -sys.path.append(_me.get_path('root') + '/Scripts/Python') -from Sound_class import Sound_Graph +import gtk +import sys +import time +import os +import threading +import thread +import math +import commands +import wave class Window(SimpleGladeApp): - def __init__(self, path=_me.get_path('root') + '/Scripts/Python/GUI/widget/other.glade', root="window1", @@ -16,7 +22,6 @@ # ########################################################### def new(self): - self.get_widget("window1").set_title(_me.string('name_to_read')) thread.start_new_thread(self.update, ()) @@ -27,44 +32,45 @@ # ########################################################### def update_value(self): - self.measure.changetext = _me.string('conf_lblChange') self.measure.thresholdtext = _me.string('conf_lblThreshold') self.get_widget('cbbType').append_text(_me.string('at_gui_widget_cbbDog')) self.get_widget('cbbType').append_text(_me.string('at_gui_widget_cbbSpy')) self.get_widget('cbbType').append_text(_me.string('at_gui_widget_cbbRecord')) self.get_widget('cbbType').set_active(0) + self.get_widget('chkDog').set_label(_me.string('at_gui_widget_chkDog')) - self.get_widget('chkDogBehavior').set_label(_me.string('at_gui_widget_chkDogDehavior')) + self.get_widget('chkDog').set_active(_me.get_param('chkDog')) + self.get_widget('chkDogDefault').set_label(_me.string('at_gui_widget_chkDogDefault')) + self.get_widget('chkDogDefault').set_active(_me.get_param('chkDogDefault')) + + self.get_widget('spinDog').set_value(_me.get_param('spinDog')) + self.get_widget('chkSpy').set_label(_me.string('at_gui_widget_chkSpy')) - self.get_widget('chkSpyRecord').set_label(_me.string('at_gui_widget_chkSpyRecord')) + self.get_widget('chkSpy').set_active(_me.get_param('chkSpy')) + + self.get_widget('spinSpy').set_value(_me.get_param('spinSpy')) + self.get_widget('lblDogLevel').set_text(_me.string('at_gui_widget_lblDogLevel')) self.get_widget('lblSpyLevel').set_text(_me.string('at_gui_widget_lblSpyLevel')) self.treeview() - - def on_spinbutton1_changed(self, widget, *args): - print widget.get_text() - self.measure.dog_threshold = float(widget.get_text()) - def on_spinbutton2_changed(self, widget, *args): - self.measure.spy_threshold = float(widget.get_text()) - def treeview(self): - self.index_column = gtk.TreeViewColumn('Index') - self.index_column.set_min_width(80) + self.index_column = gtk.TreeViewColumn(_me.string('Time')) + self.index_column.set_min_width(100) self.index_cell = gtk.CellRendererText() self.index_column.pack_start(self.index_cell, True) self.index_column.add_attribute(self.index_cell, 'text', 0) - self.event_column = gtk.TreeViewColumn(_me.string('conf_lblEvent')) - self.event_column.set_min_width(190) + self.event_column = gtk.TreeViewColumn(_me.string('File')) + self.event_column.set_min_width(170) self.event_cell = gtk.CellRendererText() self.event_column.pack_start(self.event_cell, True) self.event_column.add_attribute(self.event_cell, 'text', 1) - self.type_column = gtk.TreeViewColumn(_me.string('conf_lblType')) + self.type_column = gtk.TreeViewColumn(_me.string('Duration')) self.type_column.set_min_width(80) self.type_cell = gtk.CellRendererText() self.type_column.pack_start(self.type_cell, True) @@ -75,40 +81,76 @@ self.gadget_viewer.append_column(self.index_column) self.gadget_viewer.append_column(self.event_column) self.gadget_viewer.append_column(self.type_column) + + self.gadget_viewer.connect("button_press_event", self.on_tree_button_pressed) + self.gadget_viewer.get_selection().connect("changed",self.on_treeview_selected) self.get_widget("scrolledwindow1").add(self.gadget_viewer) self.get_widget("scrolledwindow1").set_size_request(0, 150) self.get_widget("scrolledwindow1").show_all() - self.value_list.append(None, ['test', 'test', 'test']) - - - ########################################################### - # - # Event functions - # - ########################################################### - def on_window1_destroy(self, widget, *args): - _me.get_param('measure').GUI_on = False - self.measure.GUI_on = False - - - + def refresh_treeview(self, values): + self.value_list.append(None, values) + def update(self): + self.measure = Sound_Measure(float(_me.get_param('Sample'))) + _me.set_param('measure', self.measure) self.graph = Sound_Graph() - _me.set_param('graph', self.graph) - self.measure = _me.get_param('measure') - _me.get_param('measure').graph_measure = self.graph - _me.get_param('graph').measure_graph = self.measure - _me.get_param('measure').GUI_on = True + self.measure.graph_measure = self.graph + self.measure.refresh_treeview = self.refresh_treeview + self.graph.measure = self.measure + + self.monitor_id = tux.monitoring.insert(0xF0, self.measure.on_sound_level) + tux.micro.on() self.update_value() self.graph.set_size_request(400, 200) + _me.set_param('monitor_id', self.monitor_id) + _me.set_param('buffer_idx', self.measure.capture_idx) gtk.gdk.threads_enter() layout = self.get_widget('vbox2') layout.add(self.graph) layout.show_all() gtk.gdk.threads_leave() + def on_tree_button_pressed(self, widget, event): + def show_popup(p, button, time): + tux.sys.wait(0.1) + self.show_gadget_popup(p, button, time) + if event.button == 3: # right click + thread.start_new_thread(show_popup, (None, event.button, event.time)) + +#------------------------------------------------------------ +# Treeview menu +#------------------------------------------------------------ + def show_gadget_popup(self, status_icon, button, activate_time): + menu = gtk.Menu() + + item = gtk.CheckMenuItem(_me.string('Play')) + item.connect("activate", self.read_sound) + menu.append(item) + + menu.show_all() + menu.popup(None, None, None, button, activate_time) + + def on_treeview_selected(self, obj): + path = obj.get_selected_rows() + self.selected_file = path[1][0][0] + 1 + + def read_sound(self, widget): + soundcard = tux.hw.alsa_device + tux.micro.off() + tux.sys.shell("aplay -D %s /tmp/__tux-record%d.wav"%(soundcard, self.selected_file)) + tux.micro.on() + + ########################################################### + # + # Event functions + # + ########################################################### + def on_window1_destroy(self, widget, *args): + if self.measure.num > 1: + os.system('rm /tmp/__tux-record*') + def on_cbbType_changed(self, widget, *args): if self.get_widget('cbbType').get_active() == 0: self.get_widget('notebook').set_current_page(0) @@ -117,4 +159,330 @@ if self.get_widget('cbbType').get_active() == 2: self.get_widget('notebook').set_current_page(2) - + def on_spinbutton1_changed(self, widget, *args): + self.measure.dog_threshold = float(widget.get_text()) + + def on_spinbutton2_changed(self, widget, *args): + self.measure.spy_threshold = float(widget.get_text()) + + def on_chkSpy_toggled(self, widget, *args): + _me.set_param('chkSpy', widget.get_active()) + self.measure.spy_enabled = widget.get_active() + + def on_chkDog_toggled(self, widget, *args): + _me.set_param('chkDog', widget.get_active()) + self.measure.dog_enabled = widget.get_active() + + def on_chkDogDefault_toggled(self, widget, *args): + _me.set_param('chkDogDefault', widget.get_active()) + + def on_fileDogBehavior_selection_changed(self, widget, *args): + + _me.set_param('dogBehavior', widget.get_filename()) + +class Sound_Graph(gtk.DrawingArea): + def __init__(self): + super(Sound_Graph, self).__init__() + self.connect("expose_event", self.expose) + self.context = None + + def expose(self, widget, event): + self.context = widget.window.cairo_create() + self.context.rectangle(event.area.x, event.area.y, + event.area.width, event.area.height) + self.context.clip() + self.draw() + return False + + def refresh(self): + if self.window: + width,height = self.window.get_size() + self.window.invalidate_rect(gtk.gdk.Rectangle(0,0,width,height),False) + + def draw(self): + self.rect = self.get_allocation() + + self.draw_space() + self.draw_hor_div() + self.draw_ver_div() + if self.measure.dog_enabled: + self.draw_threshold(self.measure.dog_threshold, 1) + if self.measure.spy_enabled: + self.draw_threshold(self.measure.spy_threshold, 2) + self.draw_curve() + + def draw_space(self): + #draw axes + #draw a rectangle in the window area + self.context.rectangle(self.rect.x, self.rect.y, self.rect.width, self.rect.height) + #set a white background + self.context.set_source_rgb(1, 1, 1) + self.context.fill() + #draw a black border + self.context.set_source_rgb(0, 0, 0) + self.context.set_line_width(1) + self.context.stroke() + + + def draw_hor_div(self): + #draw horizontal grid with 10 div. and 10 sub-div + for i in range(20): + y = (self.rect.height / 20.0) * float(i) + #place correctly the vector + self.context.move_to(self.rect.width, y) + if i % 2 == 1: + #Minor div: no text + self.context.set_source_rgb(0.1, 0.1, 0.1) + self.context.set_line_width(0.3) + self.context.line_to(0, y) + else: + #Major div: place text + self.context.set_source_rgb(0, 0, 0) + self.context.set_line_width(0.4) + self.context.line_to(0, y) + self.context.set_source_rgb(0.15, 0.15, 0.15) + if i > 10: + self.context.show_text('-'+str((i - 10.0)/10.0)) + elif i < 10: + self.context.show_text(str((10.0 - i)/10.0)) + else: + self.context.show_text('0') + self.context.stroke() + + def draw_threshold(self, value, color): + threshold = float((value * self.rect.height/2) / 100) + threshold1 = self.rect.height / 2 + threshold + threshold2 = self.rect.height / 2 - threshold + if color == 1: + self.context.set_source_rgb(0.5, 0.5, 0) + elif color == 2: + self.context.set_source_rgb(0, 0.5, 0.5) + else: + self.context.set_source_rgb(0.5, 0.5, 0.5) + self.context.set_line_width(0.8) + self.context.move_to(self.rect.width, threshold1) + self.context.line_to(0, threshold1) + self.context.move_to(self.rect.width, threshold2) + self.context.line_to(0, threshold2) + self.context.stroke() + + def draw_ver_div(self): + #draw vertical division + #create a tab with the wanted divisions + temp_tab = [0.25, 0.5, 0.75] + for i in range(3): + self.context.set_source_rgb(0.2, 0.2, 0.2) + self.context.set_line_width(0.6) + #place correctly the vector + self.context.move_to(self.rect.width * temp_tab[i], 0) + #trace a line + self.context.line_to(self.rect.width * temp_tab[i], self.rect.height) + #replace the vector to draw text + self.context.move_to(self.rect.width * temp_tab[i], self.rect.height - 5) + #determine the time labels + txt = ((0.1 * self.measure.sample) - (0.1 * self.measure.sample * temp_tab[i])) + txt = str('%.2f' % txt) + self.context.show_text(str(txt) + " sec.") + self.context.stroke() + + def draw_curve(self): + coeff_y = float(self.rect.height / self.measure.RANGE) + coeff_x = float(self.rect.width / (self.measure.sample - 1)) + + self.fill(coeff_x, coeff_y) + + #and trace the curce + self.context.set_line_width(0.6) + self.context.set_source_rgb(0.9, 0.6,0) + self.context.move_to(self.rect.x - 2, self.rect.height + 2) + self.context.line_to(self.rect.x, self.rect.height - (self.measure.val_table_pos[0] * coeff_y)) + for i, val in enumerate(self.measure.val_table_pos): + self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height - ((self.measure.RANGE/2 + val) * coeff_y)) + self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height + 5) + + self.context.move_to(self.rect.x - 2, self.rect.height + 2) + self.context.line_to(self.rect.x, self.rect.height - (self.measure.val_table_pos[0] * coeff_y)) + for i, val in enumerate(self.measure.val_table_pos): + self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height - ((self.measure.RANGE/2 - val) * coeff_y)) + self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height + 5) + self.context.stroke() + + + + def fill(self, coeff_x, coeff_y): + #determine the coefficients to adjust the curve in the window space + self.context.move_to(self.rect.x - 2, self.rect.height / 2) + for i, val in enumerate(self.measure.val_table_pos): + self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height - ((self.measure.RANGE/2 + val) * coeff_y)) + self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height/2) + self.context.close_path() + self.context.set_source_rgba(0.9, 0.6, 0, 0.2) + self.context.fill() + + self.context.move_to(self.rect.x - 2, self.rect.height / 2) + for i, val in enumerate(self.measure.val_table_pos): + self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height - ((self.measure.RANGE/2 - val) * coeff_y)) + self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height/2) + self.context.close_path() + self.context.fill() + + +class Sound_Measure(object): + def __init__(self, sample): + self.rate = 0.1 + self.sample = sample + self.RANGE = 1024.0 + self.sample_backup = self.sample + self.val_table_pos = [0] * int(self.sample) + + self.dog_threshold = 0 + self.spy_threshold = 0 + self.dog_enabled = False + self.spy_enabled = False + self.RANGE = 1024.0 + self.notify = False + self.actuator = False + + self.__capture_buffer = [] + self.__temp_buffer = [] + self.capture_idx = tux.micro.on_buffer.connect(self.__on_capture_buffer) + self.__capture_path = '' + self.num = 1 + self.__capture_start = False + self.__stop = False + self.__delay_to_stop = time.time() + self.__write_mutex = threading.Lock() + self.__capture_mutex = threading.Lock() + self.__time = '' + self.__duration = 0.0 + self.__start_flag = False + + + ########################################################### + # + # Events control + # + ########################################################### + def event_control(self): + if self.spy_enabled and self.__capture_start == False and self.actuator == False: + if self.Increase_control(self.spy_threshold): + self.record_sound() + + if self.dog_enabled and self.actuator == False: + if self.Increase_control(self.dog_threshold): + self.notify = True + self.actuator = True + + + ########################################################### + # + # Threshold control + # + ########################################################### + def Increase_control(self, value): + val_act = ((self.val_table_pos[len(self.val_table_pos)-1])*100) / (self.RANGE/2) + val_prev = ((self.val_table_pos[len(self.val_table_pos)-2])*100) / (self.RANGE/2) + if val_prev <= value and val_act > value: + return True + + ########################################################### + # + # Acquire & Recording + # + ########################################################### + def on_sound_level(self, args): + try: + if self.sample_backup != self.sample: + self.sample = self.sample_backup + self.val_table_pos = [512] * int(self.sample) + + val = (args[1] + args[2] + args[3] + args[4]) + self.val_table_pos.append(val) + self.val_table_pos.pop(0) + self.graph_measure.refresh() + self.event_control() + except: + print sys.exc_info() + + + def __on_capture_buffer(self, buffer): + if self.__write_mutex.locked(): + return + + self.__write_mutex.acquire() + + if self.__capture_start == False: + for val in buffer: + self.__temp_buffer.append(val) + if len(self.__temp_buffer) > 1600: + for i in range(800): + self.__temp_buffer.pop(0) + + else: + if self.__start_flag: + self.__start_flag = False + self.__capture_buffer = self.__temp_buffer + self.__temp_buffer = [] + + for val in buffer: + self.__capture_buffer.append(val) + + val_act = ((self.val_table_pos[len(self.val_table_pos)-1])*100) / (self.RANGE/2) + if val_act < self.spy_threshold and self.__stop == False: + self.__delay_to_stop = time.time() + 0.2 + self.__stop = True + elif val_act > self.spy_threshold and self.__stop: + self.__stop = False + + if (time.time() >= self.__delay_to_stop) and self.__stop: + self.__stop = False + self.__capture_start = False + time.sleep(0.2) + self.__write_capture() + duration = time.time() - self.__duration + self.refresh_treeview([self.__time, 'record%d.wav'%self.num, '%.1f sec.'%duration]) + self.num += 1 + self.capture_buffer = [] + + self.__write_mutex.release() + + def __write_capture(self): + freqech = 8000 + sound_str = "" + for val in self.__capture_buffer: + sound_str += chr(val) + + wavfile = wave.open(self.__capture_path, 'w') + wavfile.setparams((1, 1, freqech , len(self.__capture_buffer), 'NONE', 'not compressed')) + wavfile.writeframes(sound_str) + wavfile.close() + + + def record_sound(self): + self.__capture_buffer = [] + if self.__capture_start: + return + act_time = time.localtime() + act_time = [act_time[3], act_time[4], act_time[5]] + if act_time[2]<10: + act_time[2] = '0%d'%act_time[2] + else: + act_time[2] = str(act_time[2]) + if act_time[1]<10: + act_time[1] = '0%d'%act_time[1] + else: + act_time[1] = str(act_time[1]) + if act_time[0]<10: + act_time[0] = '0%d'%act_time[0] + else: + act_time[0] = str(act_time[0]) + + self.__time = act_time[0] + ':' + act_time[1] + ':' + act_time[2] + self.__duration = time.time() + self.__capture_path = '/tmp/__tux-record%d.wav'%self.num + self.__capture_start = True + self.__start_flag = True + + + + Deleted: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/Sound_class.py =================================================================== --- software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/Sound_class.py 2007-12-05 16:14:55 UTC (rev 750) +++ software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/Sound_class.py 2007-12-05 16:28:39 UTC (rev 751) @@ -1,379 +0,0 @@ -import gtk -import sys -import time -import os -import threading -import thread -import math -sys.path.append('/opt/tuxdroid/api/python') -from tux import * - -class Sound_Graph(gtk.DrawingArea): - def __init__(self): - super(Sound_Graph, self).__init__() - self.connect("expose_event", self.expose) - self.context = None - - def expose(self, widget, event): - self.context = widget.window.cairo_create() - self.context.rectangle(event.area.x, event.area.y, - event.area.width, event.area.height) - self.context.clip() - self.draw() - return False - - def refresh(self): - if self.window: - width,height = self.window.get_size() - self.window.invalidate_rect(gtk.gdk.Rectangle(0,0,width,height),False) - - def draw(self): - self.rect = self.get_allocation() - - self.draw_space() - self.draw_hor_div() - self.draw_ver_div() - if self.measure_graph.dog_threshold: - self.draw_threshold(self.measure_graph.dog_threshold, 1) - if self.measure_graph.spy_threshold: - self.draw_threshold(self.measure_graph.spy_threshold, 2) - self.draw_curve() - - def draw_space(self): - #draw axes - #draw a rectangle in the window area - self.context.rectangle(self.rect.x, self.rect.y, self.rect.width, self.rect.height) - #set a white background - self.context.set_source_rgb(1, 1, 1) - self.context.fill() - #draw a black border - self.context.set_source_rgb(0, 0, 0) - self.context.set_line_width(1) - self.context.stroke() - - - def draw_hor_div(self): - #draw horizontal grid with 10 div. and 10 sub-div - for i in range(20): - y = (self.rect.height / 20.0) * float(i) - #place correctly the vector - self.context.move_to(self.rect.width, y) - if i % 2 == 1: - #Minor div: no text - self.context.set_source_rgb(0.1, 0.1, 0.1) - self.context.set_line_width(0.3) - self.context.line_to(0, y) - else: - #Major div: place text - self.context.set_source_rgb(0, 0, 0) - self.context.set_line_width(0.4) - self.context.line_to(0, y) - self.context.set_source_rgb(0.15, 0.15, 0.15) - if i > 10: - self.context.show_text('-'+str((i - 10.0)/10.0)) - elif i < 10: - self.context.show_text(str((10.0 - i)/10.0)) - else: - self.context.show_text('0') - self.context.stroke() - - def draw_threshold(self, value, color): - threshold = float((value * self.rect.height/2) / 100) - threshold1 = self.rect.height / 2 + threshold - threshold2 = self.rect.height / 2 - threshold - if color == 1: - self.context.set_source_rgb(0.5, 0.5, 0) - elif color == 2: - self.context.set_source_rgb(0, 0.5, 0.5) - else: - self.context.set_source_rgb(0.5, 0.5, 0.5) - self.context.set_line_width(0.8) - self.context.move_to(self.rect.width, threshold1) - self.context.line_to(0, threshold1) - self.context.move_to(self.rect.width, threshold2) - self.context.line_to(0, threshold2) - self.context.stroke() - - def draw_ver_div(self): - #draw vertical division - #create a tab with the wanted divisions - temp_tab = [0.25, 0.5, 0.75] - for i in range(3): - self.context.set_source_rgb(0.2, 0.2, 0.2) - self.context.set_line_width(0.6) - #place correctly the vector - self.context.move_to(self.rect.width * temp_tab[i], 0) - #trace a line - self.context.line_to(self.rect.width * temp_tab[i], self.rect.height) - #replace the vector to draw text - self.context.move_to(self.rect.width * temp_tab[i], self.rect.height - 5) - #determine the time labels - txt = ((0.1 * self.measure_graph.sample) - (0.1 * self.measure_graph.sample * temp_tab[i])) - txt = str('%.2f' % txt) - self.context.show_text(str(txt) + " sec.") - self.context.stroke() - - def draw_curve(self): - coeff_y = float(self.rect.height / self.measure_graph.RANGE) - coeff_x = float(self.rect.width / (self.measure_graph.sample - 1)) - - self.fill(coeff_x, coeff_y) - - #and trace the curce - self.context.set_line_width(0.6) - self.context.set_source_rgb(0.9, 0.6, 0.5) - self.context.move_to(self.rect.x - 2, self.rect.height + 2) - self.context.line_to(self.rect.x, self.rect.height - (self.measure_graph.val_table_pos[0] * coeff_y)) - temp_event = 0 - for i, val in enumerate(self.measure_graph.val_table_pos): - self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height - (val * coeff_y)) - self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height + 5) - - self.context.move_to(self.rect.x - 2, self.rect.height + 2) - self.context.line_to(self.rect.x, self.rect.height - (self.measure_graph.val_table_neg[0] * coeff_y)) - temp_event = 0 - for i, val in enumerate(self.measure_graph.val_table_neg): - self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height - (val * coeff_y)) - self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height + 5) - self.context.stroke() - - - - def fill(self, coeff_x, coeff_y): - #determine the coefficients to adjust the curve in the window space - self.context.move_to(self.rect.x - 2, self.rect.height / 2) - for i, val in enumerate(self.measure_graph.val_table_pos): - self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height - (val * coeff_y)) - self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height/2) - self.context.close_path() - self.context.set_source_rgba(0.9, 0.6, 0.5, 0.2) - self.context.fill() - - self.context.move_to(self.rect.x - 2, self.rect.height / 2) - for i, val in enumerate(self.measure_graph.val_table_neg): - self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height - (val * coeff_y)) - self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height/2) - self.context.close_path() - self.context.fill() - - -class Sound_Measure(object): - def __init__(self, sample): - self.rate = 0.1 - self.sample = sample - self.RANGE = 1024.0 - self.sample_backup = self.sample - self.val_table_pos = [int(self.RANGE / 2)] * int(self.sample) - self.val_table_neg = [int(self.RANGE / 2)] * int(self.sample) - self.test_tab = [0] - self.disable_event = False - - self.dog_threshold = 0 - self.spy_threshold = 0 - self.tick = time.time() + 1 - self.average = 0 - self.count = 0 - self.GUI_on = False - self.start_flag = True - self.wait = time.time() + 2.0 - self.RANGE = 1024.0 - self.__on_sound_mutex = threading.Lock() - self.__timeout_mutex = threading.Lock() - - - ########################################################### - # - # Events control - # - ########################################################### - def event_control(self): - if self.GUI_on: - self.__tab = self.test_tab - - for i in range (len(self.__tab)): - val = 50 - self.Threshold_control(i, val) - #self.Change_control(i, val) - - self.test_tab = self.__tab - - - # To prevent notifications at startup - if self.start_flag == True or self.disable_event == True: - self.start_flag = False - self.test_tab[0][7] = False - self.disable_event = False - self.start_flag = False - for i in range (len(self.event_tab)): - self.event_tab[i][7] = False - - - - - ########################################################### - # - # Threshold control - # - ########################################################### - def Threshold_control(self, index, val): - if self.__tab[index][1] == 1: - if self.__tab[index][7] != True: - if self.__tab[index][2] == 0: - #Increasing threshold control - if self.Increase_control(val) == True: - self.__tab[index][7] = True - elif self.__tab[index][2] == 1: - #Decreasing threshold control - if self.Decrease_control(val) == True: - self.__tab[index][7] = True - elif self.__tab[index][2] == 2: - #Both direction theshold control - if self.Both_control(val) == True: - self.__tab[index][7] = True - - def Increase_control(self, value): - print 'enter' - val_act = ((self.val_table_pos[len(self.val_table_pos)-1]-512)*100) / (self.RANGE/2) - val_prev = ((self.val_table_pos[len(self.val_table_pos)-2]-512)*100) / (self.RANGE/2) - if val_prev <= value and val_act > value: - print 'OK' - return True - - - def Decrease_control(self, val): - val_act = (self.val_table_pos[len(self.val_table_pos)-1]*100) / (self.RANGE/2) - val_prev = (self.val_table_pos[len(self.val_table_pos)-2]*100) / (self.RANGE/2) - if val_prev >= val and val_act < val: - return True - - def Both_control(self, val): - val_act = (self.val_table_pos[int(len(self.val_table_pos)-1)]*100) / (self.RANGE/2) - val_prev = (self.val_table_pos[int(len(self.val_table_pos)-2)]*100) / (self.RANGE/2) - if val_prev <= val and val_act > val or val_prev >= val and val_act < val: - return True - - - ########################################################### - # - # Changes control - # - ########################################################### - def Change_control(self, i, val): - #Changements control - if self.__tab[i][1] == 0: - pts_per_sec = self.sample / (self.rate * self.sample) - time = int(self.__tab[i][4] * pts_per_sec) - if self.__tab[i][7] != True: - # Drop change part : - if self.__tab[i][2] == 0: - if self.Drop_control(time, val, self.__tab[i][8], i) == True: - self.__tab[i][7] = True - # Raise change part - if self.__tab[i][2] == 1: - if self.Raise_control(time, val, self.__tab[i][8], i) == True: - self.__tab[i][7] = True - ''' - # Drop and Raise change - if self.__tab[i][2] == 2: - if self.ChangeD_control(time, val, self.__tab[i][8], i) == True: - self.__tab[i][7] = True - # Raise and Drop change - if self.__tab[i][2] == 3: - if self.ChangeU_control(time, val, self.__tab[i][8], i) == True: - self.__tab[i][7] = True - ''' - - - def Drop_control(self, time, val, timeout, index): - #timeout control : to prevent multiple notifications with the same event - if timeout != 0: - timeout -= 1 - init_val = len(self.val_table_pos) - 1 - int(time) + timeout - maximum = max(self.val_table_pos[init_val:len(self.val_table_pos)-1]) - - if maximum >= self.val_table_pos[len(self.val_table_pos)-1] + ((val/100)*self.RANGE): - self.__tab[index][8] = int(time) - return True - else: - self.__tab[index][8] = timeout - - def Raise_control(self, time, val, timeout, index): - if timeout != 0: - timeout -= 1 - init_val = len(self.val_table_pos) - 1 - int(time) + timeout - minimum = min(self.val_table_pos[init_val:(len(self.val_table_pos)-1)]) - if minimum <= self.val_table_pos[len(self.val_table_pos)-1] - ((val/100)*self.RANGE): - self.__tab[index][8] = int(time) - return True - else: - self.__tab[index][8] = timeout - - - ########################################################### - # - # Test functions - # - ########################################################### - def test_notification(self): - if self.test_tab[0][7] == True: - self.test_tab[0][7] = False - if self.test_tab[0][5] == True: - path = self.test_tab[0][6] - path = path.replace('%20', ' ') - if os.path.isfile(path) and os.path.exists(path): - path = self.test_tab[0][6] - path = "'%s'" % path - tux.sys.shell_free(path) - elif self.test_tab[0][1] == 0: - thread.start_new_thread(self.test_default_behavior, (self.changetext,)) - elif self.test_tab[0][1] == 1: - thread.start_new_thread(self.test_default_behavior, (self.thresholdtext,)) - - def test_default_behavior(self, txt): - tux.cmd.mouth_open() - tux.tts.speak(txt) - tux.cmd.mouth_close() - - ########################################################### - # - # Acquire - # - ########################################################### - def on_sound_level(self, args): - if self.__on_sound_mutex.locked(): - return - self.__on_sound_mutex.acquire() - - if self.sample_backup != self.sample: - self.sample = self.sample_backup - self.val_table_pos = [] * int(self.sample) - self.val_table_neg = [int(self.RANGE/2)] * int(self.sample) - - - val = (args[1] + args[2] + args[3] + args[4]) - print val - self.val_table_pos.append(self.RANGE/2 + val) - self.val_table_neg.append(self.RANGE/2 - val) - self.val_table_pos.pop(0) - self.val_table_neg.pop(0) - - - try: - #If widget GUI is displayed, refresh the graph. - if self.GUI_on: - self.graph_measure.refresh() - except: - print 'graph' - print sys.exc_info() - #And check for events - try: - self.event_control() - except: - print 'events' - print sys.exc_info() - self.__on_sound_mutex.release() - - - - - Modified: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/init.pyp =================================================================== --- software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/init.pyp 2007-12-05 16:14:55 UTC (rev 750) +++ software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/init.pyp 2007-12-05 16:28:39 UTC (rev 751) @@ -1,25 +1 @@ -sys.path.append(_me.get_path('root') + '/Scripts/Python') -from Sound_class import Sound_Measure - -measure = Sound_Measure(float(_me.get_param('Sample'))) -_me.set_param('measure', measure) - -# update the sample and rate values - -measure.sample = float(_me.get_param('Sample')) -measure.sample_backup = measure.sample - -measure.test_tab = _me.get_param('test_tab') -monitor_id = tux.monitoring.insert(0xF0, measure.on_sound_level) -_me.set_param('monitor_id', monitor_id) -tux.micro.on() - - -def destroy(): - tux.monitoring.remove(_me.get_param('monitor_id')) - -_me.insert_funct('destroy', destroy) - - - - +pass Modified: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/main.pyp =================================================================== --- software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/main.pyp 2007-12-05 16:14:55 UTC (rev 750) +++ software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/main.pyp 2007-12-05 16:28:39 UTC (rev 751) @@ -1,5 +1,28 @@ -def update_informations(): - pass +import os + +def on_standby(): + gdg_dict = _me.get_param('dict') + for keys in gdg_dict: + gadgets[keys].notify.set_active(gdg_dict[keys]) + tux.micro.off() + tux.cmd.mouth_close() + tux.event.on_remote_bt[K_STANDBY] = None + tux.monitoring.remove(_me.get_param('monitor_id')) + tux.micro.on_buffer.disconnect(_me.get_param('buffer_idx')) + _me.gui('widget').hide_from_main() + _me.exit_main_loop() +gdg_dict = {} +for Gdgname in gadgets.keys(): + if Gdgname != 'sound_monitor' and Gdgname != 'Manager': + gdg_dict[Gdgname] = gadgets[Gdgname].get_var('notified') + gadgets[Gdgname].notify.set_active(False) + + +_me.set_param('dict', gdg_dict) +tux.cmd.mouth_open() +tux.event.on_remote_bt[K_STANDBY] = on_standby +_me.gui('widget').show_from_main() +_me.run_main_loop() Modified: software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/notify.pyp =================================================================== --- software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/notify.pyp 2007-12-05 16:14:55 UTC (rev 750) +++ software/gadgets/sound_monitor/trunk/audio_monitor/Scripts/Python/notify.pyp 2007-12-05 16:28:39 UTC (rev 751) @@ -1,8 +1,27 @@ -def notify_checker(): - return False +def notify_checker(): + if _me.get_param('measure'): + measure = _me.get_param('measure') + if measure.notify: + measure.notify = False + return True + else: + return False + else: + return False - - def notify_actuator(): - pass + measure = _me.get_param('measure') + if _me.get_param('chkDogDefault') == False: + tux.cmd.wings_on_free(10) + for i in range(5): + tux.cmd.sound_play(14) + tux.sys.wait(0.7) + tux.sys.wait(1) + else: + path = _me.get_param('dogBehavior') + if os.path.exists(path) and os.path.isfile(path): + tux.sys.shell(path) + measure.actuator = False + + Modified: software/gadgets/sound_monitor/trunk/audio_monitor/Strings/fr_ALL.xml =================================================================== --- software/gadgets/sound_monitor/trunk/audio_monitor/Strings/fr_ALL.xml 2007-12-05 16:14:55 UTC (rev 750) +++ software/gadgets/sound_monitor/trunk/audio_monitor/Strings/fr_ALL.xml 2007-12-05 16:28:39 UTC (rev 751) @@ -1,21 +1,24 @@ <?xml version='1.0' encoding='UTF-8'?> <strings> <at_gui_widget_lblSpyLevel type='str'>Spy level</at_gui_widget_lblSpyLevel> - <at_gui_widget_cbbRecord type='str'>Recorded files</at_gui_widget_cbbRecord> - <at_gui_widget_cbbDog type='str'>Dog mode</at_gui_widget_cbbDog> + <Play type='str'>Lecture</Play> + <at_gui_widget_cbbRecord type='str'>Sons enregistrés</at_gui_widget_cbbRecord> + <at_gui_widget_cbbDog type='str'>Chien de garde</at_gui_widget_cbbDog> <name_to_read type='str'>Moniteur de son</name_to_read> <at_gui_conf_label6 type='str'>Cancel</at_gui_conf_label6> <at_gui_conf_label5 type='str'>Accept</at_gui_conf_label5> - <at_gui_widget_chkDog type='str'>Dog mode enable</at_gui_widget_chkDog> + <at_gui_widget_chkDog type='str'>Activer le mode chien de garde</at_gui_widget_chkDog> <at_gui_widget_lblDogLevel type='str'>Dog level</at_gui_widget_lblDogLevel> - <at_gui_widget_chkSpyRecord type='str'>Enable recording</at_gui_widget_chkSpyRecord> + <Duration type='str'>Durée</Duration> + <Time type='str'>Heure</Time> <at_gui_conf_label13 type='str'>Delay (sec) :</at_gui_conf_label13> <at_gui_conf_label12 type='str'>Updates</at_gui_conf_label12> - <at_gui_widget_chkDogBehavior type='str'>Enable Dog notification</at_gui_widget_chkDogBehavior> + <File type='str'>Fichier</File> + <at_gui_widget_chkDogDefault type='str'>Utiliser un script :</at_gui_widget_chkDogDefault> <help_text type='str'> </help_text> - <at_gui_widget_cbbSpy type='str'>Spy mode</at_gui_widget_cbbSpy> + <at_gui_widget_cbbSpy type='str'>Mode espion</at_gui_widget_cbbSpy> <speaker_name type='str'>Bruno8k</speaker_name> - <at_gui_widget_chkDogDefault type='str'>Default Behavior</at_gui_widget_chkDogDefault> - <at_gui_widget_chkSpy type='str'>Enable the spy mode</at_gui_widget_chkSpy> + <vr_Sound type='str'>Sound</vr_Sound> + <at_gui_widget_chkSpy type='str'>Activer le mode espion</at_gui_widget_chkSpy> </strings> Modified: software/gadgets/sound_monitor/trunk/audio_monitor/settings.xml =================================================================== --- software/gadgets/sound_monitor/trunk/audio_monitor/settings.xml 2007-12-05 16:14:55 UTC (rev 750) +++ software/gadgets/sound_monitor/trunk/audio_monitor/settings.xml 2007-12-05 16:28:39 UTC (rev 751) @@ -1,9 +1,15 @@ <?xml version='1.0' encoding='UTF-8'?> <settings> <parameters> + <spinDog type='int'>30</spinDog> + <chkDogBehavior type='bool'>False</chkDogBehavior> + <MainScript type='str'>None</MainScript> + <chkSpy type='bool'>False</chkSpy> + <chkDog type='bool'>True</chkDog> <Sample type='float'>600.0</Sample> - <test_tab type='list'>[[1, 0, 0, 0.10000000000000001, 20.0, True, None, False, 0]]</test_tab> - <MainScript type='str'>None</MainScript> + <chkSpyRecord type='bool'>False</chkSpyRecord> + <chkDogDefault type='bool'>False</chkDogDefault> + <spinSpy type='int'>40</spinSpy> </parameters> <general> <have_settings_part type='bool'>True</have_settings_part> @@ -19,10 +25,10 @@ </gui_state> <language type='str'>en_US</language> <notified type='bool'>True</notified> - <notify_delay type='int'>1</notify_delay> + <notify_delay type='int'>10</notify_delay> <framework_version type='str'>0.0.0</framework_version> <menu_active type='bool'>True</menu_active> - <have_widget_part type='bool'>True</have_widget_part> + <have_widget_part type='bool'>False</have_widget_part> <speaker type='int'>3</speaker> <pitch type='int'>100</pitch> <have_main_part type='bool'>True</have_main_part> Modified: software/gadgets/sound_monitor/trunk/audio_monitor/strings.xml =================================================================== --- software/gadgets/sound_monitor/trunk/audio_monitor/strings.xml 2007-12-05 16:14:55 UTC (rev 750) +++ software/gadgets/sound_monitor/trunk/audio_monitor/strings.xml 2007-12-05 16:28:39 UTC (rev 751) @@ -1,21 +1,24 @@ <?xml version='1.0' encoding='UTF-8'?> <strings> <at_gui_widget_lblSpyLevel type='str'>Level</at_gui_widget_lblSpyLevel> + <Play type='str'>Play</Play> <at_gui_widget_cbbRecord type='str'>Recorded files</at_gui_widget_cbbRecord> - <at_gui_widget_cbbDog type='str'>Dog mode</at_gui_widget_cbbDog> + <at_gui_widget_cbbDog type='str'>Guard dog mode</at_gui_widget_cbbDog> <name_to_read type='str'>Audio monitor</name_to_read> <at_gui_conf_label6 type='str'>Cancel</at_gui_conf_label6> <at_gui_conf_label5 type='str'>Accept</at_gui_conf_label5> - <at_gui_widget_chkDog type='str'>Enable the dog mode</at_gui_widget_chkDog> + <at_gui_widget_chkDog type='str'>Enable the guard dog mode</at_gui_widget_chkDog> <at_gui_widget_lblDogLevel type='str'>Level</at_gui_widget_lblDogLevel> - <at_gui_widget_chkSpyRecord type='str'>Enable recording</at_gui_widget_chkSpyRecord> + <Duration type='str'>Duration</Duration> + <Time type='str'>Hour</Time> <at_gui_conf_label13 type='str'>Delay (sec) :</at_gui_conf_label13> <at_gui_conf_label12 type='str'>Updates</at_gui_conf_label12> - <at_gui_widget_chkDogBehavior type='str'>Enable behavior</at_gui_widget_chkDogBehavior> + <File type='str'>File</File> + <at_gui_widget_chkSpy type='str'>Enable the spy mode</at_gui_widget_chkSpy> <help_text type='str'> </help_text> <at_gui_widget_cbbSpy type='str'>Spy mode</at_gui_widget_cbbSpy> - <at_gui_widget_chkSpy type='str'>Enable the spy mode</at_gui_widget_chkSpy> - <at_gui_widget_chkDogDefault type='str'>Default behavior</at_gui_widget_chkDogDefault> + <vr_Sound type='str'>Sound</vr_Sound> + <at_gui_widget_chkDogDefault type='str'>Use an external script</at_gui_widget_chkDogDefault> <speaker_name type='str'>Ryan8k</speaker_name> </strings> Modified: software/gadgets/sound_monitor/trunk/audio_monitor.tgf =================================================================== (Binary files differ) |