X-Git-Url: http://git.maemo.org/git/?p=pedometerwidget;a=blobdiff_plain;f=src%2Fusr%2Flib%2Fhildon-desktop%2Fpedometer_widget_home.py;h=5e1b7359ff5cb1123ca005d990c896e726aecc93;hp=b75a0a4db847245cc0448ffa098866c582628f7c;hb=749abb06cea098136e96e42c5e335242fe00b31d;hpb=b37e38f08cb2123a5114355f09d0a1454b8f4d07 diff --git a/src/usr/lib/hildon-desktop/pedometer_widget_home.py b/src/usr/lib/hildon-desktop/pedometer_widget_home.py index b75a0a4..5e1b735 100644 --- a/src/usr/lib/hildon-desktop/pedometer_widget_home.py +++ b/src/usr/lib/hildon-desktop/pedometer_widget_home.py @@ -35,8 +35,15 @@ UNIT = PATH + "/unit" ASPECT = PATH + "/aspect" SECONDVIEW = PATH + "/secondview" GRAPHVIEW = PATH + "/graphview" +NOIDLETIME = PATH + "/noidletime" LOGGING = PATH + "/logging" +ALARM_PATH = PATH + "/alarm" +ALARM_ENABLE = ALARM_PATH + "/enable" +ALARM_FNAME = ALARM_PATH + "/fname" +ALARM_TYPE = ALARM_PATH + "/type" +ALARM_INTERVAL = ALARM_PATH + "/interval" + ICONSPATH = "/opt/pedometerhomewidget/" unit = 0 @@ -146,6 +153,12 @@ class PedoValues(): self.dist + other.dist, self.calories + other.calories) + def __sub__(self, other): + return PedoValues(self.time - other.time, + self.steps - other.steps, + self.dist - other.dist, + self.calories - other.calories) + def get_print_time(self): tdelta = self.time hours = int(tdelta / 3600) @@ -167,7 +180,7 @@ class PedoValues(): return "%d m" % self.dist else: return "%d ft" % int(self.dist * 3.2808) - + def get_avg_speed(self): conv = 0 if self.unit: @@ -179,7 +192,7 @@ class PedoValues(): return 0 speed = 1.0 * self.dist / self.time return speed * conv - + def get_print_avg_speed(self): suffix = "" conv = 0 @@ -231,7 +244,7 @@ class PedoRepository(Singleton): self.values[when] = values def get_last_7_days(self): - ret = [] + ret = [] day = date.today() for i in range(7): try: @@ -267,17 +280,17 @@ class PedoRepository(Singleton): for k, v in self.values.iteritems(): ret = ret + v return ret - + def get_today_values(self): try: return self.values[date.today()] except KeyError: return PedoValues() - + def get_this_week_values(self): day = date.today() ret = PedoValues() - while True: + while True: try: ret += self.values[day] except: @@ -285,9 +298,9 @@ class PedoRepository(Singleton): if day.weekday() == 0: break day = day - timedelta(days=1) - - return ret - + + return ret + class PedoRepositoryXML(PedoRepository): DIR = os.path.join(os.path.expanduser("~"), ".pedometer") FILE = os.path.join(DIR, "data.xml") @@ -310,7 +323,7 @@ class PedoRepositoryXML(PedoRepository): time = float(v.getAttribute("time")) day = date.fromordinal(d) self.values[day] = PedoValues(time, steps, dist, calories) - + f.close() except Exception, e: logger.error("Error while loading data from xml file: %s" % e) @@ -340,7 +353,6 @@ class PedoRepositoryXML(PedoRepository): except Exception, e: logger.error("Error while saving data to xml file: %s" % e) - class PedoRepositoryPickle(PedoRepository): DIR = os.path.join(os.path.expanduser("~"), ".pedometer") FILE = os.path.join(DIR, "pickle.log") @@ -366,6 +378,61 @@ class PedoRepositoryPickle(PedoRepository): except Exception, e: logger.error("Error while saving data to pickle: %s" % e) +class AlarmController(Singleton): + enable = False + fname = "/home/user/MyDocs/.sounds/Ringtones/Bicycle.aac" + interval = 5 + type = 0 + + def __init__(self): + self.client = gconf.client_get_default() + try: + self.enable = self.client.get_bool(ALARM_ENABLE) + self.fname = self.client.get_string(ALARM_FNAME) + self.interval = self.client.get_int(ALARM_INTERVAL) + self.type = self.client.get_int(ALARM_TYPE) + except: + self.client.set_bool(ALARM_ENABLE, self.enable) + self.client.set_string(ALARM_FNAME, self.fname) + self.client.set_int(ALARM_INTERVAL, self.interval) + self.client.set_int(ALARM_TYPE, self.type) + + def update(self): + pass + + def play(self): + pass + + def set_enable(self, value): + self.enable = value + self.client.set_bool(ALARM_ENABLE, value) + + def get_enable(self): + return self.enable + + def set_alarm_file(self, fname): + self.fname = fname + self.client.set_string(ALARM_FNAME, fname) + + def get_alarm_file(self): + if self.fname == None: + return "" + return self.fname + + def set_interval(self, interval): + self.interval = interval + self.client.set_int(ALARM_INTERVAL, interval) + + def get_interval(self): + return self.interval + + def set_type(self, type): + self.type = type + self.client.set_int(ALARM_TYPE, type) + + def get_type(self): + return self.type + class PedoController(Singleton): mode = 0 unit = 0 @@ -373,23 +440,24 @@ class PedoController(Singleton): #what to display in second view - 0 - alltime, 1 - today, 2 - week second_view = 0 callback_update_ui = None + no_idle_time = False STEP_LENGTH = 0.7 #values for the two views in the widget ( current and day/week/alltime) v = [PedoValues(), PedoValues()] - startTime = 0 + last_time = 0 is_running = False - graph_controller = None - + + observers = [] + def __init__(self): self.pedometer = PedoCounter(self.steps_detected) self.pedometerInterval = PedoIntervalCounter() self.pedometerInterval.set_mode(self.mode) self.repository = PedoRepositoryXML() self.repository.load() - - self.graph_controller = GraphController() + self.load_values() def load_values(self): @@ -407,10 +475,10 @@ class PedoController(Singleton): def start_pedometer(self): self.v[0] = PedoValues() - self.startTime = time.time() + self.last_time = time.time() self.is_running = True self.pedometer.start() - self.notify_UI(True) + self.notify(True) def stop_pedometer(self): self.is_running = False @@ -433,20 +501,24 @@ class PedoController(Singleton): self.v[0].calories = self.get_calories(self.v[0].steps) def steps_detected(self, cnt, last_steps=False): - self.v[0].steps += cnt - self.v[0].dist += self.get_distance(cnt) - self.v[0].calories += self.get_distance(cnt) - self.v[0].time = time.time() - self.startTime - if last_steps: - self.save_values() - self.notify_UI() + if not last_steps and cnt == 0 and self.no_idle_time: + logger.info("No steps detected, timer is paused") else: - self.notify_UI(True) + self.v[0].steps += cnt + self.v[0].dist += self.get_distance(cnt) + self.v[0].calories += self.get_distance(cnt) + self.v[0].time += time.time() - self.last_time + if last_steps: + self.save_values() + self.notify() + else: + self.notify(True) + self.last_time = time.time() def set_mode(self, mode): self.mode = mode self.set_height(self.height_interval) - self.notify_UI() + self.notify() def set_unit(self, new_unit): self.unit = new_unit @@ -455,7 +527,7 @@ class PedoController(Singleton): def set_second_view(self, second_view): self.second_view = second_view self.load_values() - self.notify_UI() + self.notify() def set_callback_ui(self, func): self.callback_update_ui = func @@ -476,7 +548,10 @@ class PedoController(Singleton): #increase step length if RUNNING if self.mode == 1: self.STEP_LENGTH *= 1.45 - self.notify_UI() + self.notify() + + def set_no_idle_time(self, value): + self.no_idle_time = value def get_distance(self, steps=None): if steps == None: @@ -486,11 +561,23 @@ class PedoController(Singleton): def get_calories(self, steps): return steps - def notify_UI(self, optional=False): + def add_observer(self, func): + try: + self.observers.index(func) + except: + self.observers.append(func) + + def remove_observer(self, func): + self.observers.remove(func) + + def notify(self, optional=False): if self.callback_update_ui is not None: self.callback_update_ui() - self.graph_controller.update_ui(optional) - + + for func in self.observers: + func(optional) + + class PedoCounter(Singleton): COORD_FNAME = "/sys/class/i2c-adapter/i2c-3/3-001d/coord" COORD_FNAME_SDK = "/home/andrei/pedometer-widget-0.1/date.txt" @@ -509,7 +596,7 @@ class PedoCounter(Singleton): def __init__(self, update_function=None): if not os.path.exists(self.COORD_FNAME): self.COORD_FNAME = self.COORD_FNAME_SDK - + self.interval_counter = PedoIntervalCounter() self.update_function = update_function @@ -622,10 +709,10 @@ class CustomButton(hildon.Button): return self.retval class CustomEventBox(gtk.EventBox): - + def __init__(self): gtk.EventBox.__init__(self) - + def do_expose_event(self, event): self.context = self.window.cairo_create() self.context.rectangle(event.area.x, event.area.y, @@ -652,28 +739,29 @@ class GraphController(Singleton): def __init__(self): self.repository = PedoRepositoryXML() self.last_update = 0 - + PedoController().add_observer(self.update_ui) + def set_graph(self, widget): - self.widget = widget + self.widget = widget self.update_ui() - + def set_current_view(self, view): """ current_view % len(ytitles) - gives the ytitle current_view / len(ytitles) - gives the xtitle - """ - self.current_view = view + """ + self.current_view = view if self.current_view == len(self.ytitles) * len(self.xtitles): self.current_view = 0 self.x_id = self.current_view / len(self.ytitles) self.y_id = self.current_view % len(self.ytitles) - + def next_view(self): self.set_current_view(self.current_view+1) self.update_ui() return self.current_view - + def last_weeks_labels(self): d = date.today() delta = timedelta(days=7) @@ -682,7 +770,7 @@ class GraphController(Singleton): ret.append(d.strftime("Week %W")) d = d - delta return ret - + def compute_values(self): labels = [] if self.x_id == 0: @@ -692,17 +780,17 @@ class GraphController(Singleton): for i in range(7): labels.append(d.ctime().split()[0]) d = d - delta - + elif self.x_id == 1: values = self.repository.get_last_weeks() d = date.today() for i in range(7): labels.append(d.strftime("Week %W")) - d = d - timedelta(days=7) + d = d - timedelta(days=7) else: - values = self.repository.get_today() + values = self.repository.get_today() #TODO get labels - + if self.y_id == 0: yvalues = [line.steps for line in values] elif self.y_id == 1: @@ -711,28 +799,25 @@ class GraphController(Singleton): yvalues = [line.dist for line in values] else: yvalues = [line.calories for line in values] - + #determine values for y lines in graph diff = self.get_best_interval_value(max(yvalues)) ytext = [] for i in range(6): - s = str(int(i*diff)) - while len(s) < 5: - s = ' ' + s - ytext.append(s) - + ytext.append(str(int(i*diff))) + if self.widget is not None: yvalues.reverse() labels.reverse() self.widget.values = yvalues self.widget.ytext = ytext self.widget.xtext = labels - self.widget.max_value = diff * 5 + self.widget.max_value = diff * 5 self.widget.text = self.xtitles[self.x_id] + " / " + self.ytitles[self.y_id] self.widget.queue_draw() else: logger.error("Widget not set in GraphController") - + def get_best_interval_value(self, max_value): diff = 1.0 * max_value / 5 l = len(str(int(diff))) @@ -741,43 +826,44 @@ class GraphController(Singleton): if val == 0: val = 1 return val - + def update_ui(self, optional=False): """update graph values every x seconds""" if optional and self.last_update - time.time() < 600: return if self.widget is None: return - - print "update_ui" + self.compute_values() self.last_update = time.time() - + class GraphWidget(gtk.DrawingArea): - + def __init__(self): gtk.DrawingArea.__init__(self) self.set_size_request(-1, 150) self.yvalues = 5 + + """sample values""" self.ytext = [" 0", "1000", "2000", "3000", "4000", "5000"] self.xtext = ["Monday", "Tuesday", "Wednesday","Thursday", "Friday", "Saturday", "Sunday"] self.values = [1500, 3400, 4000, 3600, 3200, 0, 4500] self.max_value = 5000 self.text = "All time steps" - + def do_expose_event(self, event): context = self.window.cairo_create() - + # set a clip region for the expose event context.rectangle(event.area.x, event.area.y, event.area.width, event.area.height) context.clip() - + context.save() - + context.set_operator(cairo.OPERATOR_SOURCE) style = self.rc_get_style() - + if self.state == gtk.STATE_ACTIVE: color = style.lookup_color("SelectionColor") else: @@ -787,57 +873,65 @@ class GraphWidget(gtk.DrawingArea): context.paint() context.restore(); self.draw(context) - + def draw(self, cr): - print self.max_value - space_below = 20 + space_below = 20 space_above = 10 border_right = 10 border_left = 30 + rect = self.get_allocation() x = rect.width y = rect.height - + + cr.select_font_face("Purisa", cairo.FONT_SLANT_NORMAL, + cairo.FONT_WEIGHT_NORMAL) + cr.set_font_size(13) + + #check space needed to display ylabels + te = cr.text_extents(self.ytext[-1]) + border_left = te[2] + 7 + cr.set_source_rgb(1, 1, 1) cr.move_to(border_left, space_above) cr.line_to(border_left, y-space_below) cr.set_line_width(2) - cr.stroke() - + cr.stroke() + cr.move_to(border_left, y-space_below) cr.line_to(x-border_right, y-space_below) cr.set_line_width(2) - cr.stroke() - - ydiff = (y-space_above-space_below) / self.yvalues + cr.stroke() + + ydiff = (y-space_above-space_below) / self.yvalues for i in range(self.yvalues): yy = y-space_below-ydiff*(i+1) cr.move_to(border_left, yy) cr.line_to(x-border_right, yy) cr.set_line_width(0.8) cr.stroke() - - cr.select_font_face("Purisa", cairo.FONT_SLANT_NORMAL, - cairo.FONT_WEIGHT_NORMAL) - cr.set_font_size(13) + + for i in range(6): - yy = y - space_below - ydiff*i + 5 - cr.move_to(1, yy) + yy = y - space_below - ydiff*i + 5 + te = cr.text_extents(self.ytext[i]) + + cr.move_to(border_left-te[2]-2, yy) cr.show_text(self.ytext[i]) - + cr.set_font_size(15) - cr.move_to(x/3, y-5) + te = cr.text_extents(self.text) + cr.move_to((x-te[2])/2, y-5) cr.show_text(self.text) - + graph_x_space = x - border_left - border_right graph_y_space = y - space_below - space_above bar_width = graph_x_space*0.75 / len(self.values) bar_distance = graph_x_space*0.25 / (1+len(self.values)) - + #set dummy max value to avoid exceptions if self.max_value == 0: self.max_value = 100 - for i in range(len(self.values)): xx = border_left + (i+1)*bar_distance + i * bar_width yy = y-space_below @@ -845,19 +939,19 @@ class GraphWidget(gtk.DrawingArea): cr.set_source_rgba(1, 1, 1, 0.75) cr.rectangle(int(xx), int(yy-height), int(bar_width), int(height)) cr.fill() - + cr.set_source_rgba(1, 1, 1, 1) - cr.select_font_face("Purisa", cairo.FONT_SLANT_NORMAL, + cr.select_font_face("Purisa", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) - cr.set_font_size(13) - + cr.set_font_size(13) + cr.rotate(2*math.pi * (-45) / 180) for i in range(len(self.values)): xx = y - space_below - 10 - yy = border_left + (i+1)*bar_distance + i * bar_width - cr.move_to(-xx, yy + bar_width*1.25 / 2) + yy = border_left + (i+1)*bar_distance + i * bar_width + cr.move_to(-xx, yy + bar_width*1.25 / 2) cr.show_text(self.xtext[i]) - + class PedometerHomePlugin(hildondesktop.HomePluginItem): button = None @@ -869,20 +963,21 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): #second view ( day / week/ alltime) labelsT = {} - + second_view_labels = ["All-time", "Today", "This week"] controller = None pedometer = None pedometerInterval = None graph_controller = None - startTime = None mode = 0 height = 0 unit = 0 aspect = 0 second_view = 0 + graph_view = 0 + no_idle_time = False logging = False def __init__(self): @@ -890,7 +985,7 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): gobject.type_register(CustomEventBox) gobject.type_register(GraphWidget) - + self.client = gconf.client_get_default() try: self.mode = self.client.get_int(MODE) @@ -899,6 +994,7 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): self.aspect = self.client.get_int(ASPECT) self.second_view = self.client.get_int(SECONDVIEW) self.graph_view = self.client.get_int(GRAPHVIEW) + self.no_idle_time = self.client.get_bool(NOIDLETIME) self.logging = self.client.get_bool(LOGGING) except: @@ -908,6 +1004,7 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): self.client.set_int(ASPECT, 0) self.client.set_int(SECONDVIEW, 0) self.client.set_int(GRAPHVIEW, 0) + self.client.set_bool(NOIDLETIME, False) self.client.set_bool(LOGGING, False) self.controller = PedoController() @@ -916,10 +1013,13 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): self.controller.set_unit(self.unit) self.controller.set_second_view(self.second_view) self.controller.set_callback_ui(self.update_values) - + self.controller.set_no_idle_time(self.no_idle_time) + self.graph_controller = GraphController() self.graph_controller.set_current_view(self.graph_view) + self.alarm_controller = AlarmController() + self.button = CustomButton(ICONSPATH + "play.png") self.button.connect("clicked", self.button_clicked) @@ -968,26 +1068,25 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): eventBox.add(totalVBox) eventBox.connect("button-press-event", self.eventBox_clicked) eventBox.connect("button-release-event", self.eventBox_clicked_release) - - + mainHBox.add(buttonVBox) mainHBox.add(descVBox) mainHBox.add(currentVBox) mainHBox.add(eventBox) self.mainhbox = mainHBox - + graph = GraphWidget() self.graph_controller.set_graph(graph) - + eventBoxGraph = CustomEventBox() eventBoxGraph.set_visible_window(False) eventBoxGraph.add(graph) self.graph = graph eventBoxGraph.connect("button-press-event", self.eventBoxGraph_clicked) eventBoxGraph.connect("button-release-event", self.eventBoxGraph_clicked_release) - + self.mainvbox = gtk.VBox() - + self.mainvbox.add(mainHBox) self.mainvbox.add(eventBoxGraph) @@ -998,26 +1097,26 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): self.connect("unrealize", self.close_requested) self.set_settings(True) self.connect("show-settings", self.show_settings) - + def eventBoxGraph_clicked(self, widget, data=None): widget.set_state(gtk.STATE_ACTIVE) - + def eventBoxGraph_clicked_release(self, widget, data=None): self.graph_view = self.graph_controller.next_view() self.client.set_int(GRAPHVIEW, self.graph_view) - + widget.set_state(gtk.STATE_NORMAL) def eventBox_clicked(self, widget, data=None): widget.set_state(gtk.STATE_ACTIVE) - + def eventBox_clicked_release(self, widget, data=None): widget.set_state(gtk.STATE_NORMAL) - + self.second_view = (self.second_view + 1) % 3 self.controller.set_second_view(self.second_view) self.client.set_int(SECONDVIEW, self.second_view) - + def new_label_heading(self, title=""): l = gtk.Label(title) hildon.hildon_helper_set_logical_font(l, "SmallSystemFont") @@ -1054,6 +1153,98 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): def update_total(self): self.update_ui_values(self.labelsT, self.controller.get_second()) + def show_alarm_settings(self, main_button): + def choose_file(widget): + file = hildon.FileChooserDialog(self, gtk.FILE_CHOOSER_ACTION_OPEN, hildon.FileSystemModel() ) + file.show() + if ( file.run() == gtk.RESPONSE_OK): + fname = file.get_filename() + widget.set_value(fname) + self.alarm_controller.set_alarm_file(fname) + file.destroy() + + def test_sound(button): + try: + self.alarm_controller.play() + except Exception, e: + logger.error("Could not play alarm sound: %s" % e) + hildon.hildon_banner_show_information(self, "None", "Could not play alarm sound") + + def enableButton_changed(button): + value = button.get_active() + self.alarm_controller.set_enable(value) + if value: + main_button.set_value("Enabled") + else: + main_button.set_value("Disabled") + + def selectorType_changed(selector, data, labelEntry2): + self.alarm_controller.set_type(selector.get_active(0)) + labelEntry2.set_label(suffix[self.alarm_controller.get_type()]) + + dialog = gtk.Dialog() + dialog.set_title("Alarm settings") + dialog.add_button("OK", gtk.RESPONSE_OK) + + enableButton = hildon.CheckButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT) + enableButton.set_label("Enable alarm") + enableButton.set_active(self.alarm_controller.get_enable()) + enableButton.connect("toggled", enableButton_changed) + + testButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) + testButton.set_alignment(0, 0.8, 1, 1) + testButton.set_title("Test sound") + testButton.connect("pressed", test_sound) + + fileButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) + fileButton.set_alignment(0, 0.8, 1, 1) + fileButton.set_title("Alarm sound") + fileButton.set_value(self.alarm_controller.get_alarm_file()) + fileButton.connect("pressed", choose_file) + + labelEntry = gtk.Label("Notify every:") + suffix = ["mins", "steps", "m/ft", "calories"] + labelEntry2 = gtk.Label(suffix[self.alarm_controller.get_type()]) + intervalEntry = hildon.Entry(gtk.HILDON_SIZE_AUTO_WIDTH) + intervalEntry.set_text(str(self.alarm_controller.get_interval())) + + selectorType = hildon.TouchSelector(text=True) + selectorType.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE) + selectorType.append_text("Time") + selectorType.append_text("Steps") + selectorType.append_text("Distance") + selectorType.append_text("Calories") + selectorType.connect("changed", selectorType_changed, labelEntry2) + + typePicker = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) + typePicker.set_alignment(0.0, 0.5, 1.0, 1.0) + typePicker.set_title("Alarm type") + typePicker.set_selector(selectorType) + typePicker.set_active(self.alarm_controller.get_type()) + + hbox = gtk.HBox() + hbox.add(labelEntry) + hbox.add(intervalEntry) + hbox.add(labelEntry2) + + dialog.vbox.add(enableButton) + dialog.vbox.add(fileButton) + dialog.vbox.add(typePicker) + dialog.vbox.add(hbox) + dialog.show_all() + while 1: + response = dialog.run() + if response != gtk.RESPONSE_OK: + break + try: + value = int(intervalEntry.get_text()) + self.alarm_controller.set_interval(value) + break + except: + hildon.hildon_banner_show_information(self, "None", "Invalid interval") + + dialog.destroy() + def show_settings(self, widget): def reset_total_counter(arg): widget.totalCounter = 0 @@ -1061,6 +1252,9 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): widget.update_total() hildon.hildon_banner_show_information(self, "None", "Total counter was resetted") + def alarmButton_pressed(widget): + self.show_alarm_settings(widget) + def selector_changed(selector, data): widget.mode = selector.get_active(0) widget.client.set_int(MODE, widget.mode) @@ -1071,7 +1265,6 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): widget.client.set_int(HEIGHT, widget.height) widget.controller.set_height(widget.height) - def selectorUnit_changed(selector, data): widget.unit = selectorUnit.get_active(0) widget.client.set_int(UNIT, widget.unit) @@ -1086,22 +1279,37 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): widget.logging = checkButton.get_active() widget.client.set_bool(LOGGING, widget.logging) + def idleButton_changed(idleButton): + widget.no_idle_time = idleButton.get_active() + widget.client.set_bool(NOIDLETIME, widget.no_idle_time) + widget.controller.set_no_idle_time(widget.no_idle_time) + dialog = gtk.Dialog() dialog.set_title("Settings") - dialog.add_button("OK", gtk.RESPONSE_OK) + + button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) button.set_title("Reset total counter") button.set_alignment(0, 0.8, 1, 1) button.connect("clicked", reset_total_counter) + alarmButton = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) + alarmButton.set_title("Alarm") + if self.alarm_controller.get_enable(): + alarmButton.set_value("Enabled") + else: + alarmButton.set_value("Disabled") + alarmButton.set_alignment(0, 0.8, 1, 1) + alarmButton.connect("clicked", alarmButton_pressed) + selector = hildon.TouchSelector(text=True) selector.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE) selector.append_text("Walk") selector.append_text("Run") selector.connect("changed", selector_changed) - modePicker = hildon.ButtonPickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) + modePicker = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL) modePicker.set_alignment(0.0, 0.5, 1.0, 1.0) modePicker.set_title("Select mode") modePicker.set_selector(selector) @@ -1153,13 +1361,20 @@ class PedometerHomePlugin(hildondesktop.HomePluginItem): logButton.set_active(widget.logging) logButton.connect("toggled", logButton_changed) + idleButton = hildon.CheckButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT) + idleButton.set_label("Pause time when not walking") + idleButton.set_active(widget.no_idle_time) + idleButton.connect("toggled", idleButton_changed) + pan_area = hildon.PannableArea() vbox = gtk.VBox() vbox.add(button) + vbox.add(alarmButton) vbox.add(modePicker) vbox.add(heightPicker) vbox.add(unitPicker) vbox.add(UIPicker) + vbox.add(idleButton) #vbox.add(logButton) pan_area.add_with_viewport(vbox)