Parcourir la source

Timer Tool now shows total time, too

Nico Ruhnke il y a 2 ans
Parent
commit
521c39e31b

+ 1 - 0
time_recoder/time_recoder_gui/time_recorder_gui_config.py

@@ -10,4 +10,5 @@ ADD_TASK_BUTTON_TEXT = 'hinzufügen'
 NEW_TASK_TEXT_KEY = 'sub_task_name'
 TASK_TREE_COMBO_NAME = 'task_tree'
 TIMER_KEY = 'timer'
+TOTAL_TIMER_KEY = 'total_timer'
 WINDOW_SIZE = (400, 250)

+ 9 - 4
time_recoder/time_recoder_gui/time_recorder_gui_main.py

@@ -7,7 +7,8 @@ from sqlalchemy.orm import sessionmaker
 from time_recoder.time_recoder_gui.time_recorder_gui_config import PAUSE_BUTTON_TEXT, START_BUTTON_TEXT, \
     STOP_BUTTON_TEXT, \
     STOP_BUTTON_INTRODUCTION_TEXT, PAUSE_BUTTON_INTRODUCTION_TEXT, WINDOW_SIZE, SELECT_TASK_INTRODUCTION_TEXT, \
-    ADD_TASK_INTRODUCTION_TEXT, ADD_TASK_BUTTON_TEXT, NEW_TASK_TEXT_KEY, TASK_TREE_COMBO_NAME, TIMER_KEY
+    ADD_TASK_INTRODUCTION_TEXT, ADD_TASK_BUTTON_TEXT, NEW_TASK_TEXT_KEY, TASK_TREE_COMBO_NAME, TIMER_KEY, \
+    TOTAL_TIMER_KEY
 from time_recoder import save_recorded_time_in_table
 from time_recoder.time_recoder_gui.time_recorder_task_handler import TaskHandler
 from time_recoder.time_recoder_gui.time_recorder_timer import Timer
@@ -25,7 +26,10 @@ def create_layout():
         [PySimpleGUI.Button(START_BUTTON_TEXT),
          PySimpleGUI.Button(PAUSE_BUTTON_TEXT),
          PySimpleGUI.Button(STOP_BUTTON_TEXT)],
-        [PySimpleGUI.Text('', size=(8, 1), font=('Helvetica', 20), justification='center', key=TIMER_KEY)],
+        [PySimpleGUI.Text('Total Time', size=(10, 1), font=('Helvetica', 20), justification='center'),
+         PySimpleGUI.Text('Task Time', size=(10, 1), font=('Helvetica', 20), justification='center')],
+        [PySimpleGUI.Text('', size=(10, 1), font=('Helvetica', 20), justification='center', key=TOTAL_TIMER_KEY),
+         PySimpleGUI.Text('', size=(10, 1), font=('Helvetica', 20), justification='center', key=TIMER_KEY)],
         [PySimpleGUI.Text(SELECT_TASK_INTRODUCTION_TEXT),
          PySimpleGUI.Combo(taskHandler.get_task_tree_name_strings(taskHandler.root_task),
                            size=(30, 1),
@@ -64,7 +68,8 @@ def add_sub_task_button_is_pushed(event):
 def event_loop(window):
     while True:
         event, values = window.read(timeout=10)
-        window[TIMER_KEY].update(timer.get_value_string())
+        window[TIMER_KEY].update(timer.get_task_value_string())
+        window[TOTAL_TIMER_KEY].update(timer.get_total_value_string())
         if window_is_closed(event):
             break
         if start_button_is_pushed(event):
@@ -76,7 +81,7 @@ def event_loop(window):
             timer.pause()
 
         if stop_button_is_pushed(event):
-            worked_time_in_minutes = timer.get_passed_time() / 60
+            worked_time_in_minutes = timer.get_passed_task_time() / 60
             selected_task_name = window.Element(TASK_TREE_COMBO_NAME).get()
             if selected_task_name:
                 current_task = taskHandler.get_task_by_id(taskHandler.get_task_id(selected_task_name))

+ 49 - 12
time_recoder/time_recoder_gui/time_recorder_timer.py

@@ -8,43 +8,80 @@ def get_current_time():
 class Timer:
 
     def __init__(self):
-        self.start_time = -1
+        self.total_start_time = -1
+        self.task_start_time = -1
         self.pause_time = 0
+        self.stop_time = 0
         self.is_paused = False
+        self.is_stopped = True
 
-    def get_passed_time(self):
-        if self.was_started():
+    def get_passed_task_time(self):
+        if self.task_was_started():
             current_time = get_current_time()
             if self.is_paused:
-                return current_time - (self.start_time + (current_time - self.pause_time))
+                return current_time - (self.task_start_time + (current_time - self.pause_time))
             else:
-                return current_time - self.start_time
+                return current_time - self.task_start_time
         else:
             return 0
 
-    def get_value_string(self):
-        current_time = self.get_passed_time()
+    def get_passed_total_time(self):
+        if self.timer_was_started():
+            current_time = get_current_time()
+            if self.is_paused:
+                return current_time - (self.total_start_time + (current_time - self.pause_time))
+            elif self.is_stopped:
+                return current_time - (self.total_start_time + (current_time - self.stop_time))
+            else:
+                return current_time - self.total_start_time
+        else:
+            return 0
+
+    def get_task_value_string(self):
+        current_time = self.get_passed_task_time()
+        return '{:02d}:{:02d}:{:02d}'.format((current_time // 60) // 60,
+                                             (current_time // 60) % 60,
+                                             current_time % 60)
+
+    def get_total_value_string(self):
+        current_time = self.get_passed_total_time()
         return '{:02d}:{:02d}:{:02d}'.format((current_time // 60) // 60,
                                              (current_time // 60) % 60,
                                              current_time % 60)
 
     def start(self):
+        current_time = get_current_time()
         if self.is_paused:
-            self.start_time = self.start_time + (get_current_time() - self.pause_time)
+            self.task_start_time = self.task_start_time + (current_time - self.pause_time)
+            self.total_start_time = self.total_start_time + (current_time - self.pause_time)
             self.pause_time = 0
             self.is_paused = False
         else:
-            self.start_time = get_current_time()
+            if not self.task_was_started():
+                self.task_start_time = current_time
+            if not self.timer_was_started():
+                self.total_start_time = current_time
+            elif self.is_stopped:
+                self.total_start_time = self.total_start_time + (current_time - self.stop_time)
+                self.stop_time = 0
+        self.is_stopped = False
 
     def stop(self):
-        self.start_time = -1
+        self.task_start_time = -1
+        if self.is_paused:
+            self.total_start_time = self.total_start_time + (get_current_time() - self.pause_time)
         self.pause_time = 0
         self.is_paused = False
+        self.stop_time = get_current_time()
+        self.is_stopped = True
 
     def pause(self):
         if not self.is_paused:
             self.is_paused = True
             self.pause_time = get_current_time()
 
-    def was_started(self):
-        return self.start_time > 0
+    def task_was_started(self):
+        return self.task_start_time > 0
+
+    def timer_was_started(self):
+        return self.total_start_time > 0