|
@@ -1,7 +1,21 @@
|
|
|
+import time
|
|
|
+from threading import Thread
|
|
|
+
|
|
|
import PySimpleGUI
|
|
|
-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
|
|
|
+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
|
|
|
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
|
|
|
+from time_recoder.time_recorder_database.create_db import ENGINE
|
|
|
+
|
|
|
+Session = sessionmaker(bind=ENGINE)
|
|
|
+taskHandler = TaskHandler()
|
|
|
+timer = Timer()
|
|
|
|
|
|
|
|
|
def create_layout():
|
|
@@ -10,7 +24,16 @@ def create_layout():
|
|
|
[PySimpleGUI.Text(STOP_BUTTON_INTRODUCTION_TEXT)],
|
|
|
[PySimpleGUI.Button(START_BUTTON_TEXT),
|
|
|
PySimpleGUI.Button(PAUSE_BUTTON_TEXT),
|
|
|
- PySimpleGUI.Button(STOP_BUTTON_TEXT)]
|
|
|
+ PySimpleGUI.Button(STOP_BUTTON_TEXT)],
|
|
|
+ [PySimpleGUI.Text('', size=(8, 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),
|
|
|
+ default_value='root',
|
|
|
+ key=TASK_TREE_COMBO_NAME)],
|
|
|
+ [PySimpleGUI.Text(ADD_TASK_INTRODUCTION_TEXT),
|
|
|
+ PySimpleGUI.InputText(size=(15, 1), key=NEW_TASK_TEXT_KEY),
|
|
|
+ PySimpleGUI.Button(ADD_TASK_BUTTON_TEXT)]
|
|
|
]
|
|
|
|
|
|
|
|
@@ -34,39 +57,50 @@ def pause_button_is_pushed(event):
|
|
|
return event == PAUSE_BUTTON_TEXT
|
|
|
|
|
|
|
|
|
+def add_sub_task_button_is_pushed(event):
|
|
|
+ return event == ADD_TASK_BUTTON_TEXT
|
|
|
+
|
|
|
+
|
|
|
def event_loop(window):
|
|
|
while True:
|
|
|
- event, values = window.read()
|
|
|
+ event, values = window.read(timeout=10)
|
|
|
+ window[TIMER_KEY].update(timer.get_value_string())
|
|
|
if window_is_closed(event):
|
|
|
break
|
|
|
if start_button_is_pushed(event):
|
|
|
print('Start Time')
|
|
|
- if 'start_time' in locals():
|
|
|
- if 'pause_time' in locals():
|
|
|
- print('Time updated, Pause Timer Reseted')
|
|
|
- start_time = start_time + (pause_time - save_recorded_time_in_table.get_current_time_as_timestamp())
|
|
|
- pause_time = 'reseted'
|
|
|
- else:
|
|
|
- pass
|
|
|
- else:
|
|
|
- start_time = save_recorded_time_in_table.get_current_time_as_timestamp()
|
|
|
+ timer.start()
|
|
|
+
|
|
|
if pause_button_is_pushed(event):
|
|
|
print('Pause Timer Activated')
|
|
|
- if 'pause_time' in locals():
|
|
|
- if pause_time == 'reseted':
|
|
|
- print('New Pause Timer Activated')
|
|
|
- pause_time = save_recorded_time_in_table.get_current_time_as_timestamp()
|
|
|
- else:
|
|
|
- pass
|
|
|
- else:
|
|
|
- pause_time = save_recorded_time_in_table.get_current_time_as_timestamp()
|
|
|
+ timer.pause()
|
|
|
+
|
|
|
if stop_button_is_pushed(event):
|
|
|
- print('Timer Stoped Recording, Close the Window')
|
|
|
- if 'start_time' in locals():
|
|
|
- worked_time_in_minutes = (save_recorded_time_in_table.get_current_time_as_timestamp() - start_time) / 60
|
|
|
- save_recorded_time_in_table.save_recorded_time_in_table(worked_time_in_minutes)
|
|
|
- else:
|
|
|
- pass
|
|
|
+ worked_time_in_minutes = timer.get_passed_time() / 60
|
|
|
+ selected_task_name = window.Element(TASK_TREE_COMBO_NAME).get()
|
|
|
+ current_task = taskHandler.get_task_by_id(taskHandler.get_task_id(selected_task_name))
|
|
|
+ current_branch = taskHandler.get_task_branch_as_string(current_task)
|
|
|
+ try:
|
|
|
+ save_recorded_time_in_table.save_recorded_time_in_table(worked_time_in_minutes, current_branch)
|
|
|
+ timer.stop()
|
|
|
+ print('Timer stopped recording for task: ' + selected_task_name.strip())
|
|
|
+ except PermissionError:
|
|
|
+ print("Error: couldn't write into table file. Please close any program that uses the table" +
|
|
|
+ " and press 'Stop Timer' again")
|
|
|
+
|
|
|
+ if add_sub_task_button_is_pushed(event):
|
|
|
+ sub_task_name = window.Element(NEW_TASK_TEXT_KEY).get()
|
|
|
+ sub_task_name_already_in_use = sub_task_name in taskHandler.get_task_tree_name_strings(
|
|
|
+ taskHandler.root_task)
|
|
|
+ if sub_task_name_already_in_use:
|
|
|
+ print('Error: Task name ' + sub_task_name + ' already used, please enter another one')
|
|
|
+ elif sub_task_name:
|
|
|
+ parent_task_name = window.Element(TASK_TREE_COMBO_NAME).get()
|
|
|
+ parent_task_id = taskHandler.get_task_id(parent_task_name)
|
|
|
+ print('Adding new Sub-Task: ' + sub_task_name + ' to ' + parent_task_name.strip())
|
|
|
+ taskHandler.add_task(parent_task_id, sub_task_name)
|
|
|
+ window.Element(TASK_TREE_COMBO_NAME).update(
|
|
|
+ values=taskHandler.get_task_tree_name_strings(taskHandler.root_task))
|
|
|
|
|
|
|
|
|
def gui_main():
|
|
@@ -78,3 +112,4 @@ def gui_main():
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
gui_main()
|
|
|
+ taskHandler.close_session()
|