changeset 20:28489e672e61

Allow <timespec>+ and <timespec>- (RPN) to change time for the current project
author Thomas Arendsen Hein <thomas@intevation.de>
date Tue, 18 Aug 2009 16:55:51 +0200
parents a9d58053bef7
children a06e068e3de8
files getan
diffstat 1 files changed, 36 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- 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:
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)