changeset 405:150180e972d3

Adds ability to adjust the length of (saved) entries.
author Bernhard Reiter <bernhard@intevation.de>
date Fri, 10 Feb 2017 15:01:07 +0100
parents c272982799b5
children 84f9b1eeb8b6
files INTRODUCTION getan/config.py getan/states.py
diffstat 3 files changed, 83 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/INTRODUCTION	Fri Feb 03 15:01:06 2017 +0100
+++ b/INTRODUCTION	Fri Feb 10 15:01:07 2017 +0100
@@ -13,8 +13,9 @@
 | F1                |  Switch time display mode in ProjectList.
 | F2                |  Switch sorting of entries in ProjectList.
 | d                 |  Delete marked entries (in EntryList).
-| e                 |  Edit the text of an entry.
-| a                 |  Adjust the starting datetime of an entry.
+| e                 |  Edit the text of a (marked) entry.
+| a                 |  Adjust the starting datetime of a (marked) entry.
+| l                 |  Adjust the length of a (marked) entry.
 | m                 |  Start the 'wizard' to move selected entries to another
                        project.
 | esc               |  Exit the application. This is only possible if no project
--- a/getan/config.py	Fri Feb 03 15:01:06 2017 +0100
+++ b/getan/config.py	Fri Feb 10 15:01:07 2017 +0100
@@ -90,6 +90,7 @@
     KEY_ENTRY_MOVE = "entry_move"
     KEY_ENTRY_EDIT = "entry_edit"
     KEY_ENTRY_ADJUST = "entry_adjust"
+    KEY_ENTRY_LENGTH = "entry_length"
     KEY_ADD_TIME = "add_time"
     KEY_SUBTRACT_TIME = "subtract_time"
     KEY_PROJECT_PAUSE = "project_pause"
@@ -109,6 +110,7 @@
         KEY_ENTRY_MOVE: "m",
         KEY_ENTRY_EDIT: "e",
         KEY_ENTRY_ADJUST: "a",
+        KEY_ENTRY_LENGTH: "l",
         KEY_ADD_TIME: "+",
         KEY_SUBTRACT_TIME: "-",
         KEY_PROJECT_PAUSE: " ",
@@ -163,6 +165,9 @@
     def get_entry_adjust(self):
         return self.get_binding(self.KEY_ENTRY_ADJUST)
 
+    def get_entry_length(self):
+        return self.get_binding(self.KEY_ENTRY_LENGTH)
+
     def get_entry_up(self):
         return self.get_binding(self.KEY_ENTRY_UP)
 
--- a/getan/states.py	Fri Feb 03 15:01:06 2017 +0100
+++ b/getan/states.py	Fri Feb 10 15:01:07 2017 +0100
@@ -547,8 +547,16 @@
             entry = self.view.item_in_focus()
             if entry:
                 self.set_next_state(AdjustEntryState(self.projectlist_state,
-                                                   self.controller, self.view,
-                                                   entry))
+                                                     self.controller, self.view,
+                                                     entry))
+            return True
+
+        if keys.get_entry_length() in key:
+            entry = self.view.item_in_focus()
+            if entry:
+                self.set_next_state(LengthEntryState(self.projectlist_state,
+                                                     self.controller, self.view,
+                                                     entry))
             return True
 
         return False
@@ -829,6 +837,71 @@
         self.controller.view.set_focus("entries")
         self.view.frame.set_focus("footer")
 
+class LengthEntryState(HandleUserInputState):
+
+    messages = {
+        'adjust_length_entry': _('Adjust length of entry: '),
+    }
+
+    def __init__(self, state, controller, view, entry):
+        view.set_footer_text(self.msg('adjust_length_entry'),
+                             'question', True)
+        super(LengthEntryState, self).__init__(controller, view,
+                                             None, view.footer)
+
+        # format current duration as string that is also accepted by enter()
+        total_minutes = int(entry.get_duration().total_seconds()/60)
+        hours = int(total_minutes // 60)
+
+        if hours > 0:
+            self.footer.set_edit_text(
+                "{:d}:{:d}".format(hours, int(total_minutes % 60)))
+        else:
+            self.footer.set_edit_text(int(minutes))
+
+        self.footer.set_edit_pos(len(self.footer.edit_text))
+        self.entry = entry
+        self.state = state
+        logger.debug("LengthEntryState: Entry %s" % entry)
+
+    def enter(self):
+        """Changed the length of an entry.
+
+        Works for total minutes or HH:MM.
+        """
+        entry_duration = self.footer.get_edit_text()
+
+        # avoid unexpected behavior if minus signs are given in the new length
+        if '-' in entry_duration:
+            return self
+
+        if ':' in entry_duration:
+            hours, minutes = entry_duration.split(':')
+        else:
+            hours = 0
+            minutes = entry_duration
+
+        try:
+            duration = timedelta(minutes=int(minutes), hours=int(hours))
+        except:
+            return self
+
+        entry = self.entry
+        entry.end = entry.start + duration
+
+        self.controller.update_entry(entry)
+        self.view.node_in_focus().update()
+        return self.exit()
+
+    def exit(self):
+        self.view.set_footer_text("", 'entry_footer', False)
+        self.set_next_state(DefaultEntryListState(self.state, self.controller,
+                                                  self.view))
+        return True
+
+    def set_focus(self):
+        self.controller.view.set_focus("entries")
+        self.view.frame.set_focus("footer")
 
 
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)