Register with network also on the PIN code path
[gregoa/zavai.git] / plugins / 60_audio_notes.py
1 import os.path
2 import time
3 from gettext import gettext as _
4 import gtk
5 import zavai
6
7 class AudioNotes(gtk.ToggleAction):
8     states = [_("Start recording audio"), _("Stop recording audio")]
9
10     def __init__(self, registry, **kw):
11         self.state = 0
12         super(AudioNotes, self).__init__("menu.main.organiser.audionote", self.states[self.state], None, None)
13
14         self.registry = registry
15         self.recorder = zavai.Recorder(registry)
16         self.set_active(False)
17
18         self.connect("toggled", self.on_toggle)
19
20     def shutdown(self):
21         self.recorder.stop()
22         super(AudioNotes, self).shutdown()
23
24     def on_toggle(self, *args):
25         self.state = (self.state + 1) % len(self.states)
26         self.set_property("label", self.states[self.state])
27         if self.get_active():
28             self.start()
29         else:
30             self.stop()
31
32     def start(self):
33         name = time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
34         name = os.path.join(self.registry.resource("conf").homedir, name + ".wav")
35         zavai.info("Audio note started on", name)
36         self.recorder.start(name)
37
38     def stop(self):
39         self.recorder.stop()
40
41 def init(conf = None, registry = None, **kw):
42     registry.register(AudioNotes(registry))