PK Ov88'> > settings.xml
0.0.0
False
False
True
True
True
en_US
4
True
True
1
4
100
3
None
1.0
600.0
True
[[1, 0, 0, 0.10000000000000001, 20.0, True, None, False, 0]]
6.0
4.8
[[1, 0, 0, 0.10000000000000001, 20.0, True, None, False, 0]]
PK Ov88
/ about.xml
Paul Rathgeb
battery_monitor
0.0.2
PK b88Hj parts.xml
True
True
True
PK Ov88N4 4 strings.xml
The battery level reached the threshold
The battery level changed
The battery level dropped and raised
The battery level raised and dropped
The battery level passed below the threshold
The battery level dropped
The battery level exceeded the threshold
Main behavior
The battery level raised
Weak batteries
The batteries are full
On battery
and the batteries are recharging
Charging
Add
Clear path
Modify
Remove
Behavior script
Both
Change
Drop and raise
Raise and drop
Control
Decrease
Default behavior
Drop
Event
Increase
Not notified
Notified ?
Notified
Raise
Refresh rate
Samples
Threshold
Time (sec.)
Type
Value (V)
The recharging of the battery is finished
The level of the batteries is full
About
Accept
Author
Cancel
Current
Delay (sec)
Description
Refresh rate :
Set
Control
Sample :
Update
Version
Parameters
--The events:
Two main types of events can take place, each containing various options:
The changes:
The changes are events which occur in a given time.
The four types of changes are:
- Drop
- Raise
- a drop followed by an increase
- an increase followed by a drop
For example, an event can take place if the battery level decreases by 0.1V in a time of ten seconds.
The thresholds:
The threshold events start when the battery voltage reaches a specified level.
Passing the threshold can be done:
- by an increase (moving above the threshold)
- by a decrease (moving below the threshold)
- in both directions.
-- The windows:
- The settings window:
This window contains all configuration options of the gadget, in particular the refresh rate and the number of points displayed on the graph.
Additional custom events with a notification, can also be stored here. If no external script is specified, a default behavior will be used.
The events can be modified or removed, simply by selecting the event line in the table and clicking the required button.
A checkbox allows to enable / disable the measurement when the motors are running.
- The gadget window:
This window displays the battery voltage graph.
When this window is displayed, the events stored in the settings window are not notified.
This window makes it possible to try various configurations and to add them in the settings table.
Upper limit
Lower limit
Disable measurement when the motors are running
The level of the batteries is weak
I've found the light !
Battery monitor
The level of the batteries is good
and I'm powered by the battery
and the power supply is plugged
Plugged
Ryan8k
Enable behavior script
Both direction
Apply changes
Change
Drop and raise
Raise and drop
Control
Decreasing
Display threshold on graph
Drop
Event
Increasing
Notified
Raise
Add to config
Notifications
Threshold
Value (V)
PK Jv88~> Scripts/Python/notify.pypdef notify_checker():
measure = _me.get_param('measure')
if measure.low_threshold_flag == True or measure.high_threshold_flag == True:
return True
if measure.end_of_charge_flag == True:
return True
if measure.GUI_on == False:
for i in range(len(measure.event_tab)):
temp = measure.event_tab[i][7]
if temp == True:
return True
return False
else:
for i in range(len(measure.test_tab)):
temp = measure.test_tab[i][7]
if temp == True:
return True
return False
def notify_actuator():
measure = _me.get_param('measure')
#event = _me.get_param('measure').event_tab
if _me.get_param('measure').low_threshold_flag == True:
_me.get_param('measure').low_threshold_flag = False
tux.cmd.mouth_open()
tux.tts.speak(_me.string('absolute_threshold'))
tux.cmd.mouth_close()
if _me.get_param('measure').high_threshold_flag == True:
_me.get_param('measure').high_threshold_flag = False
tux.cmd.mouth_open()
tux.tts.speak(_me.string('absolute_threshold_high'))
tux.cmd.mouth_close()
if measure.end_of_charge_flag == True:
measure.end_of_charge_flag = False
tux.cmd.mouth_open()
tux.tts.speak(_me.string('end_of_charge'))
tux.cmd.mouth_close()
else:
if measure.GUI_on:
event = measure.test_tab
else:
event = measure.event_tab
for i in range(len(event)):
#create text to speach for the default notification
if event[i][1] == 0:
if event[i][2] == 0:
text = _me.string('Drop')
elif event[i][2] == 1:
text = _me.string('Raise')
elif event[i][2] == 2:
text = _me.string('ChangeD')
elif event[i][2] == 3:
text = _me.string('ChangeU')
else:
if event[i][2] == 0:
text = _me.string('Increase')
elif event[i][2] == 1:
text = _me.string('Decrease')
elif event[i][2] == 2:
text = _me.string('Both')
if event[i][7]:
if event[i][5]:
path = str(event[i][6])
path = path.replace('%20', ' ')
if os.path.isfile(path) and os.path.exists(path):
path = "'%s'" % path
tux.sys.shell(path)
event[i][7] = False
else:
tux.cmd.mouth_open()
tux.tts.speak(text)
tux.cmd.mouth_close()
event[i][7] = False
else:
event[i][7] = False
break
PK b88&V~ Scripts/Python/init.pypsys.path.append(_me.get_path('root') + '/Scripts/Python')
from Battery_class import Measure
measure = Measure(float(_me.get_param('Sample')), float(_me.get_param('Rate')))
_me.set_param('measure', measure)
# update the sample and rate values
measure.rate = float(_me.get_param('Rate'))
measure.rate_backup = measure.rate
measure.sample = float(_me.get_param('Sample'))
measure.sample_backup = measure.sample
measure.low_threshold = _me.get_param('low_threshold')
measure.high_threshold = _me.get_param('high_threshold')
measure.chkMotors = _me.get_param('chkMotors')
measure.event_tab = _me.get_param('config')
measure.test_tab = _me.get_param('test_tab')
monitor_id = tux.monitoring.insert(0x25, measure.on_battery_level)
_me.set_param('monitor_id', monitor_id)
def destroy():
tux.monitoring.remove(_me.get_param('monitor_id'))
_me.insert_funct('destroy', destroy)
PK b88" Scripts/Python/main.pypdef update_informations():
pass
def battery_level():
measure = _me.get_param('measure')
val = measure.val_table[len(measure.val_table)-1]
max_val = measure.convert_value([0, 1, 0, measure.high_threshold])
max_val = max_val * 3.4
min_val = measure.convert_value([0, 1, 0, measure.low_threshold])
min_val = min_val * 3.4
txt = ''
if val <= min_val:
txt = _me.string('low')
#tux.tts.speak(str(txt))
elif val >= max_val:
txt = _me.string('full')
#tux.tts.speak(str(txt))
else:
txt = _me.string('normal')
#tux.tts.speak(str(txt))
txt = txt + ', '
if tux.status.charger_state():
txt = txt + _me.string('charge')
elif tux.status.power_plug():
txt = txt + _me.string('plug')
else:
txt = txt + _me.string('on_battery')
print txt
tux.cmd.mouth_open()
tux.tts.speak(str(txt))
tux.cmd.mouth_close()
battery_level()
PK b88D[ [ Scripts/Python/Battery_class.pyimport gtk
import sys
import time
import os
import threading
import thread
import math
sys.path.append('/opt/tuxdroid/api/python')
from tux import *
class Graph(gtk.DrawingArea):
def __init__(self):
super(Graph, self).__init__()
self.connect("expose_event", self.expose)
self.context = None
self.battery = ' '
self.plugged = ' '
self.charging = ' '
def expose(self, widget, event):
#when an event occur, update the context
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()
self.draw_threshold()
self.draw_label()
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.2, 0.2, 0.2)
self.context.set_line_width(0.4)
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.6)
self.context.line_to(0, y)
self.context.set_source_rgb(0.2, 0.2, 0.2)
if i != 18:
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):
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 = ((self.measure_graph.rate * self.measure_graph.sample)/60 - (self.measure_graph.rate * self.measure_graph.sample * temp_tab[i])/60)
txt = str('%.2f' % txt)
self.context.show_text(str(txt) + " min.")
self.context.stroke()
def draw_threshold(self):
coeff_y = float(self.rect.height / self.measure_graph.RANGE)
y = self.measure_graph.convert_value([0, 1, 0, self.measure_graph.low_threshold])
y = (y * 3.4)
self.context.set_source_rgb(0.8, 0, 0)
self.context.set_line_width(1)
self.context.move_to(self.rect.width, self.rect.height - y * coeff_y)
self.context.line_to(0, self.rect.height - y * coeff_y)
self.context.stroke()
y = self.measure_graph.convert_value([0, 1, 0, self.measure_graph.high_threshold])
y = (y * 3.4)
self.context.set_source_rgb(0, 0.8, 0)
self.context.set_line_width(1)
self.context.move_to(self.rect.width, self.rect.height - y * coeff_y)
self.context.line_to(0, self.rect.height - y * coeff_y)
self.context.stroke()
def draw_label(self):
#display sample and rate
#move the vector in the bottom
self.draw_circle(5, self.rect.height - 7, [0.2, 0.2, 0.7])
self.context.set_source_rgb(0.2, 0.2, 0.2)
self.context.move_to(10, self.rect.height - 2)
self.context.show_text(self.battery)
self.draw_square(5, self.rect.height - 20, [0.2, 0.2, 0.7])
self.context.set_source_rgb(0.2, 0.2, 0.2)
self.context.move_to(10, self.rect.height - 15)
self.context.show_text(self.plugged)
self.draw_triangle(5, self.rect.height - 33, [0.2, 0.2, 0.7])
self.context.set_source_rgb(0.2, 0.2, 0.2)
self.context.move_to(10, self.rect.height - 28)
self.context.show_text(self.charging)
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, 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))
temp_event = 0
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))
if self.measure_graph.val_table_event[i] == 0:
self.draw_circle(self.rect.x + ((i) * coeff_x), self.rect.height - (val * coeff_y), [0.2, 0.2, 0.7])
if self.measure_graph.val_table_event[i] == 1:
self.draw_square(self.rect.x + ((i) * coeff_x), self.rect.height - (val * coeff_y), [0.2, 0.2, 0.7])
if self.measure_graph.val_table_event[i] == 2:
self.draw_triangle(self.rect.x + ((i) * coeff_x), self.rect.height - (val * coeff_y), [0.2, 0.2, 0.7])
self.context.line_to(self.rect.x + ((i) * coeff_x), self.rect.height + 5)
self.context.stroke()
def draw_square(self, x, y, color):
self.context.stroke()
self.context.set_source_rgb(color[0], color[1], color[2])
self.context.move_to(x - 4, y - 4)
self.context.rectangle(x - 4, y - 4, 8, 8)
self.context.move_to(x, y)
self.context.fill()
self.context.set_source_rgb(0, 0, 1)
def draw_triangle(self, x, y, color):
self.context.stroke()
self.context.set_source_rgb(color[0], color[1], color[2])
self.context.move_to(x, y - 5)
self.context.line_to(x + 5, y + 5)
self.context.line_to(x - 5, y + 5)
self.context.line_to(x, y - 5)
self.context.close_path()
self.context.fill()
self.context.move_to(x, y)
self.context.set_source_rgb(0, 0, 1)
def draw_circle(self, x, y, color):
self.context.stroke()
self.context.set_source_rgb(color[0], color[1], color[2])
self.context.arc(x, y, 4, 0, 2 * math.pi)
self.context.close_path()
self.context.fill()
self.context.move_to(x, y)
self.context.set_source_rgb(0, 0, 1)
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(0, 0, 1, 0.2)
self.context.fill()
class Measure(object):
def __init__(self, sample, rate):
self.rate = rate
self.rate_backup = self.rate
self.sample = sample
self.sample_backup = self.sample
self.val_table = [-2] * int(self.sample)
self.val_table_event = [-1] * int(self.sample)
self.charger_event_backup = 3
self.test_tab = [0]
self.absolute_threshold_low_flag = False
self.absolute_threshold_high_flag = False
self.low_threshold_flag = False
self.high_threshold_flag = False
self.end_of_charge_flag = False
self.chkMotors = False
self.disable_event = False
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 = 340.0
self.low_threshold = 5.0
self.high_threshold = 6.0
self.__on_battery_mutex = threading.Lock()
self.__timeout_mutex = threading.Lock()
###########################################################
#
# Events control
#
###########################################################
def event_control(self):
if self.GUI_on:
self.__tab = self.test_tab
else:
self.__tab = self.event_tab
for i in range (len(self.__tab)):
val = self.convert_value(self.__tab[i])
self.Threshold_control(i, val)
self.Change_control(i, val)
if self.GUI_on:
self.test_tab = self.__tab
else:
self.event_tab = self.__tab
self.low_threshold_flag = self.absolute_threshold_low(self.low_threshold, self.low_threshold + 0.1)
self.high_threshold_flag = self.absolute_threshold_high(self.high_threshold, self.high_threshold - 0.1)
# 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
self.low_threshold_flag = False
self.high_threshold_flag = False
for i in range (len(self.event_tab)):
self.event_tab[i][7] = False
def convert_value(self, table):
if table[1] == 1:
#threshold event
value = table[3]
#100% in the graph = 2.5V
value = (100 * (value - 4)) / 2.5
return value
else:
value = table[3]
#100% in the graph = 2.5V
value = (100 * (value)) / 2.5
return value
###########################################################
#
# Absolute threshold control
#
###########################################################
def absolute_threshold_low(self, value, value_off):
if self.absolute_threshold_low_flag == False:
val = self.convert_value([0, 1, 0, value])
val_act = (self.val_table[len(self.val_table)-1]*100) / self.RANGE
val_prev = (self.val_table[len(self.val_table)-2]*100) / self.RANGE
if val_act < val:
self.absolute_threshold_low_flag = True
return True
else:
val = self.convert_value([0, 1, 0, value_off])
val_act = (self.val_table[len(self.val_table)-1]*100) / self.RANGE
val_prev = (self.val_table[len(self.val_table)-2]*100) / self.RANGE
if val_act > val:
self.absolute_threshold_low_flag = False
return False
def absolute_threshold_high(self, value, value_off):
if self.absolute_threshold_high_flag == False:
val = self.convert_value([0, 1, 0, value])
val_act = (self.val_table[len(self.val_table)-1]*100) / self.RANGE
val_prev = (self.val_table[len(self.val_table)-2]*100) / self.RANGE
if val_act > val:
self.absolute_threshold_high_flag = True
return True
else:
val = self.convert_value([0, 1, 0, value_off])
val_act = (self.val_table[len(self.val_table)-1]*100) / self.RANGE
val_prev = (self.val_table[len(self.val_table)-2]*100) / self.RANGE
if val_act < val:
self.absolute_threshold_high_flag = False
return 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):
val_act = (self.val_table[len(self.val_table)-1]*100) / self.RANGE
val_prev = (self.val_table[len(self.val_table)-2]*100) / self.RANGE
if val_prev <= value and val_act > value:
return True
def Decrease_control(self, val):
val_act = (self.val_table[len(self.val_table)-1]*100) / self.RANGE
val_prev = (self.val_table[len(self.val_table)-2]*100) / self.RANGE
if val_prev >= val and val_act < val:
return True
def Both_control(self, val):
val_act = (self.val_table[int(len(self.val_table)-1)]*100) / self.RANGE
val_prev = (self.val_table[int(len(self.val_table)-2)]*100) / self.RANGE
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) - 1 - int(time) + timeout
maximum = max(self.val_table[init_val:len(self.val_table)-1])
if maximum >= self.val_table[len(self.val_table)-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) - 1 - int(time) + timeout
minimum = min(self.val_table[init_val:(len(self.val_table)-1)])
if minimum <= self.val_table[len(self.val_table)-1] - ((val/100)*self.RANGE):
self.__tab[index][8] = int(time)
return True
else:
self.__tab[index][8] = timeout
def ChangeD_control(self, time, val, timeout, index):
if timeout != 0:
timeout -= 1
init_val = len(self.val_table) - 1 - int(time) + timeout
maximum = max(self.val_table[init_val:len(self.val_table)-1])
for i in range(int(time - timeout)):
if self.val_table[int(len(self.val_table)-1-i)] <= self.val_table[len(self.val_table) - 1] - ((val/100)*self.RANGE):
maximum = max(self.val_table[init_val:len(self.val_table) - i])
if maximum >= self.val_table[len(self.val_table) - 1 - i] + val:
self.__tab[index][8] = int(time)
return True
self.__tab[index][8] = timeout
return False
def ChangeU_control(self, time, val, timeout, index):
if timeout != 0:
timeout -= 1
init_val = len(self.val_table) - 1 - int(time) + timeout
maximum = max(self.val_table[init_val:len(self.val_table)-1])
for i in range(int(time - timeout)):
if self.val_table[int(len(self.val_table)-1-i)] >= self.val_table[len(self.val_table) - 1] + ((val/100)*self.RANGE):
minimum = min(self.val_table[init_val:len(self.val_table)-i])
if minimum <= self.val_table[len(self.val_table) - 1 - i] - val:
self.__tab[index][8] = int(time)
return True
self.__tab[index][8] = timeout
return False
###########################################################
#
# 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_battery_level(self, args):
if self.__on_battery_mutex.locked():
return
try:
self.__on_battery_mutex.acquire()
if not (self.chkMotors == True and args[2] == 1):
self.average += (args[0] * 256) + args[1]
self.count += 1
else:
self.disable_event = True
# Refresh the sample and rate value
if self.sample_backup != self.sample:
self.sample = self.sample_backup
self.val_table = [-2] * int(self.sample)
self.val_table_event = [-1] * int(self.sample)
self.charger_event_backup = 3
if self.rate_backup != self.rate:
self.rate_has_changed()
#control the time
if self.tick <= time.time():
self.tick = time.time() + self.rate
#If no value has been received, use the previous.
if self.count == 0:
val = self.val_table[len(self.val_table)-1]
#Else, calcul the average
else:
val = self.average / self.count
val = val - 530
charger_event = -1
#Event control
if tux.status.power_plug():
charger_event = 1
if tux.status.charger_state():
charger_event = 2
elif self.charger_event_backup > 0:
charger_event = 0
if self.charger_event_backup != charger_event:
# End of the charge cycle
if self.charger_event_backup == 2 and charger_event == 1:
self.end_of_charge_flag = True
self.charger_event_backup = charger_event
else:
charger_event = -1
#Add the new value in the table and reset all flags
self.val_table.append(val)
self.val_table.pop(0)
self.val_table_event.append(charger_event)
self.val_table_event.pop(0)
self.average = 0
self.count = 0
#If widget GUI is displayed, refresh the graph.
if self.GUI_on:
self.graph_measure.refresh()
#And check for events
self.event_control()
self.__on_battery_mutex.release()
except:
self.__on_battery_mutex.release()
print sys.exc_info()
def rate_has_changed(self):
self.rate = self.rate_backup
pts_per_sec = self.sample / (self.rate * self.sample)
for i in range(len(self.event_tab)):
if self.event_tab[i][1] == 0:
if self.event_tab[i][4] <= self.rate:
self.event_tab[i][4] = self.rate
elif self.event_tab[i][4] >= self.rate * self.sample:
self.event_tab[i][4] = self.rate * self.sample
self.event_tab[i][8] = int(self.event_tab[i][4] * pts_per_sec)
if self.test_tab[0][1] == 0:
if self.test_tab[0][4] <= self.rate:
self.test_tab[0][4] = self.rate
elif self.test_tab[0][4] >= self.rate * self.sample:
self.test_tab[0][4] = self.rate * self.sample
self.test_tab[0][8] = int(self.test_tab[0][4] * pts_per_sec)
self.test_tab[0][8] = int(self.test_tab[0][4] * pts_per_sec)
PK b88RAQ Q ! Scripts/Python/GUI/conf/other.pypbindtextdomain("params", "")
class Window(SimpleGladeApp):
def __init__(self,
path=_me.get_path('root') + '/Scripts/Python/GUI/conf/other.glade',
root="window1",
domain="params", **kwargs):
SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
def new(self):
self.measure = _me.get_param('measure')
_me.insert_funct('refresh_tree', self.refresh_tree)
_me.insert_funct('verify_tab', self.verify_tab)
self.updates_commons()
self.make_viewtree()
self.update_labels()
def updates_commons(self):
# Window title
txt = "%s : %s" % (_me.string('name_to_read'),
_me.string('gui_conf_window_title'))
self.get_widget("window1").set_title(txt)
# Update Frame
txt = _me.string('gui_conf_update_title')
self.get_widget("label12").set_text(txt)
txt = "%s : " % _me.string('gui_conf_delay_lb')
self.get_widget("label13").set_text(txt)
value = _me.get_var('notify_delay')
self.get_widget("delay_spinbutton").set_value(value)
# Bottom buttons
txt = _me.string('gui_conf_cancel_bt')
self.get_widget("label6").set_text(txt)
txt = _me.string('gui_conf_accept_bt')
self.get_widget("label5").set_text(txt)
self.get_widget('txt_conf_rate').set_text(str(_me.get_param('Rate')))
self.get_widget('txt_conf_sample').set_text(str(_me.get_param('Sample')))
self.get_widget('txtLowThreshold').set_text(str(_me.get_param('low_threshold')))
self.get_widget('txtHighThreshold').set_text(str(_me.get_param('high_threshold')))
###########################################################
#
# Battery configuration control
#
###########################################################
def make_viewtree(self):
self.index_column = gtk.TreeViewColumn('Index')
self.index_column.set_min_width(50)
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(100)
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.set_min_width(100)
self.type_cell = gtk.CellRendererText()
self.type_column.pack_start(self.type_cell, True)
self.type_column.add_attribute(self.type_cell, 'text', 2)
self.value_column = gtk.TreeViewColumn(_me.string('conf_lblValue'))
self.value_column.set_min_width(100)
self.value_cell = gtk.CellRendererText()
self.value_column.pack_start(self.value_cell, True)
self.value_column.add_attribute(self.value_cell, 'text', 3)
self.time_column = gtk.TreeViewColumn(_me.string('conf_lblTime'))
self.time_column.set_min_width(100)
self.time_cell = gtk.CellRendererText()
self.time_column.pack_start(self.time_cell, True)
self.time_column.add_attribute(self.time_cell, 'text', 4)
self.notified_column = gtk.TreeViewColumn(_me.string('conf_lblNotified'))
self.notified_column.set_min_width(100)
self.notified_cell = gtk.CellRendererText()
self.notified_column.pack_start(self.notified_cell, True)
self.notified_column.add_attribute(self.notified_cell, 'text', 5)
self.behavior_column = gtk.TreeViewColumn(_me.string('conf_lblBehavior'))
self.behavior_cell = gtk.CellRendererText()
self.behavior_column.pack_start(self.behavior_cell, True)
self.behavior_column.add_attribute(self.behavior_cell, 'text', 6)
self.value_list = gtk.TreeStore(int, str, str, str, str, str, str)
self.gadget_viewer = gtk.TreeView(self.value_list)
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.append_column(self.value_column)
self.gadget_viewer.append_column(self.time_column)
self.gadget_viewer.append_column(self.notified_column)
self.gadget_viewer.append_column(self.behavior_column)
self.get_widget("scrolledwindow1").add(self.gadget_viewer)
self.get_widget("scrolledwindow1").set_size_request(0, 150)
self.get_widget("scrolledwindow1").show_all()
self.get_widget('cbb_conf_event').set_active(0)
self.get_widget('txt_conf_value').set_text('1.0')
self.get_widget('txt_conf_time').set_text('0.1')
self.get_widget('chkMotors').set_label(_me.string('lblMotors'))
self.get_widget('chkMotors').set_active(_me.get_param('chkMotors'))
self.measure.chkMotors = _me.get_param('chkMotors')
self.gadget_viewer.get_selection().connect("changed",self.on_row_selected)
#self.gadget_viewer.connect("row_activated", self.on_row_selected)
self.measure.event_tab = _me.get_param('config')
self.get_widget('cbb_conf_event').append_text(_me.string('conf_lblChange'))
self.get_widget('cbb_conf_event').append_text(_me.string('conf_lblThreshold'))
self.get_widget('cbb_conf_event').set_active(0)
for i in range(len(self.measure.event_tab)):
self.add_row(i)
###########################################################
#
# Update the labels
#
###########################################################
def update_labels(self):
self.get_widget("lbl_conf_event").set_text(_me.string('conf_lblEvent'))
self.get_widget("lbl_conf_type").set_text(_me.string('conf_lblType'))
self.get_widget("lbl_conf_value").set_text(_me.string('conf_lblValue'))
self.get_widget("lbl_conf_time").set_text(_me.string('conf_lblTime'))
self.get_widget("lbl_conf_notified").set_text(_me.string('conf_lblNotified'))
self.get_widget("lbl_conf_behavior").set_text(_me.string('conf_lblBehavior'))
self.get_widget("btn_conf_add").set_label(_me.string('conf_btnAdd'))
self.get_widget("btn_conf_remove").set_label(_me.string('conf_btnRemove'))
self.get_widget("btn_conf_modify").set_label(_me.string('conf_btnModify'))
self.get_widget("btnBehavior").set_label(_me.string('conf_btnBehavior'))
self.get_widget("lbl_conf_sample").set_text(_me.string('conf_lblSample'))
self.get_widget("lbl_conf_rate").set_text(_me.string('conf_lblRate'))
self.get_widget("lblControlFrame").set_text(_me.string('conf_lblControl'))
self.get_widget("lblScript").set_text(_me.string('MainBehavior'))
self.get_widget("lblHighThreshold").set_label(_me.string('lblHighThreshold'))
self.get_widget("lblLowThreshold").set_label(_me.string('lblLowThreshold'))
###########################################################
#
# On row selected
#
###########################################################
def on_row_selected(self, obj):
path = obj.get_selected_rows()
self.__iter = self.value_list.get_iter(path[1][0])
index = self.value_list.get_value(self.__iter, 0)
event = self.value_list.get_value(self.__iter, 1)
typet = self.value_list.get_value(self.__iter, 2)
value = self.value_list.get_value(self.__iter, 3)
time = self.value_list.get_value(self.__iter, 4)
notify = self.value_list.get_value(self.__iter, 5)
behavior = self.value_list.get_value(self.__iter, 6)
if event == _me.string('conf_lblChange'):
self.get_widget('cbb_conf_event').set_active(0)
if typet == _me.string('conf_lblDrop'):
self.get_widget('cbb_conf_type').set_active(0)
if typet == _me.string('conf_lblRaise'):
self.get_widget('cbb_conf_type').set_active(1)
if typet == _me.string('conf_lblChangeD'):
self.get_widget('cbb_conf_type').set_active(2)
if typet == _me.string('conf_lblChangeU'):
self.get_widget('cbb_conf_type').set_active(3)
self.get_widget('txt_conf_value').set_text(value)
self.get_widget('txt_conf_time').set_text(time)
else:
self.get_widget('cbb_conf_event').set_active(1)
if typet == _me.string('conf_lblIncrease'):
self.get_widget('cbb_conf_type').set_active(0)
if typet == _me.string('conf_lblDecrease'):
self.get_widget('cbb_conf_type').set_active(1)
if typet == _me.string('conf_lblBoth'):
self.get_widget('cbb_conf_type').set_active(2)
self.get_widget('txt_conf_value').set_text(value)
self.get_widget('txt_conf_time').set_text('')
if notify == _me.string('conf_lblNotifiedBehavior'):
self.get_widget('chk_conf_notified').set_active(True)
else:
self.get_widget('chk_conf_notified').set_active(False)
if behavior != 'N.A.':
self.get_widget('conf_behavior').set_filename(behavior)
else:
self.get_widget('conf_behavior').set_filename('None')
###########################################################
#
# On row modified
#
###########################################################
def on_btn_conf_modify_clicked(self, widget, *args):
index = self.value_list.get_value(self.__iter, 0)
self.measure.event_tab = _me.get_param('config')
length = len(_me.get_param('config'))
self.verify_value()
value = []
value = [index,
self.get_widget('cbb_conf_event').get_active(),
self.get_widget('cbb_conf_type').get_active(),
float(self.get_widget('txt_conf_value').get_text()),
float(self.get_widget('txt_conf_time').get_text()),
self.get_widget('chk_conf_notified').get_active(),
str(self.get_widget('conf_behavior').get_filename()),
False,
0]
self.measure.event_tab = _me.get_param('config')
if self.verify_tab(value):
self.measure.event_tab[(index-1)] = value
_me.set_param('config', self.measure.event_tab)
self.value_list.clear()
for i in range(len(self.measure.event_tab)):
self.add_row(i)
###########################################################
#
# On row deleted
#
###########################################################
def on_btn_conf_remove_clicked(self, widget, *args):
index = self.value_list.get_value(self.__iter, 0)
self.measure.event_tab =_me.get_param('config')
self.measure.event_tab.pop(index - 1)
_me.set_param('config', self.measure.event_tab)
self.__iter = 0
self.value_list.clear()
for i in range(len(self.measure.event_tab)):
self.add_row(i)
###########################################################
#
# On row added
#
###########################################################
def on_btn_conf_add_clicked(self, widget, *args):
length = len(_me.get_param('config'))
self.verify_value()
value = []
value = [(length + 1),
self.get_widget('cbb_conf_event').get_active(),
self.get_widget('cbb_conf_type').get_active(),
float(self.get_widget('txt_conf_value').get_text()),
float(self.get_widget('txt_conf_time').get_text()),
self.get_widget('chk_conf_notified').get_active(),
str(self.get_widget('conf_behavior').get_filename()),
False,
0]
self.measure.event_tab = _me.get_param('config')
if self.verify_tab(value):
self.measure.event_tab.append(value)
self.refresh_tree()
def refresh_tree(self):
_me.set_param('config', self.measure.event_tab)
self.value_list.clear()
for i in range(len(self.measure.event_tab)):
self.add_row(i)
def verify_tab(self, tab):
for i in range(len(self.measure.event_tab)):
if self.measure.event_tab[i][1] == tab[1]:
if self.measure.event_tab[i][2] == tab[2]:
if self.measure.event_tab[i][3] == tab[3]:
if self.measure.event_tab[i][4] == tab[4]:
if self.measure.event_tab[i][5] == tab[5]:
if self.measure.event_tab[i][6] == tab[6]:
return False
return True
###########################################################
#
# Add row function
#
###########################################################
def add_row(self, tab_index):
self.measure.event_tab = _me.get_param('config')
i = tab_index
if self.measure.event_tab[i][1] == 0:
Event = _me.string('conf_lblChange')
if self.measure.event_tab[i][2] == 0:
Type = _me.string('conf_lblDrop')
elif self.measure.event_tab[i][2] == 1:
Type = _me.string('conf_lblRaise')
elif self.measure.event_tab[i][2] == 2:
Type = _me.string('conf_lblChangeD')
elif self.measure.event_tab[i][2] == 3:
Type = _me.string('conf_lblChangeU')
Value = str(self.measure.event_tab[i][3])
Time = str(self.measure.event_tab[i][4])
else:
Event = _me.string('conf_lblThreshold')
if self.measure.event_tab[i][2] == 0:
Type = _me.string('conf_lblIncrease')
elif self.measure.event_tab[i][2] == 1:
Type = _me.string('conf_lblDecrease')
elif self.measure.event_tab[i][2] == 2:
Type = _me.string('conf_lblBoth')
Value = str(self.measure.event_tab[i][3])
Time = 'N.A.'
if self.measure.event_tab[i][5]:
Notify = _me.string('conf_lblNotifiedBehavior')
if self.measure.event_tab[i][6] ==None:
Behavior = _me.string('conf_lblDefaultBehavior')
else:
Behavior = str(self.measure.event_tab[i][6])
else:
Notify = _me.string('conf_lblNotNotified')
Behavior = 'N.A.'
self.value_list.append(None,[(i+1), Event, Type, Value, Time, Notify, Behavior])
###########################################################
#
# On combo box event
#
###########################################################
def on_cbb_conf_event_changed(self, widget, *args):
if self.get_widget('cbb_conf_event').get_active() == 0:
for i in range (4):
self.get_widget('cbb_conf_type').remove_text(0)
self.get_widget('cbb_conf_type').append_text(_me.string('conf_lblDrop'))
self.get_widget('cbb_conf_type').append_text(_me.string('conf_lblRaise'))
self.get_widget('cbb_conf_type').append_text(_me.string('conf_lblChangeD'))
self.get_widget('cbb_conf_type').append_text(_me.string('conf_lblChangeU'))
self.get_widget('cbb_conf_type').set_active(0)
else:
for i in range (4):
self.get_widget('cbb_conf_type').remove_text(0)
self.get_widget('cbb_conf_type').append_text(_me.string('conf_lblIncrease'))
self.get_widget('cbb_conf_type').append_text(_me.string('conf_lblDecrease'))
self.get_widget('cbb_conf_type').append_text(_me.string('conf_lblBoth'))
self.get_widget('cbb_conf_type').set_active(0)
###########################################################
#
# On accept button clicked
#
###########################################################
def on_accept_clicked(self, widget, *args):
_me.set_param('Rate', float(self.get_widget('txt_conf_rate').get_text()))
_me.set_param('Sample',float(self.get_widget('txt_conf_sample').get_text()))
_me.set_param(('MainScript'), str(self.get_widget('mainScript').get_filename()))
_me.set_param(('chkMotors'), self.get_widget('chkMotors').get_active())
self.measure.chkMotors = self.get_widget('chkMotors').get_active()
self.measure.rate_backup = _me.get_param('Rate')
self.measure.sample_backup = _me.get_param('Sample')
try:
float(self.get_widget('txtLowThreshold').get_text())
except:
self.get_widget('txtLowThreshold').set_text('4.8')
if float(self.get_widget('txtLowThreshold').get_text()) < 4.0:
self.get_widget('txtLowThreshold').set_text('4.0')
if float(self.get_widget('txtLowThreshold').get_text()) > 6.3:
self.get_widget('txtLowThreshold').set_text('6.3')
self.measure.low_threshold = float(self.get_widget('txtLowThreshold').get_text())
_me.set_param('low_threshold', self.measure.low_threshold)
try:
float(self.get_widget('txtHighThreshold').get_text())
except:
self.get_widget('txtHighThreshold').set_text('4.8')
if float(self.get_widget('txtHighThreshold').get_text()) < self.measure.low_threshold:
self.get_widget('txtHighThreshold').set_text(str(self.measure.low_threshold + 0.1))
if float(self.get_widget('txtHighThreshold').get_text()) > 6.4:
self.get_widget('txtHighThreshold').set_text('6.4')
self.measure.high_threshold = float(self.get_widget('txtHighThreshold').get_text())
_me.set_param('high_threshold', self.measure.high_threshold)
self.measure.absolute_threshold_high_flag = False
self.measure.absolute_threshold_low_flag = False
_me.set_var('notify_delay', int(self.get_widget("delay_spinbutton").get_value()))
self.get_widget("window1").destroy()
###########################################################
#
# On cancel button clicked
#
###########################################################
def on_cancel_clicked(self, widget, *args):
self.get_widget("window1").destroy()
###########################################################
#
# On Clear path button clicked
#
###########################################################
def on_btnBehavior_clicked(self, widget, *args):
self.get_widget('conf_behavior').set_filename('None')
index = self.value_list.get_value(self.__iter, 0)
self.measure.event_tab[index-1][6] = None
self.value_list.clear()
for i in range(len(self.measure.event_tab)):
self.add_row(i)
###########################################################
#
# Verify the value
#
###########################################################
def verify_value(self):
if self.get_widget('cbb_conf_event').get_active() == 0:
maximum = 2.5
minimum = 0.025
else:
maximum = 6.5
minimum = 4.0
try:
float(self.get_widget('txt_conf_time').get_text())
except:
self.get_widget('txt_conf_time').set_text('0.1')
if float(self.get_widget('txt_conf_time').get_text()) < self.measure.rate:
self.get_widget('txt_conf_time').set_text(str(self.measure.rate))
if float(self.get_widget('txt_conf_time').get_text()) > self.measure.rate * self.measure.sample:
self.get_widget('txt_conf_time').set_text(str(self.measure.rate * self.measure.sample))
try:
float(self.get_widget('txt_conf_value').get_text())
except:
self.get_widget('txt_conf_value').set_text(str(minimum))
if float(self.get_widget('txt_conf_value').get_text()) < minimum:
self.get_widget('txt_conf_value').set_text(str(minimum))
if float(self.get_widget('txt_conf_value').get_text()) > maximum:
self.get_widget('txt_conf_value').set_text(str(maximum))
PK b88Phߗ ߗ # Scripts/Python/GUI/conf/other.glade
True
Parameters
GTK_WINDOW_TOPLEVEL
GTK_WIN_POS_NONE
False
False
False
True
False
False
GDK_WINDOW_TYPE_HINT_NORMAL
GDK_GRAVITY_NORTH_WEST
True
False
True
False
0
5
True
0
0.5
GTK_SHADOW_ETCHED_IN
True
False
0
True
True
GTK_POLICY_AUTOMATIC
GTK_POLICY_ALWAYS
GTK_SHADOW_NONE
GTK_CORNER_TOP_LEFT
0
True
True
719
68
True
80
24
True
True
True
True
0
True
●
False
208
35
80
24
True
True
True
True
0
True
●
False
296
35
88
16
True
Type
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
112
8
80
16
True
Time
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
296
8
88
30
True
False
True
112
32
88
16
True
Event
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
16
8
80
16
True
Value
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
208
8
96
16
True
Notified?
False
False
GTK_JUSTIFY_LEFT
False
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
376
8
88
30
True
False
True
16
32
24
24
True
True
GTK_RELIEF_NORMAL
False
False
False
True
416
32
144
30
True
Select A File
GTK_FILE_CHOOSER_ACTION_OPEN
True
False
False
-1
480
32
144
16
True
Behavior script
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
480
8
0
True
True
68
True
88
29
True
True
Add
True
GTK_RELIEF_NORMAL
True
16
8
88
29
True
True
Remove
True
GTK_RELIEF_NORMAL
True
112
8
88
29
True
True
Modify
True
GTK_RELIEF_NORMAL
True
208
8
100
29
True
True
Clear path
True
GTK_RELIEF_NORMAL
True
502
8
0
True
True
84
True
80
24
True
True
True
True
0
True
●
False
160
0
80
24
True
True
True
True
0
True
●
False
160
24
144
30
True
Select A File
GTK_FILE_CHOOSER_ACTION_OPEN
True
False
False
-1
480
24
216
16
True
Behavior script
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
480
0
464
24
True
True
checkbutton1
True
GTK_RELIEF_NORMAL
True
False
False
True
16
56
145
24
True
Sample :
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
16
0
145
24
True
Rate :
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
16
24
80
24
True
True
True
True
0
True
●
False
382
0
135
25
True
label14
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
248
0
135
25
True
label15
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
248
24
80
24
True
True
True
True
0
True
●
False
382
24
0
True
True
True
<b>Control</b>
False
True
GTK_JUSTIFY_LEFT
False
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
label_item
0
True
True
5
True
0
0.5
GTK_SHADOW_IN
True
0.5
0.5
1
1
0
0
12
0
29
True
120
24
True
True
1
0
False
GTK_UPDATE_ALWAYS
False
False
1 1 3600 1 10 10
88
0
336
16
True
Delay (sec) :
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
0
0
True
<b>Updates</b>
False
True
GTK_JUSTIFY_LEFT
False
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
label_item
0
True
True
44
True
96
32
True
True
GTK_RELIEF_NORMAL
True
True
0.5
0.5
0
0
0
0
0
0
True
False
2
True
gtk-apply
4
0.5
0.5
0
0
0
False
False
True
Accept
True
False
GTK_JUSTIFY_LEFT
False
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
0
False
False
16
8
96
32
True
True
GTK_RELIEF_NORMAL
True
True
0.5
0.5
0
0
0
0
0
0
True
False
2
True
gtk-cancel
4
0.5
0.5
0
0
0
False
False
True
Cancel
True
False
GTK_JUSTIFY_LEFT
False
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
0
False
False
144
8
0
True
True
PK b88D7 7 # Scripts/Python/GUI/widget/other.pypbindtextdomain("params", "")
sys.path.append(_me.get_path('root') + '/Scripts/Python')
from Battery_class import Graph
class Window(SimpleGladeApp):
def __init__(self,
path=_me.get_path('root') + '/Scripts/Python/GUI/widget/other.glade',
root="window1",
domain="params", **kwargs):
SimpleGladeApp.__init__(self, path, root, domain, **kwargs)
###########################################################
#
# Display the new window
#
###########################################################
def new(self):
self.get_widget("window1").set_title(_me.string('name_to_read'))
self.get_widget("lblThreshold").set_text(_me.string('widget_lblTest'))
self.get_widget("btnAdd").set_label(_me.string('widget_lblSet'))
self.get_widget('txtValue').set_text('1.0')
self.get_widget('txtTime').set_text('0.1')
self.get_widget('cbbEvent').append_text(_me.string('conf_lblChange'))
self.get_widget('cbbEvent').append_text(_me.string('conf_lblThreshold'))
self.get_widget('cbbEvent').set_active(0)
self.get_widget("lblEvent").set_text(_me.string('conf_lblEvent'))
self.get_widget("lblType").set_text(_me.string('conf_lblType'))
self.get_widget("lblValue").set_text(_me.string('conf_lblValue'))
self.get_widget("lblTime").set_text(_me.string('conf_lblTime'))
self.get_widget("lblNotify").set_text(_me.string('conf_lblNotified'))
self.get_widget("lblScript").set_text(_me.string('conf_lblBehavior'))
self.get_widget("lblBtnApply").set_text(_me.string('widget_lblBtnApply'))
tab = _me.get_param('test_tab')
self.get_widget('cbbEvent').set_active(tab[0][1])
self.get_widget('cbbType').set_active(tab[0][2])
self.get_widget('txtValue').set_text(str(tab[0][3]))
self.get_widget('txtTime').set_text(str(tab[0][4]))
self.get_widget('chkNotify').set_active(tab[0][5])
if tab[0][6] != None:
self.get_widget('Behavior').set_filename(str(tab[0][6]))
thread.start_new_thread(self.update, ())
###########################################################
#
# Update the values
#
###########################################################
def update_value(self):
self.measure.changetext = _me.string('conf_lblChange')
self.measure.thresholdtext = _me.string('conf_lblThreshold')
try:
self.graph.battery = _me.string('battery')
self.graph.plugged = _me.string('plugged')
self.graph.charging = _me.string('charging')
except:
print sys.exc_info()
###########################################################
#
# Event functions
#
###########################################################
def on_window1_destroy(self, widget, *args):
_me.get_param('measure').GUI_on = False
self.measure.GUI_on = False
def on_btnAdd_clicked(self, widget, *args):
length = len(_me.get_param('config'))
self.verify_value()
value = []
value = [(length + 1),
self.get_widget('cbbEvent').get_active(),
self.get_widget('cbbType').get_active(),
float(self.get_widget('txtValue').get_text()),
float(self.get_widget('txtTime').get_text()),
self.get_widget('chkNotify').get_active(),
str(self.get_widget('Behavior').get_filename()),
False,
0]
self.measure.event_tab = _me.get_param('config')
verify_tab = _me.get_funct('verify_tab')
if verify_tab(value):
self.measure.event_tab.append(value)
refresh_tree = _me.get_funct('refresh_tree')
refresh_tree()
def on_btnApply_clicked(self, widget, *args):
length = len(_me.get_param('config'))
self.verify_value()
value = []
value = [(length + 1),
self.get_widget('cbbEvent').get_active(),
self.get_widget('cbbType').get_active(),
float(self.get_widget('txtValue').get_text()),
float(self.get_widget('txtTime').get_text()),
self.get_widget('chkNotify').get_active(),
str(self.get_widget('Behavior').get_filename()),
False,
0]
self.measure.test_tab[0] = value
_me.set_param('test_tab', self.measure.test_tab)
def on_expander_activate(self, widget, *args):
self.get_widget('txtValue').set_text(str(self.measure.test_tab[0][3]))
self.get_widget('txtTime').set_text(str(self.measure.test_tab[0][4]))
###########################################################
#
# On combo box event
#
###########################################################
def on_cbb_conf_event_changed(self, widget, *args):
if self.get_widget('cbbEvent').get_active() == 0:
for i in range (4):
self.get_widget('cbbType').remove_text(0)
self.get_widget('cbbType').append_text(_me.string('conf_lblDrop'))
self.get_widget('cbbType').append_text(_me.string('conf_lblRaise'))
self.get_widget('cbbType').append_text(_me.string('conf_lblChangeD'))
self.get_widget('cbbType').append_text(_me.string('conf_lblChangeU'))
self.get_widget('cbbType').set_active(0)
else:
for i in range (4):
self.get_widget('cbbType').remove_text(0)
self.get_widget('cbbType').append_text(_me.string('conf_lblIncrease'))
self.get_widget('cbbType').append_text(_me.string('conf_lblDecrease'))
self.get_widget('cbbType').append_text(_me.string('conf_lblBoth'))
self.get_widget('cbbType').set_active(0)
###########################################################
#
# Value integrity control
#
###########################################################
def check_float_value(self, value, minimum, maximum):
try:
value = float(value)
except:
value = float(minimum)
if value < float(minimum):
value = float(minimum)
elif value > float(maximum):
value = float(maximum)
return value
def update(self):
self.graph = Graph()
_me.set_param('graph', self.graph)
#_me.update_informations()
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.update_value()
self.graph.set_size_request(400, 200)
gtk.gdk.threads_enter()
layout = self.get_widget('vbox2')
layout.add(self.graph)
layout.show_all()
gtk.gdk.threads_leave()
def verify_value(self):
if self.get_widget('cbbEvent').get_active() == 0:
maximum = 2.5
minimum = 0.025
else:
maximum = 6.5
minimum = 4.0
try:
float(self.get_widget('txtTime').get_text())
except:
self.get_widget('txtTime').set_text('1.0')
if float(self.get_widget('txtTime').get_text()) < self.measure.rate:
self.get_widget('txtTime').set_text(str(self.measure.rate))
if float(self.get_widget('txtTime').get_text()) > self.measure.rate * self.measure.sample:
self.get_widget('txtTime').set_text(str(self.measure.rate * self.measure.sample))
try:
float(self.get_widget('txtValue').get_text())
except:
self.get_widget('txtValue').set_text(str(minimum))
if float(self.get_widget('txtValue').get_text()) < minimum:
self.get_widget('txtValue').set_text(str(minimum))
if float(self.get_widget('txtValue').get_text()) > maximum:
self.get_widget('txtValue').set_text(str(maximum))
PK b88FjhK hK % Scripts/Python/GUI/widget/other.glade
True
Widget
GTK_WINDOW_TOPLEVEL
GTK_WIN_POS_NONE
False
600
449
False
False
True
False
False
GDK_WINDOW_TYPE_HINT_NORMAL
GDK_GRAVITY_NORTH_WEST
True
False
True
False
0
True
False
0
0
True
True
True
True
False
0
5
400
True
0
0.5
GTK_SHADOW_ETCHED_IN
True
0.5
0.5
1
1
0
0
12
0
373
197
True
80
24
True
True
True
True
0
True
●
False
200
35
80
24
True
True
True
True
0
True
●
False
284
35
88
30
True
False
True
104
32
88
16
True
Type
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
104
8
80
16
True
Value
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
200
8
80
16
True
Time
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
284
8
96
16
True
Notified?
False
False
GTK_JUSTIFY_LEFT
False
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
0
72
144
16
True
Behavior script
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
120
72
144
30
True
Select A File
GTK_FILE_CHOOSER_ACTION_OPEN
True
False
False
-1
120
96
24
24
True
True
GTK_RELIEF_NORMAL
False
False
False
True
32
96
88
30
True
False
True
8
32
88
16
True
Event
False
False
GTK_JUSTIFY_LEFT
True
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
8
8
144
29
True
True
GTK_RELIEF_NORMAL
True
True
0.5
0.5
0
0
0
0
0
0
True
False
2
True
gtk-yes
4
0.5
0.5
0
0
0
False
False
True
Apply changes
True
False
GTK_JUSTIFY_LEFT
False
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
0
False
False
8
160
144
29
True
True
button1
True
GTK_RELIEF_NORMAL
True
176
160
True
False
True
GTK_JUSTIFY_LEFT
False
False
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
label_item
True
True
Test notifications
False
False
GTK_JUSTIFY_LEFT
False
True
0.5
0.5
0
0
PANGO_ELLIPSIZE_NONE
-1
False
0
label_item
0
True
True
PK Ov88
$ $ Strings/fr_ALL.xml
Le niveau de la batterie a passé le seuil
Le niveau de la batterie a changé
Le niveau de la batterie a chuté puis augmenté
Le niveau de la batterie a augmenté puis chuté
Le niveau de la batterie est passé en dessous du seuil
Le niveau de la batterie a chuté
Le niveau de la batterie est passé en dessus du seuil
Comportement principal
Le niveau de la batterie a augmenté
Batteries faibles
Batteries pleines
Sur batteries
et les batteries sont en train d'être rechargée
En charge
Ajouter
Supprimer
Modifier
Enlever
Comportement
Deux directions
Changement
Chute et augmente
Augmente et chute
Contrôle
Diminue
Comportement pas défaut
Chute
Evènement
Augmente
Non notifié
Notifié ?
Notifié
Accroissement
Rafraichissement
Points
Seuil
Temps (sec.)
Type
Valeur (V)
La charge de la batterie est terminée
Les batteries sont pleines
A propos
Valider
Auteur
Annuler
Assignation
Délai (sec)
Description
Rafraichissement :
Set
Contrôle
Nombre de points :
Mise à jour
Version
Paramètres
-- Les évènements :
Deux grands types d'évènements peuvent avoir lieu, contenant chacun diverses options :
Les changements :
Les changements sont de évènements qui se produisent dans un laps de temps donné.
Les quatre types de changements sont :
- Chute
- Augmentation
- Une chute suivie d'une augmentation
- Une augmentation suivie d'une chute
Par exemple, un évènement peut avoir lieu si le niveau de la batterie diminue de 0.1V dans un laps de temps de dix secondes.
Les seuils :
Les évènements de seuils se déclenche lorsque le niveau de batterie atteint un certain niveau.
Le passage du seuil peut se faire :
- par une augmentation (dépassement du seuil)
- par une diminution (passage en dessous du seuil)
- dans les deux directions.
-- Les fenêtres :
- La fenêtre de configuration :
Cette fenêtre reprend toutes les options de configuration du gadget, notamment le taux de rafraîchissement ainsi que le nombre de points affichés sur le graphique.
Des évènements, pouvant entraîner une notification, peuvent également être enregistrés.
Si aucun script externe n'est spécifié, un comportement de base se déclenchera.
Les évènements peuvent à tous moment être modifiés ou supprimés, par simple sélection de la ligne dans le tableau.
Une option permet de rejeter les mesures lorsque les moteurs fonctionnent.
- La fenêtre du gadget :
Cette fenêtre affiche le graphique de la batterie.
Lorsque cette fenêtre est affichée, les évènements enregistrés dans la fenêtre de configuration ne sont plus notifiés.
Cette fenêtre permet de tester diverses configurations et de les ajouter dans le tableau de configuration.
Limite supérieure
Limite inférieure
Rejeter les mesures lorsque les moteurs fonctionnent
Le niveau des batteries est faible
J'ai trouvé la lumière !
Moniteur de batteries
Le niveau des batteries est bon
et je suis alimenté par les batteries
et l'alimentation est connectée
Connecté
Bruno8k
Activer le script
Deux directions
Appliquer
Changement
Changement inf.
Changement sup.
Contrôle
Decroissance
Afficher le seuil sur le graph.
Chute
Evènement
Accroissement
Notifé
Augmentation
Ajouter a la config.
Notifications
Seuil
Valeur (V)
PK b883Tv9 9 Pictures/Icons/gadget.pngPNG
IHDR p
n tEXtSoftware Adobe ImageReadyqe<