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 pyfzf.pyfzf import FzfPrompt
from model import Model from model import Model
from params import Params from params import Params
from bcolors import bcolors from screen import Screen
class Config: class Config:
def __init__(self): def __init__(self):
self.model = Model() self.model = Model()
self.params = Params() self.params = Params()
self.screen = Screen()
self.fzf = FzfPrompt() self.fzf = FzfPrompt()
self.info = ''
def manage(self): def manage(self):
print(bcolors.HEADER + 'Managing configs' + bcolors.ENDC)
active = 'off' active = 'off'
if self.params.get('active'): if self.params.get('active'):
active = 'on' active = 'on'
self.info = 'Show current tasks: [' + active + ']\n'
print(bcolors.WARNING + 'Show current tasks: [' + active + ']' + bcolors.ENDC)
done = 'off' done = 'off'
if self.params.get('done'): if self.params.get('done'):
done = 'on' done = 'on'
self.info += 'Show done tasks: [' + done + ']\n'
print(bcolors.WARNING + 'Show done tasks: [' + done + ']' + bcolors.ENDC)
self.manage_menu() self.manage_menu()
def manage_menu(self): 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': if menu == 'q':
self.bye() self.screen.bye()
elif menu == '?': elif menu == '?':
self.manage_about() self.screen.activate_about()
self.manage_menu() self.manage_menu()
elif menu == '!': elif menu == '!':
@ -55,43 +65,41 @@ class Config:
return return
else: else:
print(bcolors.FAIL + 'This is not implemented...' + bcolors.ENDC) self.screen.add_fail('This is not implemented...')
self.manage_menu() 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): def toggle_active(self):
active = self.params.get('active') active = self.params.get('active')
self.params.update('active', not 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): def toggle_done(self):
done = self.params.get('done') done = self.params.get('done')
self.params.update('done', not 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): def manage_timeslot(self):
self.manage_timeslot_menu() self.manage_timeslot_menu()
def manage_timeslot_menu(self): 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': if menu == 'q':
self.bye() self.screen.bye()
elif menu == '?': elif menu == '?':
self.manage_timeslot_about() self.screen.activate_about()
self.manage_timeslot_menu()
elif menu == '+': elif menu == '+':
self.add_time_slot() self.add_time_slot()
@ -103,27 +111,15 @@ q - exit
return return
else: else:
print(bcolors.FAIL + 'This is not implemented...' + bcolors.ENDC) self.screen.add_fail('This is not implemented...')
self.manage_menu() self.manage_timeslot_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()
def add_time_slot(self): def add_time_slot(self):
print(bcolors.HEADER + 'Adding time slot' + bcolors.ENDC) self.screen.print_init('Adding time slot')
name = input('Name (short): ') name = input('Name (short): ')
description = input('Description: ') description = input('Description: ')
tid = self.model.create_time_slot(name, 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() self.manage()
def search_tag(self, tid=None): def search_tag(self, tid=None):
@ -141,12 +137,12 @@ q - exit
tag = self.model.get_tag_by_name(selected[0]) tag = self.model.get_tag_by_name(selected[0])
self.manage_tag(tag['id']) self.manage_tag(tag['id'])
else: else:
print(bcolors.FAIL + 'Tag was not selected...' + bcolors.ENDC) self.screen.add_fail('Tag was not selected...')
def remove_tag(self, tid=None): def remove_tag(self, tid=None):
tagsData = self.model.get_all_tags() tagsData = self.model.get_all_tags()
if not tagsData: if not tagsData:
print(bcolors.FAIL + 'Where is no tags...' + bcolors.ENDC) self.screen.add_fail('Where is no tags...')
self.manage_tag_menu() self.manage_tag_menu()
tags = [] tags = []
@ -156,11 +152,7 @@ q - exit
selected = self.fzf.prompt(tags) selected = self.fzf.prompt(tags)
if selected: if selected:
self.model.remove_tag_by_name(selected[0]) 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() self.manage_tag()
else: else:
print(bcolors.FAIL + 'Tag was not selected...' + bcolors.ENDC) self.screen.add_fail('Tag was not selected...')
def bye(self):
print(bcolors.FAIL + 'bye o/' + bcolors.ENDC)
sys.exit(0)

68
tag.py
View file

@ -1,48 +1,58 @@
import sys
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
from model import Model from model import Model
from bcolors import bcolors from screen import Screen
class Tag: class Tag:
def __init__(self): def __init__(self):
self.model = Model() self.model = Model()
self.fzf = FzfPrompt() self.fzf = FzfPrompt()
self.screen = Screen()
self.header = ''
self.info = None
def manage_tag(self, tid=None): def manage_tag(self, tid=None):
if tid: if tid:
tag = self.model.get_tag(tid) tag = self.model.get_tag(tid)
print(bcolors.HEADER + 'Managing tag: ' + tag['name'] + bcolors.ENDC) self.header = 'Managing tag: ' + tag['name']
else: else:
print(bcolors.HEADER + 'Managing tags' + bcolors.ENDC) self.header = 'Managing tags'
tagsData = self.model.get_all_tags() tagsData = self.model.get_all_tags()
if not tagsData: if not tagsData:
self.add_tag() self.add_tag()
tagsData = self.model.get_all_tags() tagsData = self.model.get_all_tags()
tags = bcolors.WARNING self.info = ' '.join([t['name'] for t in tagsData]) + '\n'
for t in tagsData:
tags += t['name'] + ' '
print(tags + bcolors.ENDC)
self.manage_tag_menu(tid) self.manage_tag_menu(tid)
def manage_tag_menu(self, tid=None): 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': if menu == 'q':
self.bye() self.screen.bye()
elif menu == '/': elif menu == '/':
self.search_tag(tid) self.search_tag(tid)
self.manage_tag_menu(tid) self.manage_tag_menu(tid)
elif menu == '?': elif menu == '?':
self.manage_tag_about(tid) self.screen.activate_about()
self.manage_tag(tid)
elif menu == '+': elif menu == '+':
self.add_tag() self.add_tag()
@ -54,28 +64,14 @@ class Tag:
return return
else: else:
print(bcolors.FAIL + 'This is not implemented...' + bcolors.ENDC) self.screen.add_fail('This is not implemented...')
self.manage_tag_menu(tid) 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): def add_tag(self):
print(bcolors.HEADER + 'Adding tag' + bcolors.ENDC) self.screen.print_init('Adding tag')
name = input('Name: ') name = input('Name: ')
tid = self.model.create_tag(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) self.manage_tag(tid)
def search_tag(self, tid=None): def search_tag(self, tid=None):
@ -93,12 +89,12 @@ q - exit
tag = self.model.get_tag_by_name(selected[0]) tag = self.model.get_tag_by_name(selected[0])
self.manage_tag(tag['id']) self.manage_tag(tag['id'])
else: else:
print(bcolors.FAIL + 'Tag was not selected...' + bcolors.ENDC) self.screen.add_fail('Tag was not selected...')
def remove_tag(self, tid=None): def remove_tag(self, tid=None):
tagsData = self.model.get_all_tags() tagsData = self.model.get_all_tags()
if not tagsData: if not tagsData:
print(bcolors.FAIL + 'Where is no tags...' + bcolors.ENDC) self.screen.add_fail('Where is no tags...')
self.manage_tag_menu() self.manage_tag_menu()
tags = [] tags = []
@ -108,11 +104,7 @@ q - exit
selected = self.fzf.prompt(tags) selected = self.fzf.prompt(tags)
if selected: if selected:
self.model.remove_tag_by_name(selected[0]) 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() self.manage_tag()
else: else:
print(bcolors.FAIL + 'Tag was not selected...' + bcolors.ENDC) self.screen.add_fail('Tag was not selected...')
def bye(self):
print(bcolors.FAIL + 'bye o/' + bcolors.ENDC)
sys.exit(0)

