# HG changeset patch # User Thomas Arendsen Hein # Date 1250604441 -7200 # Node ID 4242b263fad4cd742f77e3daceb68b4ae7fdb856 # Parent 2712fc2b827617a927d7f5271aa8618ee90be846 allow adding/subtracting times while a project is running diff -r 2712fc2b8276 -r 4242b263fad4 getan --- a/getan Tue Aug 18 15:45:12 2009 +0200 +++ b/getan Tue Aug 18 16:07:21 2009 +0200 @@ -634,7 +634,60 @@ stdscr.erase() ofs = self.render() stdscr.refresh() - + signal.signal(signal.SIGALRM, alarm_handler) + signal.alarm(1) + elif c == ord('+'): + signal.signal(signal.SIGALRM, signal.SIG_IGN) + stdscr.erase() + ofs = self.render() + old_cur = cursor_visible(1) + curses.echo() + stdscr.addstr(ofs + 1, 3, "Enter time to add: ") + timespec = stdscr.getstr() + try: + seconds = human_seconds(timespec) + if seconds > 0: + self.current_project.start_time -= timedelta(seconds=seconds) + except ValueError: + pass + curses.noecho() + cursor_visible(old_cur) + stdscr.erase() + ofs = self.render() + stdscr.refresh() + signal.signal(signal.SIGALRM, alarm_handler) + signal.alarm(1) + elif c == ord('-'): + signal.signal(signal.SIGALRM, signal.SIG_IGN) + stdscr.erase() + ofs = self.render() + old_cur = cursor_visible(1) + curses.echo() + stdscr.addstr(ofs + 1, 3, "Enter time to subtract: ") + timespec = stdscr.getstr() + try: + seconds = human_seconds(timespec) + if seconds > 0: + now = datetime.now() + self.current_project.start_time += timedelta(seconds=seconds) + if self.current_project.start_time > now: + seconds = self.current_project.start_time - now + self.current_project.start_time = now + cur = None + try: + cur = self.con.cursor() + self.current_project.substractTime(cur, seconds) + finally: + tolerantClose(cur) + except ValueError: + pass + curses.noecho() + cursor_visible(old_cur) + stdscr.erase() + ofs = self.render() + stdscr.refresh() + signal.signal(signal.SIGALRM, alarm_handler) + signal.alarm(1) elif curses.ascii.isascii(c): project_node = self.selection.findProject(chr(c)) if project_node is None: