From: Thadeu Lima de Souza Cascardo Date: Sun, 23 Mar 2014 19:29:00 +0000 (-0300) Subject: Introduz classe tipos para ocupações, tipo de bens, etc. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Firpf-gui.git;a=commitdiff_plain;h=0b93e487df31e15d903f1dcebf475f761085696d Introduz classe tipos para ocupações, tipo de bens, etc. --- diff --git a/src/tipos.py b/src/tipos.py new file mode 100644 index 0000000..c236554 --- /dev/null +++ b/src/tipos.py @@ -0,0 +1,62 @@ +# coding=utf-8 +# +# Copyright 2013 Thadeu Lima de Souza Cascardo +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# -*- mode: python; encoding: utf-8; -*- + +import xml.dom.minidom +import dirs + +class Tipos: + def __init__(self, fname, cols, group = -1): + irpf_dir = dirs.get_default_irpf_dir() + self.xml = xml.dom.minidom.parse(irpf_dir.get_resource_file(fname)) + self.l = [] + self.g = {} + self.cols = cols + self.group = group + self._list() + if group >= 0: + self._group() + + def _list(self): + for i in self.xml.getElementsByTagName("ITEM"): + if self.cols[-1] in i.attributes.keys(): + item = [] + for j in self.cols: + item.append(i.attributes[j].nodeValue) + self.l.append(item) + + def list(self): + return self.l + + def _group(self): + for i in self.l: + if i[self.group] not in self.g: + self.g[i[self.group]] = [] + self.g[i[self.group]].append(i) + + def groups(self): + if group < 0: + return None + return self.g + + def get_by_code(self, code): + for i in self.l: + if i[0] == code: + return i + return None + +# vim:tabstop=4:expandtab:smartindent