57
ztm.py
View file

@ -1,7 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
import argparse import argparse
import sys
from pyfzf.pyfzf import FzfPrompt from pyfzf.pyfzf import FzfPrompt
@ -9,8 +8,8 @@ from model import Model
from task import Task from task import Task
from tag import Tag from tag import Tag
from config import Config from config import Config
from bcolors import bcolors
from params import Params from params import Params
from screen import Screen
class Main: class Main:
@ -20,6 +19,7 @@ class Main:
self.tag = Tag() self.tag = Tag()
self.config = Config() self.config = Config()
self.params = Params() self.params = Params()
self.screen = Screen()
self.fzf = FzfPrompt() self.fzf = FzfPrompt()
@ -31,29 +31,25 @@ class Main:
n = self.parser.parse_args() n = self.parser.parse_args()
if n.active: if n.active:
self.params.update('active', True) 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() self.menu()
def menu(self): 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 == '?': if menu == '?':
self.about() self.screen.activate_about()
self.menu()
elif menu == '+': elif menu == '+':
self.task.add() self.task.add()
@ -72,29 +68,12 @@ Task manager from Zordsdavini (2018) ''' + bcolors.ENDC)
self.menu() self.menu()
elif menu == 'q': elif menu == 'q':
self.bye() self.screen.bye()
else: else:
print(bcolors.FAIL + 'This is not implemented...' + bcolors.ENDC) self.screen.add_fail('This is not implemented...')
self.menu() 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__': if __name__ == '__main__':
a = Main() a = Main()