Adiciona lista de bens à interface.
[cascardo/irpf-gui.git] / src / menu.py
1 # coding=utf-8
2 #
3 #   Copyright 2013 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
4 #
5 #   This program is free software: you can redistribute it and/or modify
6 #   it under the terms of the GNU General Public License as published by
7 #   the Free Software Foundation, either version 3 of the License, or
8 #   (at your option) any later version.
9 #
10 #   This program is distributed in the hope that it will be useful,
11 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #   GNU General Public License for more details.
14 #
15 #   You should have received a copy of the GNU General Public License
16 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 # -*- mode: python; encoding: utf-8; -*-
18
19 import baseui
20 import contribuinte
21 import rendimentoPJ
22 import bens
23 import sys
24
25 def List(UI, L, display):
26     exit = False
27     while not exit:
28         ls = []
29         for i in L.items:
30             d = i.get_attr(display)
31             if d == None:
32                 d = ""
33             ls.append(d)
34         r = UI.list(ls)
35         if r[1] == None:
36             exit = True
37         elif r[1] == 'add':
38             UI.form(L.form(L.new_item()))
39         elif r[1] == 'edit':
40             UI.form(L.form(L.items[r[0] - 1]))
41         elif r[1] == 'delete':
42             L.remove_item(r[0] - 1)
43     return True
44
45 def RendimentosPJ(UI, contrib):
46     rend = rendimentoPJ.RendimentosPJ(contrib)
47     return List(UI, rend, "nomeFontePagadora")
48
49 def DadosPessoais(UI, contrib):
50     UI.form(contrib.form())
51     return True
52
53 def Bens(UI, contrib):
54     b = bens.Bens(contrib)
55     return List(UI, b, "discriminacao")
56
57 def Salvar(UI, contrib):
58     contrib.save()
59
60 def menu(UI, contrib):
61     m = [ 
62         "Sair",
63         "Salvar",
64         "Dados Pessoais",
65         "Rendimentos PJ",
66         "Bens",
67         ]
68     f = [
69         None,
70         Salvar,
71         DadosPessoais,
72         RendimentosPJ,
73         Bens,
74         ]
75     exit = False
76     while not exit:
77         r = UI.menu(m)
78         if r <= 0:
79             exit = True
80         else:
81             f[r](UI, contrib)
82
83 def main():
84     ret = False
85     UI = baseui.BaseUI()
86     while ret == False:
87         cpf = UI.get_string("Digite seu CPF: ")
88         try:
89             contrib = contribuinte.Contribuinte(cpf)
90             ret = menu(UI, contrib)
91         except RuntimeError, e:
92             print "CPF invalido"
93
94 if __name__ == '__main__':
95     main()
96
97 # vim:tabstop=4:expandtab:smartindent