Adiciona Quadros e Rendimentos Isentos na 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 import isentos
25
26 def List(UI, L, display):
27     exit = False
28     while not exit:
29         ls = []
30         for i in L.items:
31             d = i.get_attr(display)
32             if d == None:
33                 d = ""
34             ls.append(d)
35         r = UI.list(ls)
36         if r[1] == None:
37             exit = True
38         elif r[1] == 'add':
39             UI.form(L.form(L.new_item()))
40         elif r[1] == 'edit':
41             UI.form(L.form(L.items[r[0] - 1]))
42         elif r[1] == 'delete':
43             L.remove_item(r[0] - 1)
44     return True
45
46 def RendimentosPJ(UI, contrib):
47     rend = rendimentoPJ.RendimentosPJ(contrib)
48     return List(UI, rend, "nomeFontePagadora")
49
50 def DadosPessoais(UI, contrib):
51     UI.form(contrib.form())
52     return True
53
54 def Bens(UI, contrib):
55     b = bens.Bens(contrib)
56     return List(UI, b, "discriminacao")
57
58 def Quadro(UI, quadro):
59     return List(UI, quadro, "especificacao")
60
61 def Quadros(quadros):
62     def fQuadros(UI, contrib):
63         exit = False
64         while not exit:
65             r = UI.menu(map(lambda x: x.name, quadros.quadros))
66             if r < 0:
67                 exit = True
68             else:
69                 Quadro(UI, quadros.quadros[r])
70     return fQuadros
71
72 def Salvar(UI, contrib):
73     contrib.save()
74
75 def menu(UI, contrib):
76     m = [ 
77         "Sair",
78         "Salvar",
79         "Dados Pessoais",
80         "Rendimentos PJ",
81         "Bens",
82         "Rendimentos Isentos",
83         ]
84     f = [
85         None,
86         Salvar,
87         DadosPessoais,
88         RendimentosPJ,
89         Bens,
90         Quadros(isentos.RendimentosIsentos(contrib)),
91         ]
92     exit = False
93     while not exit:
94         r = UI.menu(m)
95         if r <= 0:
96             exit = True
97         else:
98             f[r](UI, contrib)
99
100 def main():
101     ret = False
102     UI = baseui.BaseUI()
103     while ret == False:
104         cpf = UI.get_string("Digite seu CPF: ")
105         try:
106             contrib = contribuinte.Contribuinte(cpf)
107             ret = menu(UI, contrib)
108         except RuntimeError, e:
109             print "CPF invalido"
110
111 if __name__ == '__main__':
112     main()
113
114 # vim:tabstop=4:expandtab:smartindent