changeset 89:3bea335c0f30

Save the current project when switching to Running state
author Björn Ricks <bjoern.ricks@intevation.de>
date Mon, 30 May 2011 15:45:25 +0200
parents 6dc52940dde0
children 04dbf4c9f297
files ChangeLog getan/states.py
diffstat 2 files changed, 20 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon May 30 15:42:15 2011 +0200
+++ b/ChangeLog	Mon May 30 15:45:25 2011 +0200
@@ -1,3 +1,11 @@
+2011-05-30	Björn Ricks <bjoern.ricks@intevation.de>
+
+	* getan/states.py: Save the current project when switching to Running state.
+	Now it's possible to move up and down through the project list or even to
+	the entry list while a project is running. This behaviour also changed the
+	current project. Therefore it's necessary to keep the project while changing
+	to other states.
+
 2011-05-30	Björn Ricks <bjoern.ricks@intevation.de>
 
 	* getan/states.py: Move 'up' and 'down' keypress handling to
--- a/getan/states.py	Mon May 30 15:42:15 2011 +0200
+++ b/getan/states.py	Mon May 30 15:45:25 2011 +0200
@@ -88,13 +88,14 @@
                     self.controller.start_project(self.view.item_in_focus())
                     self.controller.update_entries(
                         self.view.item_in_focus())
-                    return RunningProjectsState(self.controller, self.view)
+                    return RunningProjectsState(self.controller, self.view, proj)
         return self
 
 
     def select(self):
-        self.controller.start_project(self.view.item_in_focus())
-        return RunningProjectsState(self.controller, self.view)
+        proj = self.view.item_in_focus()
+        self.controller.start_project(proj)
+        return RunningProjectsState(self.controller, self.view, proj)
 
 class ExitState(ProjectState):
     messages = {
@@ -135,13 +136,14 @@
     sec         = 0
     break_start = None
 
-    def __init__(self, controller, view):
+    def __init__(self, controller, view, project):
         super(RunningProjectsState, self).__init__(controller, view)
+        self.project = project
         signal.signal(signal.SIGALRM, self.handle_signal)
         signal.alarm(1)
 
     def handle_signal(self, signum, frame):
-        proj = self.view.item_in_focus()
+        proj = self.project
         if not proj: return
         if not self.break_start:
             self.controller.view.set_footer_text(self.msg('running') %
@@ -184,7 +186,7 @@
             return self
         if ' ' in key and self.break_start:
             self.view._total_time()
-            proj = self.view.item_in_focus()
+            proj = self.project
             if proj:
                 proj.start += datetime.now() - self.break_start
                 self.break_start = None
@@ -196,7 +198,7 @@
         signal.alarm(0)
         self.view.select()
         if self.break_start:
-            proj = self.view.item_in_focus()
+            proj = self.project
             if proj: proj.start += datetime.now() - self.break_start
         self.controller.view.set_footer_text(self.msg('description'),'question',1)
         self.controller.view.get_frame().set_focus('footer')
@@ -254,6 +256,7 @@
     def __init__(self, controller, view, running_state):
         super(BaseTimeState, self).__init__(controller, view, running_state,
                                            view.frame.get_footer())
+        self.project = running_state.project
 
     def exit(self):
         self.view._total_time()
@@ -271,7 +274,7 @@
 class AddTimeState(BaseTimeState):
     def enter(self):
         minutes         = safe_int(self.view.frame.get_footer().get_edit_text())
-        project         = self.view.item_in_focus()
+        project         = self.project
         project.start  -= timedelta(minutes=minutes)
         self.state.sec += minutes * 60
         logger.info("AddTimeState: add %d minutes to project '%s'"
@@ -287,7 +290,7 @@
         if sec > self.state.sec:
             self.view._total_time()
             return self.state
-        project         = self.view.item_in_focus()
+        project         = self.project
         project.start  += timedelta(minutes=minutes)
         self.state.sec -= sec
         logger.info("SubtractTimeState: subtract %d minutes from project '%s'"
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)