# HG changeset patch # User Thomas Arendsen Hein # Date 1250607351 -7200 # Node ID 28489e672e610c73446c1b734d6a3f8d9e9fac9f # Parent a9d58053bef718aa67f55d0875360082737d454a Allow + and - (RPN) to change time for the current project diff -r a9d58053bef7 -r 28489e672e61 getan --- a/getan Tue Aug 18 16:09:17 2009 +0200 +++ b/getan Tue Aug 18 16:55:51 2009 +0200 @@ -354,6 +354,7 @@ self.state = PAUSED self.current_project = None self.selection = self.tree + self.stack = [] self.loadProjects() def initDB(self, database): @@ -376,6 +377,11 @@ def shutdown(self): self.con.close() + def fetchStack(self): + cut = ''.join([chr(i) for i in self.stack]) + self.stack = [] + return cut + def findProject(self, key): key_lower = key.lower() lower = None @@ -640,20 +646,25 @@ 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() + if self.stack: + timespec = self.fetchStack() + else: + old_cur = cursor_visible(1) + curses.echo() + stdscr.addstr(ofs + 1, 3, "Enter time to add: ") + timespec = stdscr.getstr() + curses.noecho() + cursor_visible(old_cur) + stdscr.erase() + ofs = self.render() try: seconds = human_seconds(timespec) if seconds > 0: - self.current_project.start_time -= timedelta(seconds=seconds) + seconds = timedelta(seconds=seconds) + self.current_project.start_time -= seconds + stdscr.addstr(ofs + 1, 3, "added %s" % human_time(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) @@ -661,15 +672,24 @@ 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() + if self.stack: + timespec = self.fetchStack() + else: + old_cur = cursor_visible(1) + curses.echo() + stdscr.addstr(ofs + 1, 3, "Enter time to subtract: ") + timespec = stdscr.getstr() + curses.noecho() + cursor_visible(old_cur) + stdscr.erase() + ofs = self.render() try: seconds = human_seconds(timespec) if seconds > 0: now = datetime.now() - self.current_project.start_time += timedelta(seconds=seconds) + seconds = timedelta(seconds=seconds) + self.current_project.start_time += seconds + stdscr.addstr(ofs + 1, 3, "subtracted %s" % human_time(seconds)) if self.current_project.start_time > now: seconds = self.current_project.start_time - now self.current_project.start_time = now @@ -681,13 +701,11 @@ 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 self.stack or curses.ascii.isdigit(c): + self.stack.append(c) elif curses.ascii.isascii(c): project_node = self.selection.findProject(chr(c)) if project_node is None: