move prints to Screen class

This commit is contained in:
Arnas Udovicius 2019-01-07 08:58:44 +02:00
parent 774498ec48
commit 1e64c780f5
3 changed files with 94 additions and 131 deletions

100
config.py
View file

@ -1,42 +1,52 @@
import sys
from pyfzf.pyfzf import FzfPrompt
from model import Model
from params import Params
from bcolors import bcolors
from screen import Screen
class Config:
def __init__(self):
self.model = Model()
self.params = Params()
self.screen = Screen()
self.fzf = FzfPrompt()
self.info = ''
def manage(self):
print(bcolors.HEADER + 'Managing configs' + bcolors.ENDC)
active = 'off'
if self.params.get('active'):
active = 'on'
print(bcolors.WARNING + 'Show current tasks: [' + active + ']' + bcolors.ENDC)
self.info = 'Show current tasks: [' + active + ']\n'
done = 'off'
if self.params.get('done'):
done = 'on'
print(bcolors.WARNING + 'Show done tasks: [' + done + ']' + bcolors.ENDC)
self.info += 'Show done tasks: [' + done + ']\n'
self.manage_menu()
def manage_menu(self):
menu = input(bcolors.OKBLUE + '~config: ' + bcolors.OKGREEN + 'What you want to do? (?!vt#<q) ' + bcolors.ENDC)
about = '''
Short instruction
-----------------
? - help (this dialog)
! - toggle active tasks
v - toggle done tasks
t - manage time slots
# - backup/restore
< - back
q - exit
'''
self.screen.change_path('~config', '?!vt#<q', about, 'Managing configs', self.info)
menu = self.screen.print()
if menu == 'q':
self.bye()
self.screen.bye()
elif menu == '?':
self.manage_about()
self.screen.activate_about()
self.manage_menu()
elif menu == '!':
@ -55,43 +65,41 @@ class Config:
return
else:
print(bcolors.FAIL + 'This is not implemented...' + bcolors.ENDC)
self.screen.add_fail('This is not implemented...')
self.manage_menu()
def manage_about(self):
print(bcolors.WARNING + '''
Short instruction
-----------------
? - help (this dialog)
! - toggle active tasks
v - toggle done tasks
t - manage time slots
# - backup/restore
< - back
q - exit
''' + bcolors.ENDC)
def toggle_active(self):
active = self.params.get('active')
self.params.update('active', not active)
print(bcolors.OKBLUE + '[parameter "active" has been toggled]' + bcolors.ENDC)
self.screen.add_message('parameter "active" has been toggled')
def toggle_done(self):
done = self.params.get('done')
self.params.update('done', not done)
print(bcolors.OKBLUE + '[parameter "done" has been toggled]' + bcolors.ENDC)
self.screen.add_message('parameter "done" has been toggled')
def manage_timeslot(self):
self.manage_timeslot_menu()
def manage_timeslot_menu(self):
menu = input(bcolors.OKBLUE + '~config/time_slot: ' + bcolors.OKGREEN + 'What you want to do? (?!vt#<q) ' + bcolors.ENDC)
about = '''
Short instruction
-----------------
? - help (this dialog)
+ - add time slot
- - remove time slot
< - back
q - exit
'''
self.screen.change_path('~config/time_slot', '?+-<q', about, 'Managing time slots')
menu = self.screen.print()
if menu == 'q':
self.bye()
self.screen.bye()
elif menu == '?':
self.manage_timeslot_about()
self.screen.activate_about()
self.manage_timeslot_menu()
elif menu == '+':
self.add_time_slot()
@ -103,27 +111,15 @@ q - exit
return
else:
print(bcolors.FAIL + 'This is not implemented...' + bcolors.ENDC)
self.manage_menu()
def manage_timeslot_about(self):
print(bcolors.WARNING + '''
Short instruction
-----------------
? - help (this dialog)
+ - add time slot
- - remove time slot
< - back
q - exit
''' + bcolors.ENDC)
self.manage()
self.screen.add_fail('This is not implemented...')
self.manage_timeslot_menu()
def add_time_slot(self):
print(bcolors.HEADER + 'Adding time slot' + bcolors.ENDC)
self.screen.print_init('Adding time slot')
name = input('Name (short): ')
description = input('Description: ')
tid = self.model.create_time_slot(name, description)
print(bcolors.OKBLUE + '[time slot has been created]' + bcolors.ENDC)
self.screen.add_message('time slot has been created')
self.manage()
def search_tag(self, tid=None):
@ -141,12 +137,12 @@ q - exit
tag = self.model.get_tag_by_name(selected[0])
self.manage_tag(tag['id'])
else:
print(bcolors.FAIL + 'Tag was not selected...' + bcolors.ENDC)
self.screen.add_fail('Tag was not selected...')
def remove_tag(self, tid=None):
tagsData = self.model.get_all_tags()
if not tagsData:
print(bcolors.FAIL + 'Where is no tags...' + bcolors.ENDC)
self.screen.add_fail('Where is no tags...')
self.manage_tag_menu()
tags = []
@ -156,11 +152,7 @@ q - exit
selected = self.fzf.prompt(tags)
if selected:
self.model.remove_tag_by_name(selected[0])
print(bcolors.OKBLUE + '[tag has been deleted]' + bcolors.ENDC)
self.screen.add_message('tag has been deleted')
self.manage_tag()
else:
print(bcolors.FAIL + 'Tag was not selected...' + bcolors.ENDC)
def bye(self):
print(bcolors.FAIL + 'bye o/' + bcolors.ENDC)
sys.exit(0)
self.screen.add_fail('Tag was not selected...')

68
tag.py
View file

@ -1,48 +1,58 @@
import sys
from pyfzf.pyfzf import FzfPrompt
from model import Model
from bcolors import bcolors
from screen import Screen
class Tag:
def __init__(self):
self.model = Model()
self.fzf = FzfPrompt()
self.screen = Screen()
self.header = ''
self.info = None
def manage_tag(self, tid=None):
if tid:
tag = self.model.get_tag(tid)
print(bcolors.HEADER + 'Managing tag: ' + tag['name'] + bcolors.ENDC)
self.header = 'Managing tag: ' + tag['name']
else:
print(bcolors.HEADER + 'Managing tags' + bcolors.ENDC)
self.header = 'Managing tags'
tagsData = self.model.get_all_tags()
if not tagsData:
self.add_tag()
tagsData = self.model.get_all_tags()
tags = bcolors.WARNING
for t in tagsData:
tags += t['name'] + ' '
print(tags + bcolors.ENDC)
self.info = ' '.join([t['name'] for t in tagsData]) + '\n'
self.manage_tag_menu(tid)
def manage_tag_menu(self, tid=None):
menu = input(bcolors.OKBLUE + '~tag: ' + bcolors.OKGREEN + 'What you want to do? (?/+-&<q) ' + bcolors.ENDC)
about = '''
Short instruction
-----------------
? - help (this dialog)
/ - search tag
+ - add tag
- - remove tag
& - search linked tasks
< - back
q - exit
'''
self.screen.change_path('~tag', '?/+-&<q', about, self.header, self.info)
menu = self.screen.print()
if menu == 'q':
self.bye()
self.screen.bye()
elif menu == '/':
self.search_tag(tid)
self.manage_tag_menu(tid)
elif menu == '?':
self.manage_tag_about(tid)
self.screen.activate_about()
self.manage_tag(tid)
elif menu == '+':
self.add_tag()
@ -54,28 +64,14 @@ class Tag:
return
else:
print(bcolors.FAIL + 'This is not implemented...' + bcolors.ENDC)
self.screen.add_fail('This is not implemented...')
self.manage_tag_menu(tid)
def manage_tag_about(self, tid=None):
print(bcolors.WARNING + '''
Short instruction
-----------------
? - help (this dialog)
/ - search tag
+ - add tag
- - remove tag
& - search linked tasks
< - back
q - exit
''' + bcolors.ENDC)
self.manage_tag(tid)
def add_tag(self):
print(bcolors.HEADER + 'Adding tag' + bcolors.ENDC)
self.screen.print_init('Adding tag')
name = input('Name: ')
tid = self.model.create_tag(name)
print(bcolors.OKBLUE + '[tag has been created]' + bcolors.ENDC)
self.screen.add_message('tag has been created')
self.manage_tag(tid)
def search_tag(self, tid=None):
@ -93,12 +89,12 @@ q - exit
tag = self.model.get_tag_by_name(selected[0])
self.manage_tag(tag['id'])
else:
print(bcolors.FAIL + 'Tag was not selected...' + bcolors.ENDC)
self.screen.add_fail('Tag was not selected...')
def remove_tag(self, tid=None):
tagsData = self.model.get_all_tags()
if not tagsData:
print(bcolors.FAIL + 'Where is no tags...' + bcolors.ENDC)
self.screen.add_fail('Where is no tags...')
self.manage_tag_menu()
tags = []
@ -108,11 +104,7 @@ q - exit
selected = self.fzf.prompt(tags)
if selected:
self.model.remove_tag_by_name(selected[0])
print(bcolors.OKBLUE + '[tag has been deleted]' + bcolors.ENDC)
self.screen.add_message('tag has been deleted')
self.manage_tag()
else:
print(bcolors.FAIL + 'Tag was not selected...' + bcolors.ENDC)
def bye(self):
print(bcolors.FAIL + 'bye o/' + bcolors.ENDC)
sys.exit(0)
self.screen.add_fail('Tag was not selected...')

57
ztm.py
View file

@ -1,7 +1,6 @@
#!/usr/bin/env python
import argparse
import sys
from pyfzf.pyfzf import FzfPrompt
@ -9,8 +8,8 @@ from model import Model
from task import Task
from tag import Tag
from config import Config
from bcolors import bcolors
from params import Params
from screen import Screen
class Main:
@ -20,6 +19,7 @@ class Main:
self.tag = Tag()
self.config = Config()
self.params = Params()
self.screen = Screen()
self.fzf = FzfPrompt()
@ -31,29 +31,25 @@ class Main:
n = self.parser.parse_args()
if n.active:
self.params.update('active', True)
print(bcolors.HEADER + '''
GEEEEEEEL .. :
,##############Wf.,;;L#K;;. ,W, .Et
........jW##Wt t#E t##, ,W#t
tW##Kt t#E L###, j###t
tW##E; t#E .E#j##, G#fE#t
tW##E; t#E ;WW; ##,:K#i E#t
.fW##D, t#E j#E. ##f#W, E#t
.f###D, t#E .D#L ###K: E#t
.f####Gfffffffffff; t#E :K#t ##D. E#t
.fLLLLLLLLLLLLLLLLLi fE ... #G ..
: j
Task manager from Zordsdavini (2018) ''' + bcolors.ENDC)
self.menu()
def menu(self):
menu = input(bcolors.OKBLUE + '~: ' + bcolors.OKGREEN + 'What you want to do? (?+/tcq) ' + bcolors.ENDC)
about = '''
Short instruction
-----------------
? - help (this dialog)
+ - add
/ - search
t - tag manager
c - configuration
q - exit
'''
self.screen.change_path('~', '?+/tcq', about)
menu = self.screen.print()
if menu == '?':
self.about()
self.screen.activate_about()
self.menu()
elif menu == '+':
self.task.add()
@ -72,29 +68,12 @@ Task manager from Zordsdavini (2018) ''' + bcolors.ENDC)
self.menu()
elif menu == 'q':
self.bye()
self.screen.bye()
else:
print(bcolors.FAIL + 'This is not implemented...' + bcolors.ENDC)
self.screen.add_fail('This is not implemented...')
self.menu()
def about(self):
print(bcolors.WARNING + '''
Short instruction
-----------------
? - help (this dialog)
+ - add
/ - search
t - tag manager
c - configuration
q - exit
''' + bcolors.ENDC)
self.menu()
def bye(self):
print(bcolors.FAIL + 'bye o/' + bcolors.ENDC)
sys.exit(0)
if __name__ == '__main__':
a = Main()