#! /usr/bin/env python """ This program will allow annotating without taking your fingers off of the keyboard. Copyright (C) 2006 Scott Shawcroft This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. This program will allow annotating without taking your fingers off of the keyboard. It will automatically store start and stop times along with the text. """ def format_time(time): hour = int(time)/1000/3600 if hour<10: hour = "0" + str(hour) else: hour = str(hour) minute = int(time)/1000/60%60 if minute < 10: minute = "0" + str(minute) else: minute = str(minute) seconds = int(time)/1000%60 if seconds < 10: seconds = "0" + str(seconds) else: seconds = str(seconds) mseconds = int(time)%1000 if mseconds<10: mseconds = "00" + str(mseconds) elif mseconds<100: mseconds = "0" + str(mseconds) else: mseconds = str(mseconds) return hour + ":" + minute + ":" + seconds + "." + mseconds def to_ms(string): # If the string is empty return empty. if string=="": return "" time = string.split(":") if len(time)==3: h,m,s = time if s.find(".")!=-1: s,ms = s.split(".") ms = s + ms + "0"*(3-len(ms)) else: ms = s + "000" elif len(time)==2: m,s = time h = "0" ms = str(1000*int(s)) return int(h)*3600*1000 + int(m)*60*1000 + int(ms)