[tuxdroid-svn] r601 - in software/gadgets/battery_monitor/trunk: . Battery_monitor_svn Battery_moni
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-10-11 07:44:29
|
Author: Paul_R Date: 2007-10-11 09:44:02 +0200 (Thu, 11 Oct 2007) New Revision: 601 Modified: software/gadgets/battery_monitor/trunk/Battery_monitor.tgf software/gadgets/battery_monitor/trunk/Battery_monitor_svn/Scripts/Python/Battery_class.py software/gadgets/battery_monitor/trunk/Battery_monitor_svn/about.xml software/gadgets/battery_monitor/trunk/Battery_monitor_svn/settings.xml software/gadgets/battery_monitor/trunk/Battery_monitor_svn/strings.xml Log: * Split the draw function's in the Graph class into smaller sub-functions. Modified: software/gadgets/battery_monitor/trunk/Battery_monitor.tgf =================================================================== (Binary files differ) Modified: software/gadgets/battery_monitor/trunk/Battery_monitor_svn/Scripts/Python/Battery_class.py =================================================================== --- software/gadgets/battery_monitor/trunk/Battery_monitor_svn/Scripts/Python/Battery_class.py 2007-10-10 15:04:47 UTC (rev 600) +++ software/gadgets/battery_monitor/trunk/Battery_monitor_svn/Scripts/Python/Battery_class.py 2007-10-11 07:44:02 UTC (rev 601) @@ -19,7 +19,7 @@ self.context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) self.context.clip() - self.draw(self.context) + self.draw() return False def refresh(self): @@ -27,92 +27,110 @@ width,height = self.window.get_size() self.window.invalidate_rect(gtk.gdk.Rectangle(0,0,width,height),False) - def draw(self, context): - rect = self.get_allocation() - #draw axes + def draw(self): + self.rect = self.get_allocation() + + self.draw_space() + self.draw_hor_div() + self.draw_ver_div() + self.draw_label() + self.draw_curve() + + def draw_space(self): + #draw axes #draw a rectangle in the window area - context.rectangle(rect.x, rect.y, rect.width, rect.height) + self.context.rectangle(self.rect.x, self.rect.y, self.rect.width, self.rect.height) #set a white background - context.set_source_rgb(1, 1, 1) - context.fill() + self.context.set_source_rgb(1, 1, 1) + self.context.fill() #draw a black border - context.set_source_rgb(0, 0, 0) - context.set_line_width(1) - context.stroke() - + 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 = (rect.height / 20.0) * float(i) + y = (self.rect.height / 20.0) * float(i) #place correctly the vector - context.move_to(rect.width, y) + self.context.move_to(self.rect.width, y) if i % 2 == 1: #Minor div: no text - context.set_source_rgb(0.2, 0.2, 0.2) - context.set_line_width(0.4) - context.line_to(0, y) + self.context.set_source_rgb(0.2, 0.2, 0.2) + self.context.set_line_width(0.4) + self.context.line_to(0, y) else: #Major div: place text - context.set_source_rgb(0, 0, 0) - context.set_line_width(0.6) - context.line_to(0, y) - context.set_source_rgb(0.2, 0.2, 0.2) + self.context.set_source_rgb(0, 0, 0) + self.context.set_line_width(0.6) + self.context.line_to(0, y) + self.context.set_source_rgb(0.2, 0.2, 0.2) if i != 18: - context.show_text(str(6.5 - (0.125 * i))+' V') - context.stroke() - - #draw vertical division + self.context.show_text(str(6.5 - (0.125 * i))+' V') + 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): - context.set_source_rgb(0.2, 0.2, 0.2) - context.set_line_width(0.6) + self.context.set_source_rgb(0.2, 0.2, 0.2) + self.context.set_line_width(0.6) #place correctly the vector - context.move_to(rect.width * temp_tab[i], 0) + self.context.move_to(self.rect.width * temp_tab[i], 0) #trace a line - context.line_to(rect.width * temp_tab[i], rect.height) + self.context.line_to(self.rect.width * temp_tab[i], self.rect.height) #replace the vector to draw text - context.move_to(rect.width * temp_tab[i], rect.height - 5) + self.context.move_to(self.rect.width * temp_tab[i], self.rect.height - 5) #determine the time labels - context.show_text(str((self.measure_graph.rate * self.measure_graph.sample) - ((self.measure_graph.rate) * + self.context.show_text(str((self.measure_graph.rate * self.measure_graph.sample) - ((self.measure_graph.rate) * self.measure_graph.sample * temp_tab[i])) + " sec.") - context.stroke() + self.context.stroke() + def draw_label(self): #display sample and rate #move the vector in the bottom - context.move_to(5, rect.height - 10) + self.context.move_to(5, self.rect.height - 10) #display the rate - context.show_text("rate = "+str(self.measure_graph.rate)+" sec.") - context.move_to(5, rect.height - 20) + self.context.show_text("rate = "+str(self.measure_graph.rate)+" sec.") + self.context.move_to(5, self.rect.height - 20) #and the samples - context.show_text("samples = "+str(self.measure_graph.sample)) - context.stroke() - - #determine the coefficients to adjust the curve in the window space - coeff_y = float(rect.height / 340.00) - coeff_x = float(rect.width / (self.measure_graph.sample - 1)) + self.context.show_text("samples = "+str(self.measure_graph.sample)) + self.context.stroke() - #Fill... - context.set_line_width(0.6) - context.set_source_rgb(0, 0, 1) - context.move_to(rect.x - 2, rect.height + 2) - context.line_to(rect.x, rect.height - (self.measure_graph.val_table[0] * coeff_y)) - for i, val in enumerate(self.measure_graph.val_table): - context.line_to(rect.x + ((i) * coeff_x), rect.height - (val * coeff_y)) - context.line_to(rect.x + ((i) * coeff_x), rect.height + 5) - context.close_path() - context.set_source_rgba(1.0, 0, 0, 0.2) - context.fill() + def draw_curve(self): + coeff_y = float(self.rect.height / 340.00) + coeff_x = float(self.rect.width / (self.measure_graph.sample - 1)) + self.fill(coeff_x, coeff_y) + #and trace the curce - context.set_line_width(0.6) - context.set_source_rgb(1, 0, 0) - context.move_to(rect.x - 2, rect.height + 2) - context.line_to(rect.x, rect.height - (self.measure_graph.val_table[0] * coeff_y)) + self.context.set_line_width(0.6) + self.context.set_source_rgb(1, 0, 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_graph.val_table[0] * coeff_y)) for i, val in enumerate(self.measure_graph.val_table): - context.line_to(rect.x + ((i) * coeff_x), rect.height - (val * coeff_y)) - context.line_to(rect.x + ((i) * coeff_x), rect.height + 5) - context.stroke() + 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 + #Fill... + self.context.set_line_width(0.6) + self.context.set_source_rgb(0, 0, 1) + 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[0] * coeff_y)) + for i, val in enumerate(self.measure_graph.val_table): + 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.close_path() + self.context.set_source_rgba(1.0, 0, 0, 0.2) + self.context.fill() + + class Measure(): def __init__(self): #Initial value @@ -326,33 +344,30 @@ # ########################################################### def on_battery_level(self, args): - try: - print 'battery received' - self.__on_battery_mutex.acquire() - self.average += (args[0] * 256) + args[1] - self.count += 1 - if self.sample_backup != self.sample: - self.sample = self.sample_backup - self.val_table = [-2] * int(self.sample) - if self.rate_backup != self.rate: - self.rate_has_changed() + self.__on_battery_mutex.acquire() + self.average += (args[0] * 256) + args[1] + self.count += 1 + if self.sample_backup != self.sample: + self.sample = self.sample_backup + self.val_table = [-2] * int(self.sample) + if self.rate_backup != self.rate: + self.rate_has_changed() - if self.tick <= time.time(): - print self.average - self.tick = time.time() + self.rate - val = self.average / self.count - val = val - 530 - self.val_table.append(val) - self.val_table.pop(0) - self.average = 0 - self.count = 0 - if self.GUI_on: - self.graph_measure.refresh() - self.event_control() - self.__on_battery_mutex.release() - except: - print sys.exc_info() + if self.tick <= time.time(): + self.tick = time.time() + self.rate + val = self.average / self.count + val = val - 530 + self.val_table.append(val) + self.val_table.pop(0) + self.average = 0 + self.count = 0 + if self.GUI_on: + self.graph_measure.refresh() + self.event_control() + self.__on_battery_mutex.release() + + def rate_has_changed(self): self.rate = self.rate_backup pts_per_sec = self.sample / (self.rate * self.sample) Modified: software/gadgets/battery_monitor/trunk/Battery_monitor_svn/about.xml =================================================================== --- software/gadgets/battery_monitor/trunk/Battery_monitor_svn/about.xml 2007-10-10 15:04:47 UTC (rev 600) +++ software/gadgets/battery_monitor/trunk/Battery_monitor_svn/about.xml 2007-10-11 07:44:02 UTC (rev 601) @@ -1,7 +1,7 @@ <?xml version='1.0' encoding='UTF-8'?> <about> - <gadget_name type='str'>light_monitor</gadget_name> <gadget_author type='str'>Paul Rathgeb</gadget_author> + <gadget_version type='str'>0.0.1</gadget_version> <gadget_description type='str'>Light monitor for tux droid</gadget_description> - <gadget_version type='str'>0.0.1</gadget_version> + <gadget_name type='str'>light_monitor</gadget_name> </about> Modified: software/gadgets/battery_monitor/trunk/Battery_monitor_svn/settings.xml =================================================================== --- software/gadgets/battery_monitor/trunk/Battery_monitor_svn/settings.xml 2007-10-10 15:04:47 UTC (rev 600) +++ software/gadgets/battery_monitor/trunk/Battery_monitor_svn/settings.xml 2007-10-11 07:44:02 UTC (rev 601) @@ -10,22 +10,22 @@ <changeD_rad type='bool'>False</changeD_rad> <threshold type='float'>50.0</threshold> <decrease_rad type='bool'>False</decrease_rad> - <behavior_file_threshold type='NoneType'>None</behavior_file_threshold> + <Sample type='float'>500.0</Sample> <raise type='float'>10.0</raise> <changeU_rad type='bool'>False</changeU_rad> <threshold_notified type='bool'>False</threshold_notified> <config type='list'>[]</config> <behavior_file_change type='NoneType'>None</behavior_file_change> + <drop_rad type='bool'>True</drop_rad> <raise_rad type='bool'>False</raise_rad> <changeD type='float'>10.0</changeD> <drop_time type='float'>1.0</drop_time> <changeU type='float'>10.0</changeU> <raise_time type='float'>1.0</raise_time> <drop type='float'>10.0</drop> - <drop_rad type='bool'>True</drop_rad> <MainScript type='str'> </MainScript> - <Sample type='float'>500.0</Sample> + <behavior_file_threshold type='NoneType'>None</behavior_file_threshold> <threshold_chk type='bool'>False</threshold_chk> <Rate type='float'>1.0</Rate> <changeD_time type='float'>1.0</changeD_time> Modified: software/gadgets/battery_monitor/trunk/Battery_monitor_svn/strings.xml =================================================================== --- software/gadgets/battery_monitor/trunk/Battery_monitor_svn/strings.xml 2007-10-10 15:04:47 UTC (rev 600) +++ software/gadgets/battery_monitor/trunk/Battery_monitor_svn/strings.xml 2007-10-11 07:44:02 UTC (rev 601) @@ -4,14 +4,12 @@ <conf_lblThreshold type='str'>Threshold</conf_lblThreshold> <gui_conf_remote_title type='str'>Control</gui_conf_remote_title> <conf_lblRaise type='str'>Raise</conf_lblRaise> - <widget_lblTest type='str'>Notifications</widget_lblTest> <gui_conf_description_lb type='str'>Description</gui_conf_description_lb> <conf_lblEvent type='str'>Event</conf_lblEvent> <widget_lblControl type='str'>Control</widget_lblControl> <gui_conf_accept_bt type='str'>Accept</gui_conf_accept_bt> <help_text type='str'> </help_text> - <conf_lblBehavior type='str'>Behavior script</conf_lblBehavior> <conf_lblChange type='str'>Change</conf_lblChange> <conf_lblBoth type='str'>Both</conf_lblBoth> <widget_lblBtnApply type='str'>Apply changes</widget_lblBtnApply> @@ -21,17 +19,19 @@ <gui_conf_update_title type='str'>Update</gui_conf_update_title> <widget_lblValue type='str'>Value (%)</widget_lblValue> <gui_conf_cancel_bt type='str'>Cancel</gui_conf_cancel_bt> - <widget_lblBoth type='str'>Both direction</widget_lblBoth> + <gui_conf_rate_lb type='str'>Refresh rate :</gui_conf_rate_lb> <mainscript type='str'>I've found the light !</mainscript> + <conf_btnRemove type='str'>Remove</conf_btnRemove> <gui_conf_delay_lb type='str'>Delay (sec)</gui_conf_delay_lb> <conf_btnBehavior type='str'>Clear path</conf_btnBehavior> <gui_conf_about_title type='str'>About</gui_conf_about_title> <conf_lblChangeD type='str'>Drop and raise</conf_lblChangeD> - <widget_lblChangeD type='str'>Drop and raise</widget_lblChangeD> + <conf_lblChangeU type='str'>Raise and drop</conf_lblChangeU> <speaker_name type='str'>Ryan8k</speaker_name> <conf_lblSample type='str'>Samples</conf_lblSample> <conf_lblType type='str'>Type</conf_lblType> <widget_lblDisplayThreshold type='str'>Display threshold on graph</widget_lblDisplayThreshold> + <widget_lblDark type='str'>Search darkness</widget_lblDark> <conf_btnModify type='str'>Modify</conf_btnModify> <widget_lblEvent type='str'>Event</widget_lblEvent> <widget_lblNotified type='str'>Notified</widget_lblNotified> @@ -44,10 +44,10 @@ <conf_lblNotifiedBehavior type='str'>Notified</conf_lblNotifiedBehavior> <gui_conf_author_lb type='str'>Author</gui_conf_author_lb> <widget_lblDrop type='str'>Drop</widget_lblDrop> - <conf_lblNotified type='str'>Notified ?</conf_lblNotified> - <gui_conf_rate_lb type='str'>Refresh rate :</gui_conf_rate_lb> + <MainBehavior type='str'>Main behavior</MainBehavior> + <widget_lblBoth type='str'>Both direction</widget_lblBoth> <conf_lblDefaultBehavior type='str'>Default behavior</conf_lblDefaultBehavior> - <conf_lblChangeU type='str'>Raise and drop</conf_lblChangeU> + <conf_lblBehavior type='str'>Behavior script</conf_lblBehavior> <gui_conf_remote_set_bt type='str'>Set</gui_conf_remote_set_bt> <widget_lblChange type='str'>Change</widget_lblChange> <widget_lblLight type='str'>Search light</widget_lblLight> @@ -55,14 +55,14 @@ <conf_lblNotNotified type='str'>Not notified</conf_lblNotNotified> <conf_lblDrop type='str'>Drop</conf_lblDrop> <gui_conf_window_title type='str'>Parameters</gui_conf_window_title> - <widget_lblDark type='str'>Search darkness</widget_lblDark> + <conf_lblNotified type='str'>Notified ?</conf_lblNotified> <widget_lblSet type='str'>Add to config</widget_lblSet> <conf_lblValue type='str'>Value (%)</conf_lblValue> <conf_lblRate type='str'>Refresh rate</conf_lblRate> <widget_lblBehavior type='str'>Enable behavior script</widget_lblBehavior> - <MainBehavior type='str'>Main behavior</MainBehavior> + <widget_lblChangeD type='str'>Drop and raise</widget_lblChangeD> <conf_lblTime type='str'>Time (sec.)</conf_lblTime> <conf_lblControl type='str'>Control</conf_lblControl> - <conf_btnRemove type='str'>Remove</conf_btnRemove> + <widget_lblTest type='str'>Notifications</widget_lblTest> <widget_lblThreshold type='str'>Threshold</widget_lblThreshold> </strings> |