Merge branch 'master' of https://vcs.maemo.org/git/pedometerwidget
[pedometerwidget] / src / usr / lib / hildon-desktop / pedometer_widget_home.py
1 #Pedometer Home Widget
2 #Author: Mirestean Andrei < andrei.mirestean at gmail.com >
3 #
4 #This program is free software: you can redistribute it and/or modify
5 #it under the terms of the GNU General Public License as published by
6 #the Free Software Foundation, either version 3 of the License, or
7 #(at your option) any later version.
8 #
9 #This program is distributed in the hope that it will be useful,
10 #but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #GNU General Public License for more details.
13 #
14 #You should have received a copy of the GNU General Public License
15 #along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 import gtk
18 import cairo
19 import hildondesktop
20 import gobject
21 import os
22 import time
23 import hildon
24 import gconf
25
26 PATH="/apps/pedometerhomewidget"
27 COUNTER=PATH+"/counter"
28 TIMER=PATH+"/timer"
29 MODE=PATH+"/mode"
30 HEIGHT=PATH+"/height"
31 UNIT=PATH+"/unit"
32 ASPECT=PATH+"/aspect"
33 LOGGING=PATH+"/logging"
34
35 ICONSPATH = "/opt/pedometerhomewidget/"
36
37 class PedoIntervalCounter:
38     MIN_THRESHOLD = 500
39     MIN_TIME_STEPS = 0.5
40     x = []
41     y = []
42     z = []
43     t = []
44
45     #TODO: check if last detected step is at the end of the interval
46
47     def __init__(self, coords, tval):
48         self.x = coords[0]
49         self.y = coords[1]
50         self.z = coords[2]
51         self.t = tval
52
53     def setThreshold(self, value):
54         self.MIN_THRESHOLD = value
55
56     def setTimeSteps(self, value):
57         self.MIN_TIME_STEPS = value
58
59     def calc_mean(self, vals):
60         sum = 0
61         for i in vals:
62             sum+=i
63         if len(vals) > 0:
64             return sum / len(vals)
65         return 0
66
67     def calc_stdev(self, vals):
68         rez = 0
69         mean = self.calc_mean(vals)
70         for i in vals:
71             rez+=pow(abs(mean-i),2)
72         return math.sqrt(rez/len(vals))
73
74     def calc_threshold(self, vals):
75         vmax = max(vals)
76         vmin = min(vals)
77         mean = self.calc_mean(vals)
78         threshold = max (abs(mean-vmax), abs(mean-vmin))
79         return threshold
80
81     def count_steps(self, vals, t):
82         threshold = self.MIN_THRESHOLD
83         mean = self.calc_mean(vals)
84         cnt = 0
85
86         i=0
87         while i < len(vals):
88             if abs(vals[i] - mean) > threshold:
89                 cnt+=1
90                 ntime = t[i] + 0.5
91                 while i < len(vals) and t[i] < ntime:
92                     i+=1
93             i+=1
94         return cnt
95
96     def get_best_values(self, x, y, z):
97         dev1 = self.calc_stdev(x)
98         dev2 = self.calc_stdev(y)
99         dev3 = self.calc_stdev(z)
100         dev_max = max(dev1, dev2, dev3)
101
102         if ( abs(dev1 - dev_max ) < 0.001):
103             logger.info("X chosen as best axis, stdev %f" % dev1)
104             return x
105         elif (abs(dev2 - dev_max) < 0.001):
106             logger.info("Y chosen as best axis, stdev %f" % dev2)
107             return y
108         else:
109             logger.info("Z chosen as best axis, stdev %f" % dev3)
110             return z
111
112     def number_steps(self):
113         vals = self.get_best_values(self.x, self.y, self.z)
114         return self.count_steps(vals, self.t)
115
116 class PedoCounter():
117     COORD_FNAME = "/sys/class/i2c-adapter/i2c-3/3-001d/coord"
118     COORD_FNAME_SDK = "/home/andrei/pedometer-widget-0.1/date.txt"
119     LOGFILE = "/home/user/log_pedometer"
120     COORD_GET_INTERVAL = 10
121     COUNT_INTERVAL = 5
122
123     STEP_LENGTH = 0.7
124
125     MIN_THRESHOLD = 500
126     MIN_TIME_STEPS = 0.5
127
128     counter = 0
129     stop_requested = False
130     update_function = None
131     logging = False
132     isRunning = False
133
134     mode = 0
135
136     def __init__(self, update_function = None):
137         if not os.path.exists(self.COORD_FNAME):
138             self.COORD_FNAME = self.COORD_FNAME_SDK
139
140         self.update_function = update_function
141
142     def set_mode(self, mode):
143         #runnig, higher threshold to prevent fake steps
144         self.mode = mode
145         if mode == 1:
146             self.MIN_THRESHOLD = 650
147             self.MIN_TIME_STEPS = 0.35
148         #walking
149         else:
150             self.MIN_THRESHOLD = 500
151             self.MIN_TIME_STEPS = 0.5
152
153     def set_logging(self, value):
154         self.logging = value
155
156     #set height, will affect the distance
157     def set_height(self, height_interval):
158         if height_interval == 0:
159             self.STEP_LENGTH = 0.59
160         elif height_interval == 1:
161             self.STEP_LENGTH = 0.64
162         elif height_interval == 2:
163             self.STEP_LENGTH = 0.71
164         elif height_interval == 3:
165             self.STEP_LENGTH = 0.77
166         elif height_interval == 4:
167             self.STEP_LENGTH = 0.83
168         #increase step length if RUNNING
169         if self.mode == 1:
170             self.STEP_LENGTH *= 1.45
171
172     def get_rotation(self):
173         f = open(self.COORD_FNAME, 'r')
174         coords = [int(w) for w in f.readline().split()]
175         f.close()
176         return coords
177
178     def reset_counter(self):
179         counter = 0
180
181     def get_counter(self):
182         return counter
183
184     def start(self):
185         logger.info("Counter started")
186         self.isRunning = True
187         if self.logging:
188             fname = "%d_%d_%d_%d_%d_%d" % time.localtime()[0:6]
189             self.file = open(self.LOGFILE + fname + ".txt", "w")
190         gobject.idle_add(self.run)
191
192     def run(self):
193         self.coords = [[], [], []]
194         self.stime = time.time()
195         self.t = []
196         gobject.timeout_add(self.COORD_GET_INTERVAL, self.read_coords)
197         return False
198
199     def read_coords(self):
200         x,y,z = self.get_rotation()
201         self.coords[0].append(int(x))
202         self.coords[1].append(int(y))
203         self.coords[2].append(int(z))
204         now = time.time()-self.stime
205         if self.logging:
206             self.file.write("%d %d %d %f\n" %(self.coords[0][-1], self.coords[1][-1], self.coords[2][-1], now))
207
208         self.t.append(now)
209         #call stop_interval
210         ret = True
211         if self.t[-1] > 5 or self.stop_requested:
212             ret = False
213             gobject.idle_add(self.stop_interval)
214         return ret
215
216     def stop_interval(self):
217         pic = PedoIntervalCounter(self.coords, self.t)
218         cnt = pic.number_steps()
219
220         logger.info("Number of steps detected for last interval %d, number of coords: %d" % (cnt, len(self.t)))
221
222         self.counter += cnt
223         logger.info("Total number of steps : %d" % self.counter)
224         gobject.idle_add(self.update_function, self.counter, cnt)
225
226         if self.stop_requested:
227             gobject.idle_add(self.stop)
228         else:
229             gobject.idle_add(self.run)
230         return False
231
232     def stop(self):
233         if self.logging:
234             self.file.close()
235         logger.info("Counter has finished")
236
237     def request_stop(self):
238         self.stop_requested = True
239         self.isRunning = False
240
241     def get_distance(self, steps=None):
242         if steps == None:
243             steps = self.counter
244         return self.STEP_LENGTH * steps;
245
246 class CustomButton(hildon.Button):
247     def __init__(self, icon):
248         hildon.Button.__init__(self, gtk.HILDON_SIZE_AUTO_WIDTH, hildon.BUTTON_ARRANGEMENT_VERTICAL)
249         self.icon = icon
250         self.set_size_request(int(32*1.4), int(30*1.0))
251         self.retval = self.connect("expose_event", self.expose)
252
253     def set_icon(self, icon):
254         self.icon = icon
255
256     def expose(self, widget, event):
257         self.context = widget.window.cairo_create()
258         self.context.rectangle(event.area.x, event.area.y,
259                             event.area.width, event.area.height)
260
261         self.context.clip()
262         rect = self.get_allocation()
263         self.context.rectangle(rect.x, rect.y, rect.width, rect.height)
264         self.context.set_source_rgba(1, 1, 1, 0)
265
266         style = self.rc_get_style()
267         color = style.lookup_color("DefaultBackgroundColor")
268         if self.state == gtk.STATE_ACTIVE:
269             style = self.rc_get_style()
270             color = style.lookup_color("SelectionColor")
271             self.context.set_source_rgba (color.red/65535.0, color.green/65335.0, color.blue/65535.0, 0.75);
272         self.context.fill()
273
274         #img = cairo.ImageSurface.create_from_png(self.icon)
275
276         #self.context.set_source_surface(img)
277         #self.context.set_source_surface(img, rect.width/2 - img.get_width() /2, 0)
278         img = gtk.Image()
279         img.set_from_file(self.icon)
280         buf = img.get_pixbuf()
281         buf =  buf.scale_simple(int(32 * 1.5), int(30 * 1.5), gtk.gdk.INTERP_BILINEAR)
282
283         self.context.set_source_pixbuf(buf, rect.x+(event.area.width/2-15)-8, rect.y+1)
284         self.context.scale(200,200)
285         self.context.paint()
286
287         return self.retval
288
289 class PedometerHomePlugin(hildondesktop.HomePluginItem):
290     button = None
291
292     #labels for current steps
293     labels = ["timer", "count", "dist", "avgSpeed"]
294     #labelsC = { "timer" : None, "count" : None, "dist" : None, "avgSpeed" : None }
295
296     #labels for all time steps
297     #labelsT = { "timer" : None, "count" : None, "dist" : None, "avgSpeed" : None }
298     labelsC = {}
299     labelsT = {}
300
301     pedometer = None
302     startTime = None
303
304     totalCounter = 0
305     totalTime = 0
306     mode = 0
307     height = 0
308     unit = 0
309
310     counter = 0
311     time = 0
312     aspect = 0
313     logging = False
314
315     def __init__(self):
316         hildondesktop.HomePluginItem.__init__(self)
317
318         self.client = gconf.client_get_default()
319         try:
320             self.totalCounter = self.client.get_int(COUNTER)
321             self.totalTime = self.client.get_int(TIMER)
322             self.mode = self.client.get_int(MODE)
323             self.height = self.client.get_int(HEIGHT)
324             self.unit = self.client.get_int(UNIT)
325             self.aspect = self.client.get_int(ASPECT)
326             self.logging = self.client.get_bool(LOGGING)
327         except:
328             self.client.set_int(COUNTER, 0)
329             self.client.set_int(TIMER, 0)
330             self.client.set_int(MODE, 0)
331             self.client.set_int(HEIGHT, 0)
332             self.client.set_int(UNIT, 0)
333             self.client.set_int(ASPECT, 0)
334             self.client.set_bool(LOGGING, False)
335
336         self.pedometer = PedoCounter(self.update_values)
337         self.pedometer.set_mode(self.mode)
338         self.pedometer.set_height(self.height)
339
340         #self.button = gtk.Button("Start")
341         self.button = CustomButton(ICONSPATH + "play.png")
342         self.button.connect("clicked", self.button_clicked)
343
344         self.create_labels(self.labelsC)
345         self.create_labels(self.labelsT)
346
347         self.update_ui_values(self.labelsC, 0, 0)
348         self.update_ui_values(self.labelsT, self.totalTime, self.totalCounter)
349
350         mainHBox = gtk.HBox(spacing=1)
351
352         descVBox = gtk.VBox(spacing=1)
353         descVBox.add(self.new_label_heading())
354         descVBox.add(self.new_label_heading("Time:"))
355         descVBox.add(self.new_label_heading("Steps:"))
356         descVBox.add(self.new_label_heading("Distance:"))
357         descVBox.add(self.new_label_heading("Avg Speed:"))
358
359         currentVBox = gtk.VBox(spacing=1)
360         currentVBox.add(self.new_label_heading("Current"))
361         currentVBox.add(self.labelsC["timer"])
362         currentVBox.add(self.labelsC["count"])
363         currentVBox.add(self.labelsC["dist"])
364         currentVBox.add(self.labelsC["avgSpeed"])
365         self.currentBox = currentVBox
366
367         totalVBox = gtk.VBox(spacing=1)
368         totalVBox.add(self.new_label_heading("Total"))
369         totalVBox.add(self.labelsT["timer"])
370         totalVBox.add(self.labelsT["count"])
371         totalVBox.add(self.labelsT["dist"])
372         totalVBox.add(self.labelsT["avgSpeed"])
373         self.totalBox = totalVBox
374
375         buttonVBox = gtk.VBox(spacing=1)
376         buttonVBox.add(self.new_label_heading(""))
377         buttonVBox.add(self.button)
378         buttonVBox.add(self.new_label_heading(""))
379
380         mainHBox.add(buttonVBox)
381         mainHBox.add(descVBox)
382         mainHBox.add(currentVBox)
383         mainHBox.add(totalVBox)
384
385         self.mainhbox = mainHBox
386
387         mainHBox.show_all()
388         self.add(mainHBox)
389         self.update_aspect()
390
391         self.connect("unrealize", self.close_requested)
392         self.set_settings(True)
393         self.connect("show-settings", self.show_settings)
394
395     def new_label_heading(self, title=""):
396         l = gtk.Label(title)
397         hildon.hildon_helper_set_logical_font(l, "SmallSystemFont")
398         return l
399
400     def create_labels(self, new_labels):
401         for label in self.labels:
402             l = gtk.Label()
403             hildon.hildon_helper_set_logical_font(l, "SmallSystemFont")
404             hildon.hildon_helper_set_logical_color(l, gtk.RC_FG, gtk.STATE_NORMAL, "ActiveTextColor")
405             new_labels[label] = l
406
407     def update_aspect(self):
408         if self.aspect == 0:
409             self.currentBox.show_all()
410             self.totalBox.show_all()
411         elif self.aspect == 1:
412             self.currentBox.show_all()
413             self.totalBox.hide_all()
414         else:
415             self.currentBox.hide_all()
416             self.totalBox.show_all()
417
418     def update_ui_values(self, labels, timer, steps):
419         def get_str_distance(meters):
420             if meters > 1000:
421                 if self.unit == 0:
422                     return "%.2f km" % (meters/1000)
423                 else:
424                     return "%.2f mi" % (meters/1609.344)
425             else:
426                 if self.unit == 0:
427                     return "%d m" % meters
428                 else:
429                     return "%d ft" % int(meters*3.2808)
430
431         def get_avg_speed(timer, dist):
432             suffix = ""
433             conv = 0
434             if self.unit:
435                 suffix = "mi/h"
436                 conv = 2.23693629
437             else:
438                 suffix = "km/h"
439                 conv = 3.6
440
441             if timer == 0:
442                 return "N/A " + suffix
443             speed = 1.0 *dist / timer
444             #convert from meters per second to km/h or mi/h
445             speed *= conv
446             return "%.2f %s" % (speed, suffix)
447
448         tdelta = timer
449         hours = int(tdelta / 3600)
450         tdelta -= 3600 * hours
451         mins = int(tdelta / 60)
452         tdelta -= 60 * mins
453         secs = int(tdelta)
454
455         strtime = "%.2d:%.2d:%.2d" % ( hours, mins, secs)
456
457         labels["timer"].set_label(strtime)
458         labels["count"].set_label(str(steps))
459
460         dist = self.pedometer.get_distance(steps)
461
462         labels["dist"].set_label(get_str_distance(dist))
463         labels["avgSpeed"].set_label(get_avg_speed(timer, dist))
464
465     def update_current(self):
466         self.update_ui_values(self.labelsC, self.time, self.counter)
467
468     def update_total(self):
469         self.update_ui_values(self.labelsT, self.totalTime, self.totalCounter)
470
471     def show_settings(self, widget):
472         def reset_total_counter(arg):
473             widget.totalCounter = 0
474             widget.totalTime = 0
475             widget.update_total()
476             hildon.hildon_banner_show_information(self,"None", "Total counter was resetted")
477
478         def selector_changed(selector, data):
479             widget.mode = selector.get_active(0)
480             widget.client.set_int(MODE, widget.mode)
481             widget.pedometer.set_mode(widget.mode)
482             widget.pedometer.set_height(widget.height)
483             widget.update_current()
484             widget.update_total()
485
486         def selectorH_changed(selector, data):
487             widget.height = selectorH.get_active(0)
488             widget.client.set_int(HEIGHT, widget.height)
489             widget.pedometer.set_height(widget.height)
490             widget.update_current()
491             widget.update_total()
492
493
494         def selectorUnit_changed(selector, data):
495             widget.unit = selectorUnit.get_active(0)
496             widget.client.set_int(UNIT, widget.unit)
497             widget.update_current()
498             widget.update_total()
499
500         def selectorUI_changed(selector, data):
501             widget.aspect = selectorUI.get_active(0)
502             widget.client.set_int(ASPECT, widget.aspect)
503             widget.update_aspect()
504
505         def logButton_changed(checkButton):
506             widget.logging = checkButton.get_active()
507             widget.client.set_bool(LOGGING, widget.logging)
508
509         dialog = gtk.Dialog()
510         dialog.set_title("Settings")
511
512         dialog.add_button("OK", gtk.RESPONSE_OK)
513         button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
514         button.set_title("Reset total counter")
515         button.set_alignment(0, 0.8, 1, 1)
516         button.connect("clicked", reset_total_counter)
517
518         selector = hildon.TouchSelector(text=True)
519         selector.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
520         selector.append_text("Walk")
521         selector.append_text("Run")
522         selector.connect("changed", selector_changed)
523
524         modePicker = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
525         modePicker.set_alignment(0.0, 0.5, 1.0, 1.0)
526         modePicker.set_title("Select mode")
527         modePicker.set_selector(selector)
528         modePicker.set_active(widget.mode)
529
530         selectorH = hildon.TouchSelector(text=True)
531         selectorH.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
532         selectorH.append_text("< 1.50 m")
533         selectorH.append_text("1.50 - 1.65 m")
534         selectorH.append_text("1.66 - 1.80 m")
535         selectorH.append_text("1.81 - 1.95 m")
536         selectorH.append_text(" > 1.95 m")
537         selectorH.connect("changed", selectorH_changed)
538
539         heightPicker = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
540         heightPicker.set_alignment(0.0, 0.5, 1.0, 1.0)
541         heightPicker.set_title("Select height")
542         heightPicker.set_selector(selectorH)
543         heightPicker.set_active(widget.height)
544
545         selectorUnit = hildon.TouchSelector(text=True)
546         selectorUnit.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
547         selectorUnit.append_text("Metric (km)")
548         selectorUnit.append_text("English (mi)")
549         selectorUnit.connect("changed", selectorUnit_changed)
550
551         unitPicker = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
552         unitPicker.set_alignment(0.0, 0.5, 1.0, 1.0)
553         unitPicker.set_title("Units")
554         unitPicker.set_selector(selectorUnit)
555         unitPicker.set_active(widget.unit)
556
557         selectorUI = hildon.TouchSelector(text=True)
558         selectorUI = hildon.TouchSelector(text=True)
559         selectorUI.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
560         selectorUI.append_text("Show current + total")
561         selectorUI.append_text("Show only current")
562         selectorUI.append_text("Show only total")
563         selectorUI.connect("changed", selectorUI_changed)
564
565         UIPicker = hildon.PickerButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
566         UIPicker.set_alignment(0.0, 0.5, 1.0, 1.0)
567         UIPicker.set_title("Widget aspect")
568         UIPicker.set_selector(selectorUI)
569         UIPicker.set_active(widget.aspect)
570
571         logButton = hildon.CheckButton(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT)
572         logButton.set_label("Log data")
573         logButton.set_active(widget.logging)
574         logButton.connect("toggled", logButton_changed)
575
576         pan_area = hildon.PannableArea()
577         vbox = gtk.VBox()
578         vbox.add(button)
579         vbox.add(modePicker)
580         vbox.add(heightPicker)
581         vbox.add(unitPicker)
582         vbox.add(UIPicker)
583         #vbox.add(logButton)
584
585         pan_area.add_with_viewport(vbox)
586         pan_area.set_size_request(-1, 300)
587
588         dialog.vbox.add(pan_area)
589         dialog.show_all()
590         response = dialog.run()
591         #hildon.hildon_banner_show_information(self, "None", "You have to Stop/Start the counter to apply the new settings")
592         dialog.destroy()
593
594     def close_requested(self, widget):
595         if self.pedometer is None:
596             return
597
598         self.pedometer.request_stop()
599
600     def update_values(self, totalCurent, lastInterval):
601         self.totalCounter += lastInterval
602         self.counter = totalCurent
603
604         tdelta = time.time() - self.time - self.startTime
605         self.time += tdelta
606         self.totalTime += tdelta
607
608         self.update_current()
609         self.update_total()
610
611     def button_clicked(self, button):
612         if self.pedometer is not None and self.pedometer.isRunning:
613             #counter is running
614             self.pedometer.request_stop()
615             self.client.set_int(COUNTER, self.totalCounter)
616             self.client.set_int(TIMER, int(self.totalTime))
617             #self.button.set_label("Start")
618             self.button.set_icon(ICONSPATH + "play.png")
619         else:
620             self.pedometer = PedoCounter(self.update_values)
621             self.pedometer.set_mode(self.mode)
622             self.pedometer.set_height(self.height)
623             self.pedometer.set_logging(self.logging)
624
625             self.time = 0
626             self.counter = 0
627
628             self.update_current()
629
630             self.pedometer.start()
631             self.startTime = time.time()
632             #self.button.set_label("Stop")
633             self.button.set_icon(ICONSPATH + "stop.png")
634
635     def do_expose_event(self, event):
636         cr = self.window.cairo_create()
637         cr.region(event.window.get_clip_region())
638         cr.clip()
639         #cr.set_source_rgba(0.4, 0.64, 0.564, 0.5)
640         style = self.rc_get_style()
641         color = style.lookup_color("DefaultBackgroundColor")
642         cr.set_source_rgba (color.red/65535.0, color.green/65335.0, color.blue/65535.0, 0.75);
643
644         radius = 5
645         width = self.allocation.width
646         height = self.allocation.height
647
648         x = self.allocation.x
649         y = self.allocation.y
650
651         cr.move_to(x+radius, y)
652         cr.line_to(x + width - radius, y)
653         cr.curve_to(x + width - radius, y, x + width, y, x + width, y + radius)
654         cr.line_to(x + width, y + height - radius)
655         cr.curve_to(x + width, y + height - radius, x + width, y + height, x + width - radius, y + height)
656         cr.line_to(x + radius, y + height)
657         cr.curve_to(x + radius, y + height, x, y + height, x, y + height - radius)
658         cr.line_to(x, y + radius)
659         cr.curve_to(x, y + radius, x, y, x + radius, y)
660
661         cr.set_operator(cairo.OPERATOR_SOURCE)
662         cr.fill_preserve()
663
664         color = style.lookup_color("ActiveTextColor")
665         cr.set_source_rgba (color.red/65535.0, color.green/65335.0, color.blue/65535.0, 0.5);
666         cr.set_line_width(1)
667         cr.stroke()
668
669         hildondesktop.HomePluginItem.do_expose_event(self, event)
670
671     def do_realize(self):
672         screen = self.get_screen()
673         self.set_colormap(screen.get_rgba_colormap())
674         self.set_app_paintable(True)
675         hildondesktop.HomePluginItem.do_realize(self)
676
677 hd_plugin_type = PedometerHomePlugin
678
679 # The code below is just for testing purposes.
680 # It allows to run the widget as a standalone process.
681 if __name__ == "__main__":
682     import gobject
683     gobject.type_register(hd_plugin_type)
684     obj = gobject.new(hd_plugin_type, plugin_id="plugin_id")
685     obj.show_all()
686     gtk.main()
687
688 ############### old pedometer.py ###
689 import math
690 import logging
691
692 logger = logging.getLogger("pedometer")
693 logger.setLevel(logging.INFO)
694
695 ch = logging.StreamHandler()
696 formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
697 ch.setFormatter(formatter)
698 logger.addHandler(ch)
699