--- /dev/null
+import Views, Actions
+import subprocess, curses
+
+class TimeMachine(Views.View):
+
+ def __init__(self, context, name, x, y, dx, dy, ports, dir, buffer):
+ Views.View.__init__(self, context, name, x, y, dx, dy)
+ nul = file("/dev/null","w")
+ self._tm = subprocess.Popen(["timemachine", "-i", "-t", str(buffer)] + list(ports), cwd=dir,
+ stdin=subprocess.PIPE, stdout=nul, stderr=nul)
+ self._recording = False
+
+ def start(self):
+ if not self._recording:
+ self._tm.stdin.write("start\n")
+ self._recording = True
+ self._redraw()
+
+ def stop(self):
+ if self._recording:
+ self._tm.stdin.write("stop\n")
+ self._recording = False
+ self._redraw()
+
+ def toggle(self):
+ if self._recording:
+ self.stop()
+ else:
+ self.start()
+
+ def _redraw(self, refresh=True):
+ self.win().addstr(1,2,"Status: ")
+ if self._recording:
+ self.win().addstr(1,10, "RECORDING", curses.A_BOLD)
+ else:
+ self.win().addstr(1,10, "Idle ")
+ if refresh:
+ self.win().refresh()
+
+ def updateView(self, bindings):
+ pass
+
+ def init(self):
+ Views.View.init(self)
+ self._redraw()
+
+class ToggleRecord(Actions.Action):
+
+ def __init__(self, name, tm):
+ Actions.Action.__init__(self, name)
+ self._tm = tm
+
+ def __call__(self, binding):
+ self._tm.toggle()
+
+
+def register(viewmanager, context, name, x, y, dx, dy, ports, dir, buffer):
+ tm = TimeMachine(context, name, x, y, dx, dy, ports, dir, buffer)
+ viewmanager.registerView(tm)
+ return tm
+