Add files from the old svn, r101.
[matthijs/upstream/mobilegtd.git] / src / gui / project_details / action_view.py
1 from log.logging import logger
2 from model.action import *
3 import appuifw
4
5 def edit_action(action):
6     f = ActionView(action)
7     f.execute()
8     return f.isSaved() == 1
9
10 class ActionView( object ):
11     
12     def __init__( self, action):
13         self.action = action
14         self.saved = False
15  
16
17  
18  
19     ## Displays the form.
20     def execute( self ):
21         self.saved = False
22         fields = [(u'Context','text',self.action.context),
23         (u'Description','text',self.action.description),
24         (u'Info','text',self.action.info)]
25         logger.log(repr(fields))
26         self.form = appuifw.Form(fields, appuifw.FFormEditModeOnly)
27         
28         self.form.save_hook = self.markSaved
29         self.form.flags = appuifw.FFormEditModeOnly
30         self.form.execute( )
31         if self.saved:
32             self.save_fields()
33  
34     def save_fields(self):
35         context = self.get_context()
36         if len(context.strip()) == 0:
37             context,description,info,status = parse_action_line(self.get_description())
38         else:
39             description = self.get_description()
40             context = parse_context(context)
41             
42         if len(self.get_info().strip()) > 0:
43             info = self.get_info()
44         else:
45             info = u""
46         self.action.context = context
47         self.action.description = description
48         self.action.info = info
49         
50     ## save_hook send True if the form has been saved.
51     def markSaved( self, saved ):
52         #appuifw.note(u'save_hook called with %s'%saved)
53         
54         if saved and self.is_valid():
55             self.saved = True
56         return self.saved
57     def isSaved( self ):
58         return self.saved
59  
60     def get_description( self ):
61         return unicode(self.form[1][2])
62  
63  
64
65     def get_context( self ):
66         return unicode(self.form[0][2])
67     def is_valid(self):
68         return len(self.form[0]) > 2 and len(self.form[1]) > 2
69  
70
71     def get_info( self ):
72         return unicode(self.form[2][2])