1 import model, config, gui
4 from model.model import *
5 from config.config import gtd_directory,Configuration
6 from config.defaultconfig import default_actions_menu
7 from gui.gui import SearchableListView
8 from infos_widget import InfosWidget
9 from info_widget import InfoWidget
10 from context_widget import ContextWidget
11 from action_widget import ActionWidget,edit_action
12 from action_view import ActionView
13 from model import action
14 from model import info
15 from model import project
16 from model.action import Action
17 from log.logging import logger
18 from e32 import Ao_lock, in_emulator
19 from key_codes import *
24 ACTION_LIST_KEYS_AND_MENU = Configuration(os.path.join(gtd_directory,"actions.cfg"), default_actions_menu)
27 def ask_for_action(project_name,proposition=None):
29 action = Action(project_name,u'')
30 was_saved = edit_action(action)
37 #def ask_for_action(project_name,proposition=None):
38 # if proposition == None:
39 # proposition = u'Context %s'%(project_name)
40 # action_line = appuifw.query(u'Enter action %s'%project_name,'text',proposition)
41 # if action_line == None:
44 # return parse_action(action_line)
47 # text = u'Enter action'
50 # new_description = appuifw.query(text,'text',action.description)
52 # action.set_description(new_description)
58 def ask_for_info(proposition):
59 return appuifw.query(u'Enter info','text',u'%s'%(proposition))
62 class ProjectView(SearchableListView):
63 def __init__(self,project):
64 self.project = project
65 self.project.observers.append(self)
66 super(ProjectView, self).__init__()
67 self.set_menu(ACTION_LIST_KEYS_AND_MENU)
68 self.set_title(self.project.name)
69 self.set_filters([lambda:self.project.actions.with_property(lambda a:a.status==action.active)])
72 self.project.observers.remove(self)
73 # self.project.status = project.active
74 # self.project.status.update(self.project)
75 super(ProjectView, self).exit()
76 # self.project.dirty = True
77 # self.project.write()
78 # self.projects.update_status(self.project)
80 show_config(ACTION_LIST_KEYS_AND_MENU)
81 ACTION_LIST_KEYS_AND_MENU.write()
84 return self.project.actions
86 def generate_widgets(self):
88 widgets.append(InfosWidget(self.project))
89 for info in self.project.infos:
90 widgets.append(InfoWidget(info,self.project))
91 for (context,actions) in self.actions_by_context().items():
92 widgets.append(ContextWidget(context,self.project))
93 for action in actions:
94 widgets.append(ActionWidget(action))
96 def actions_by_context(self):
97 context_actions_map = {}
98 for action in self.actions():
99 if not action.context in context_actions_map:
100 context_actions_map[action.context]=[]
101 context_actions_map[action.context].append(action)
102 return context_actions_map
104 def add_action(self):
105 a = ask_for_action(self.project.name)
107 self.project.add_action(a)
108 self.project.status = project.active
110 i = ask_for_info(self.project.name)
112 selected = self.selected_index()
113 # First position is "Infos"
114 if selected>=0 and selected <= len(self.project.infos):
118 self.project.add_info(info.Info(i),position)
120 self.set_index(position+1)
124 def notify(self,project,attribute,new=None,old=None):
130 __all__= ('ProjectView','ask_for_action','ask_for_info')