init commit
[profile-appoint] / profile-appointments.py
1 #!/usr/bin/env python
2
3 import hildon, gtk
4 import hildondesktop
5 import commands
6
7 class ExampleStatusPlugin(hildondesktop.StatusMenuItem):
8         def __init__(self):
9                 hildondesktop.StatusMenuItem.__init__(self)
10
11                 self.backend_started =  self.status_backend()
12
13                 self.button_title_text = "profile-appointments"
14                 self.button = hildon.Button(gtk.HILDON_SIZE_AUTO_WIDTH | gtk.HILDON_SIZE_FINGER_HEIGHT, hildon.BUTTON_ARRANGEMENT_VERTICAL)
15                 self.button.set_style(hildon.BUTTON_STYLE_PICKER)
16                 self.button.set_alignment(0.2,0.5,1,1)
17                 image = gtk.image_new_from_icon_name("profile-appointments", gtk.ICON_SIZE_BUTTON)
18                 self.button.set_image(image)
19                 self.button.set_image_position(gtk.POS_LEFT)
20                 self.button.connect("clicked", self.button_clicked_event)
21
22                 icon_theme = gtk.icon_theme_get_default()
23                 self.pixbuf = icon_theme.load_icon("profile-appointments", 22, gtk.ICON_LOOKUP_NO_SVG)
24
25                 self.add(self.button)
26                 self.show_all()
27                 self.update_button()
28
29         def status_backend(self):
30                 """is backend running?"""
31                 return commands.getoutput('pgrep switch_backend')
32
33         def button_clicked_event(self,*args):
34                 if self.backend_started:
35                         self.stop_backend()
36                 else:
37                         self.start_backend()
38                 self.update_button()
39
40         def update_button(self):
41                 """Update the start/stop button to reflect current state"""
42                 if self.backend_started:
43                         self.button.set_text(self.button_title_text,'Stop')
44                         self.set_status_area_icon(self.pixbuf)
45                 else:
46                         self.button.set_text(self.button_title_text,'Start')
47                         self.set_status_area_icon(None)
48         
49         def start_backend(self):
50                 """calls backend start"""
51                 (exitstatus, outtext) = commands.getstatusoutput("""/etc/init.d/switch_backend start""")
52                 if exitstatus <> 0:
53                         print "DEBUG: backend start exit code " + str(status) + ", output: \n"
54                         note = hildon.hildon_note_new_information(self.mainwindow, 'profile-appointments failed to start')
55                         response = gtk.Dialog.run(note)
56                         note.destroy()
57                         return
58                 self.backend_started = True
59
60         def stop_backend(self):
61                 """kills backend"""
62                 (exitstatus, outtext) = commands.getstatusoutput("""/etc/init.d/switch_backend stop""")
63                 if exitstatus <> 0:
64                         print "DEBUG: backend start exit code " + str(status) + ", output: \n"
65                         note = hildon.hildon_note_new_information(self.mainwindow, 'profile-appointments failed to start')
66                         response = gtk.Dialog.run(note)
67                         note.destroy()
68                         return
69                 self.backend_started = False
70
71 hd_plugin_type = ExampleStatusPlugin