From 6834469b62f1a0001dac6844350874a38446e07c Mon Sep 17 00:00:00 2001
From: anima
Date: Fri, 4 Jun 2021 18:07:25 +0200
Subject: [PATCH] Menu navigation optimized (Issue#1)
---
timeTrack.py | 64 +++++++++++++++++++++++++++-------------------------
1 file changed, 33 insertions(+), 31 deletions(-)
diff --git a/timeTrack.py b/timeTrack.py
index 3755ea0..49d902d 100644
--- a/timeTrack.py
+++ b/timeTrack.py
@@ -3,7 +3,7 @@
#
# timeTrack.py
# by 4nima
-# v.2.0.0
+# v.2.0.1
#
#########################
# simple time tracking with database
@@ -348,24 +348,24 @@ class TimeTrack:
logging.debug('Event younger than 1 day')
print('Vergangene Zeit: >{} Stunden'.format(int(elapsed.seconds/3600)))
- userinput = ''
- while True:
- if userinput == "F" or userinput == "f" or userinput == "1" \
- or userinput == "L" or userinput == "l" or userinput == "2" \
- or userinput == "A" or userinput == "a" or userinput == "3":
- break
+ userinput = 0
+ while not 0 < int(userinput) < 4:
print('Soll das Event fortgesetzt oder gelöscht werden?')
- print('[1/F/f] für fortsetzen')
- print('[2/L/l] für löschen')
- print('[3/A/a] für abbrechen')
+ print('[1] für fortsetzen')
+ print('[2] für löschen')
+ print('[3] für abbrechen')
userinput = input('Aktion: ')
logging.debug('User input: {}'.format(userinput))
+ try:
+ int(userinput)
+ except ValueError:
+ userinput = 0
self.clear_screen()
- if userinput == "F" or userinput == "f" or userinput == "1":
+ if userinput == "1":
logging.debug('Event should be continued')
self.time_stop()
- elif userinput == "L" or userinput == "l" or userinput == "2":
+ elif userinput == "2":
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
self.delete_event(data[0])
self.time_start()
@@ -383,21 +383,21 @@ class TimeTrack:
logging.debug('Event stop progess is started')
if data:
self.clear_screen()
- userinput = ''
- while True:
- if userinput == "B" or userinput == "b" or userinput == "1" \
- or userinput == "L" or userinput == "l" or userinput == "2" \
- or userinput == "A" or userinput == "a" or userinput == "3":
- break
+ userinput = 0
+ while not 0 < int(userinput) < 4:
print('Event von {} Uhr beenden?'.format(data[1].strftime("%H:%M")))
- print('[1/B/b] für beenden')
- print('[2/L/l] für löschen')
- print('[3/A/a] für abbrechen')
+ print('[1] für beenden')
+ print('[2] für löschen')
+ print('[3] für abbrechen')
userinput = input('Aktion: ')
logging.debug('User input: {}'.format(userinput))
+ try:
+ int(userinput)
+ except ValueError:
+ userinput = 0
self.clear_screen()
- if userinput == "B" or userinput == "b" or userinput == "1":
+ if userinput == "1":
logging.debug('Event is ended')
print('Eingabe beenden mittels doppelter Leerzeile.')
print('Durchgeführte Tätigkeiten:')
@@ -438,18 +438,20 @@ class TimeTrack:
self.delete_event(data[0])
self.print_time_entry(STARTTIME=data[1], ENDTIME=endtime, ACTIVITY=action)
print('Zeiteintrag wurde gespeichert.')
- while True:
- if userinput == "J" or userinput == "j" or userinput == "1" \
- or userinput == "N" or userinput == "n" or userinput == "2":
- break
- print('Nächsten Zeiteintrag begrinnen ?')
- print('[1/J/j] Ja')
- print('[2/N/n] Nein')
+ userinput = 0
+ while not 0 < int(userinput) < 3:
+ print('Nächsten Zeiteintrag beginnen ?')
+ print('[1] Ja')
+ print('[2] Nein')
userinput = input('Aktion: ')
logging.debug('User input: {}'.format(userinput))
+ try:
+ int(userinput)
+ except ValueError:
+ userinput = 0
self.clear_screen()
- if userinput == "J" or userinput == "j" or userinput == "1":
+ if userinput == "1":
self.time_start()
else:
logging.debug('Terminated by the user')
@@ -458,7 +460,7 @@ class TimeTrack:
connect.close()
- elif userinput == "L" or userinput == "l" or userinput == "2":
+ elif userinput == "2":
logging.info('Event should be deleted (eventid: {})'.format(data[0]))
self.delete_event(data[0])
else: